|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.lang.Thread
inputOutputHandler.ClientConnectionHandler
final class ClientConnectionHandler
Handles communication with Clients. Accepts connections,
receives Requests and sends Replyies.
Requests are put in the
InputOutputHandlerController's requestInputQueue
(see InputOutputHandlerController.addUnprocessedRequest()).
Replyies are taken from the
InputOutputHandlerController's replyOutputQueue
(see InputOutputHandlerController.getProcessedReply()).
Adds/removes user to/from UserDatabase.
Uses non-blocking I/O.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class java.lang.Thread |
|---|
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler |
| Field Summary | |
|---|---|
private int |
BACKLOG
The maximum queue length for incoming connection indications. |
private java.net.InetAddress |
BIND_ADDRESS
Address this ClientConnectionHandler's socket shall be
bound to. |
private InputOutputHandlerController |
inputOutputHandler
Reference on InputOutputHandlerController (Used to add
messages). |
private static InternalInformationPortController |
internalInformationPort
Reference on component InternalInformationPort. |
private static java.util.logging.Logger |
LOGGER
Logger used to log and display information. |
private int |
MAX_CONNECTIONS
Maximum number of connections (=connected Clients). |
private int |
NUMBER_OF_FURTHER_HOPS
Number of further mixes between the mix this InputOutputHandler
belongs to and the receiver. |
private java.lang.Integer |
numberOfActiveConnections
Number of Clients currently connected. |
private OutputStrategyController |
outputStrategy
Reference on component OutputStrategy (Used to send
InternalMessages). |
private int |
PORT
Port number this ClientConnectionHandler runs on. |
private 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. |
private java.security.SecureRandom |
secureRandom
Random number generator used to generate User identifiers. |
private java.nio.channels.Selector |
selector
Selector used for non-blocking I/O. |
private java.nio.channels.ServerSocketChannel |
serverSocketChannel
ServerSocketChannel used for accepting connections. |
private int |
SO_TIMEOUT
Maximum amount of time an accept (of a client's connection)
may take before being canceled in ms. |
private UserDatabaseController |
userDatabase
Reference on component UserDatabase (Used to add/remove
User)s. |
private java.util.LinkedList<User> |
writeRequests
List of Users with data ready to be sent. |
| Fields inherited from class java.lang.Thread |
|---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
| Constructor Summary | |
|---|---|
protected |
ClientConnectionHandler(InputOutputHandlerController inputOutputHandler,
UserDatabaseController userDatabase,
OutputStrategyController outputStrategy)
Constructs a new ClientConnectionHandler which accepts
connections, receives Requests and sends
Replyies. |
| Method Summary | |
|---|---|
protected void |
acceptConnections()
Makes this ClientConnectionHandler wait for connections,
Requests and Replyies. |
private static java.lang.String |
getProperty(java.lang.String key)
Simply used to shorten method calls (calls internalInformationPort.getProperty(key)). |
private void |
handleAcceptRequest()
Handles an accept request. |
private void |
handleReadRequest(java.nio.channels.SelectionKey key)
Handles a read request. |
private void |
handleWriteRequest(java.nio.channels.SelectionKey key)
Handles a write request. |
private void |
initializeReplyProcess()
Waits for Replyies ready to be sent (to
Clients). |
private void |
registerWriteRequests()
Registers all write requests from writeRequests with
selector. |
void |
run()
Handles read, write and accept events (non-blocking I/O). |
| Methods inherited from class java.lang.Thread |
|---|
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
private static InternalInformationPortController internalInformationPort
InternalInformationPort.
Used to display and/or log data and read general settings.
private static final java.util.logging.Logger LOGGER
private final int PORT
ClientConnectionHandler runs on.
private final java.net.InetAddress BIND_ADDRESS
ClientConnectionHandler's socket shall be
bound to.
private final int BACKLOG
private final int SO_TIMEOUT
accept (of a client's connection)
may take before being canceled in ms.
private final int MAX_CONNECTIONS
Clients).
private final int POSITION_OF_MIX_IN_CASCADE
private final int NUMBER_OF_FURTHER_HOPS
InputOutputHandler
belongs to and the receiver.
private InputOutputHandlerController inputOutputHandler
InputOutputHandlerController (Used to add
messages).
private UserDatabaseController userDatabase
UserDatabase (Used to add/remove
User)s.
private OutputStrategyController outputStrategy
OutputStrategy (Used to send
InternalMessages).
private java.util.LinkedList<User> writeRequests
Users with data ready to be sent.
private java.security.SecureRandom secureRandom
User identifiers.
private java.lang.Integer numberOfActiveConnections
Clients currently connected.
private java.nio.channels.Selector selector
Selector used for non-blocking I/O.
private java.nio.channels.ServerSocketChannel serverSocketChannel
ServerSocketChannel used for accepting connections.
| Constructor Detail |
|---|
protected ClientConnectionHandler(InputOutputHandlerController inputOutputHandler,
UserDatabaseController userDatabase,
OutputStrategyController outputStrategy)
ClientConnectionHandler which accepts
connections, receives Requests and sends
Replyies. Requests are put in the
InputOutputHandlerController's
requestInputQueue
(see InputOutputHandlerController.addUnprocessedRequest()).
Replyies are taken from the
InputOutputHandlerController's replyOutputQueue
(see InputOutputHandlerController.getProcessedReply()).
Adds/removes user to/from UserDatabase.
Uses non-blocking I/O.
inputOutputHandler - Reference on
InputOutputHandlerController
(Used to add messages).userDatabase - Reference on component
UserDatabase (Used to
add/remove User)s.outputStrategy - Reference on component
OutputStrategy (Used to send
InternalMessages).| Method Detail |
|---|
protected void acceptConnections()
ClientConnectionHandler wait for connections,
Requests and Replyies.
private void initializeReplyProcess()
Replyies ready to be sent (to
Clients). Ready Replyies are put in the
suiting User's buffer. Afterwards the
selector is notified about the data being ready to
send (non-blocking I/O).
writeRequests,
selectorpublic void run()
run in interface java.lang.Runnablerun in class java.lang.Threadprivate void registerWriteRequests()
writeRequests with
selector.
writeRequests,
selector
private void handleAcceptRequest()
throws java.io.IOException
numberOfActiveConnections,
MAX_CONNECTIONS). Generates User objects and
adds them to the UserDatabase (if connection accepted).
java.io.IOException - If an I/O error occurres.
private void handleReadRequest(java.nio.channels.SelectionKey key)
throws java.io.IOException
User's buffer. If a buffer contains a whole message, a
Message object is created and passed to the
InputOutputHandlerController (which provides it to the
MessageProcessor).
key - Token representing the registration of a
SelectableChannel with the
selector.
java.io.IOException - If an I/O error occurres.selector
private void handleWriteRequest(java.nio.channels.SelectionKey key)
throws java.io.IOException
User's buffer
to the suiting SocketChannel.
key - Token representing the registration of a
SelectableChannel with the
selector.
java.io.IOException - If an I/O error occurres.private static java.lang.String getProperty(java.lang.String key)
internalInformationPort.getProperty(key)). Returns the
property with the specified key from the property file.
key - The property key.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||