inputOutputHandler
Class InputOutputHandlerController

java.lang.Object
  extended by inputOutputHandler.InputOutputHandlerController
All Implemented Interfaces:
InputOutputHandlerInterface

public final class InputOutputHandlerController
extends java.lang.Object
implements InputOutputHandlerInterface

Controller class of component InputOutputHandler. Implements the architecture interface InputOutputHandlerInterface.

Handles communication with clients, other mixes and receivers.

Waits for new connections from clients or other mixes and accepts messages using the classes ClientConnectionHandler, PreviousMixConnectionHandler, NextMixConnectionHandler and ProxyConnectionHandler and stores them in a ConcurrentLinkedQueue.

The process of accepting connections and receiving messages works in parallel to the mix operations. Therefore, the mix is capable of taking messages at any time (unless it is overloaded).

Sends (already mixed) messages to their destination using the same classes mentioned above. The mixed messages are stored in a ConcurrentLinkedQueue. The process of sending messages works in parallel to the mix operations. Therefore, the mix is capable of mixing new messages while sending the old ones.

This class is thread-safe.

Author:
Karl-Peter Fuchs

Field Summary
protected  boolean IS_FIRST
          Indicates whether this mix is the first of the cascade or not.
protected  boolean IS_LAST
          Indicates whether this mix is the lost of the cascade or not.
protected  int NUMBER_OF_FURTHER_HOPS
          Number of further mixes between the mix this InputOutputHandler belongs to and the receiver.
protected  int NUMBER_OF_PREVIOUS_HOPS
          Number of previous mixes between the mix this InputOutputHandler belongs to and the sender.
protected  int POSITION_OF_MIX_IN_CASCADE
          The mix' position in the cascade this object belongs to. "1" means "first mix", "2" means "a middle mix" and "3" means "last mix" of cascade.
 
Constructor Summary
InputOutputHandlerController()
          Creates a new InputOutputHandler component that handles communication with clients, other mixes and proxies.
 
Method Summary
 void acceptConnections()
          Makes component listen for connections/messages on communication channels.
 void addReplies(Reply[] replies)
          Adds all the bypassed (already mixed) Replyies to the replyOutputQueue (from where they will be sent to their destination).
 void addReply(Reply reply)
          Adds the bypassed (already mixed) Reply to the replyOutputQueue (from where it will be sent to its destination).
 void addRequest(Request request)
          Adds the bypassed (already mixed) Request to the requestOutputQueue (from where it will be sent to its destination).
 void addRequests(Request[] requests)
          Adds all the bypassed (already mixed) Requests to the requestOutputQueue (from where they will be sent to their destination).
protected  void addUnprocessedReply(ReplyMessage message)
          Adds the bypassed (just received) Reply to the replyInputQueue (from where it will be taken by component MessageProcessor via getReply()).
protected  void addUnprocessedRequest(Request request)
          Adds the bypassed (just received) Request to the requestInputQueue (from where it will be taken by component MessageProcessor via getRequest()).
protected  Reply getProcessedReply()
          Returns an (already mixed) Reply from the replyOutputQueue.
protected  Request getProcessedRequest()
          Returns an (already mixed) Request from the requestOutputQueue.
 Reply getReply()
          Returns a Reply (previously received, unprocessed) from a communication partner (e. g. proxy or other mix).
 Request getRequest()
          Returns a Request (previously received, unprocessed) from a communication partner (e. g. client or other mix).
 void initialize(UserDatabaseController userDatabase, OutputStrategyController outputStrategy, ExternalInformationPortController eip)
          Initialization method for this component.
protected static java.net.InetAddress tryToGenerateInetAddress(java.lang.String hostName)
          Tries to generate an InetAddress from the bypassed host name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NUMBER_OF_FURTHER_HOPS

protected final int NUMBER_OF_FURTHER_HOPS
Number of further mixes between the mix this InputOutputHandler belongs to and the receiver.


NUMBER_OF_PREVIOUS_HOPS

protected final int NUMBER_OF_PREVIOUS_HOPS
Number of previous mixes between the mix this InputOutputHandler belongs to and the sender.


POSITION_OF_MIX_IN_CASCADE

protected final int POSITION_OF_MIX_IN_CASCADE
The mix' position in the cascade this object belongs to. "1" means "first mix", "2" means "a middle mix" and "3" means "last mix" of cascade.


IS_FIRST

protected final boolean IS_FIRST
Indicates whether this mix is the first of the cascade or not.


IS_LAST

protected final boolean IS_LAST
Indicates whether this mix is the lost of the cascade or not.

Constructor Detail

InputOutputHandlerController

public InputOutputHandlerController()
Creates a new InputOutputHandler component that handles communication with clients, other mixes and proxies.

Component can't be used before calling initialize().

See Also:
initialize( UserDatabaseController, OutputStrategyController, ExternalInformationPortController)
Method Detail

initialize

public void initialize(UserDatabaseController userDatabase,
                       OutputStrategyController outputStrategy,
                       ExternalInformationPortController eip)
Initialization method for this component. Must be called before using an instance of this class for anything but dispensing references on the instance itself.

Parameters:
userDatabase - Reference on component UserDatabase.
outputStrategy - Reference on component OutputStrategy.
eip - Reference on component ExternalInformationPort.

acceptConnections

public void acceptConnections()
Makes component listen for connections/messages on communication channels.

Specified by:
acceptConnections in interface InputOutputHandlerInterface

tryToGenerateInetAddress

protected static java.net.InetAddress tryToGenerateInetAddress(java.lang.String hostName)
Tries to generate an InetAddress from the bypassed host name. If an exception occurs, the program exits!

Parameters:
hostName - Host name to generate InetAddress from.
Returns:
InetAddress representation of the bypassed host name.

addRequest

public void addRequest(Request request)
Adds the bypassed (already mixed) Request to the requestOutputQueue (from where it will be sent to its destination).

Returns immediately (asynchronous behavior), the process of sending itself may be deferred (e. g. if communication channel is busy).

Assures order (queuing strategy) and is thread-safe.

Used by component OutputStrategy.

Specified by:
addRequest in interface InputOutputHandlerInterface
Parameters:
request - Already processed message, that shall be sent to the next communication partner.
See Also:
getProcessedRequest(), addRequests(Request[])

addRequests

public void addRequests(Request[] requests)
Adds all the bypassed (already mixed) Requests to the requestOutputQueue (from where they will be sent to their destination).

Returns immediately (asynchronous behavior), the process of sending itself may be deferred (e. g. if communication channel is busy).

Assures order (queuing strategy) and is thread-safe.

Used by component OutputStrategy.

Specified by:
addRequests in interface InputOutputHandlerInterface
Parameters:
requests - Already processed messages, that shall be sent to the next communication partner.
See Also:
getProcessedRequest(), addRequest(Request)

getProcessedRequest

protected Request getProcessedRequest()
Returns an (already mixed) Request from the requestOutputQueue. If no requests are available, this method blocks until a new Request arrives.

Assures order (queuing strategy) and is thread-safe.

Returns:
An (already mixed) Request.

addUnprocessedRequest

protected void addUnprocessedRequest(Request request)
Adds the bypassed (just received) Request to the requestInputQueue (from where it will be taken by component MessageProcessor via getRequest()).

Assures order (queuing strategy) and is thread-safe.

Parameters:
request - Just received message, that shall be added.

getRequest

public Request getRequest()
Returns a Request (previously received, unprocessed) from a communication partner (e. g. client or other mix). If no Requests are available, this method blocks until a new Request arrives.

Assures order (queuing strategy) and is thread-safe.

Specified by:
getRequest in interface InputOutputHandlerInterface
Returns:
A (previously received, unprocessed) Request.

addReply

public void addReply(Reply reply)
Adds the bypassed (already mixed) Reply to the replyOutputQueue (from where it will be sent to its destination).

Returns immediately (asynchronous behavior), the process of sending itself may be deferred (e. g. if communication channel is busy).

Assures order (queuing strategy) and is thread-safe.

Used by component OutputStrategy.

Specified by:
addReply in interface InputOutputHandlerInterface
Parameters:
reply - Already processed message, that shall be sent to the next communication partner.
See Also:
getProcessedReply(), addReplies(Reply[])

addReplies

public void addReplies(Reply[] replies)
Adds all the bypassed (already mixed) Replyies to the replyOutputQueue (from where they will be sent to their destination).

Returns immediately (asynchronous behavior), the process of sending itself may be deferred (e. g. if communication channel is busy).

Assures order (queuing strategy) and is thread-safe.

Used by component OutputStrategy.

Specified by:
addReplies in interface InputOutputHandlerInterface
Parameters:
replies - Already processed messages, that shall be sent to the next communication partner.
See Also:
getProcessedReply(), addReply(Reply)

getProcessedReply

protected Reply getProcessedReply()
Returns an (already mixed) Reply from the replyOutputQueue. If no replies are available, this method blocks until a new Reply arrives.

Assures order (queuing strategy) and is thread-safe.

Returns:
An (already mixed) Reply.

addUnprocessedReply

protected void addUnprocessedReply(ReplyMessage message)
Adds the bypassed (just received) Reply to the replyInputQueue (from where it will be taken by component MessageProcessor via getReply()).

Assures order (queuing strategy) and is thread-safe.

Parameters:
message - Message just received, that shall be added.

getReply

public Reply getReply()
Returns a Reply (previously received, unprocessed) from a communication partner (e. g. proxy or other mix). If no Replyies are available, this method blocks until a new Reply arrives.

Assures order (queuing strategy) and is thread-safe.

Specified by:
getReply in interface InputOutputHandlerInterface
Returns:
A (previously received, unprocessed) Reply.