|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--com.mischiefbox.dmud.net.ConnectionHandler
Responsible for keeping track of connection info objects, checking for new input on connections, and passing new output to connections.
Is similar to the functionality of the UNIX select() or poll() call.
Runs in a thread to allow network I/O to operate asynchronously from the rest of the system. Network I/O is checked for input first (on each connection), then attempts to empty the output queue.
| Field Summary | |
protected boolean |
bHandling
Flag to indicate if this is currently handling I/O. |
static String |
CONNECTION_HANDLER_THREAD_NAME
The connection handler thread name. |
static String |
CONNECTION_INFO_THREAD_GROUP
The name of thread group for connection info objects. |
protected HashMap |
hmConnectionInfo
Registered connection info objects. |
protected InputQueue |
qInput
The input (incoming message) queue. |
protected Queue |
qOutput
The output (outgoing message) queue. |
protected static int |
SLEEP_MILLIS
The sleep time for this thread (in between processing runs). |
protected ThreadGroup |
tgConnectionInfo
The connection info object thread group. |
protected Thread |
tHandler
The handler thread. |
| Constructor Summary | |
ConnectionHandler(InputQueue qInput,
Queue qOutput)
Create a new connection handler. |
|
| Method Summary | |
ThreadGroup |
getConnectionInfoThreadGroup()
Get the connection info thread group object. |
void |
inputMessage(ConnectionInfo conInfo,
byte[] baMsg)
Pass a message on the behalf of the connection info to the input queue. |
boolean |
isHandling()
Indicates if this is handling I/O. |
void |
registerConnectionInfo(ConnectionInfo info)
Register a new connection info object. |
void |
run()
Process connection I/O, including checking for available messages from the client and from the message handler. |
void |
stopHandler()
Stops the handler from handling I/O. |
void |
unregisterConnectionInfo(ConnectionInfo info)
Unregister a connection info object. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final String CONNECTION_INFO_THREAD_GROUP
public static final String CONNECTION_HANDLER_THREAD_NAME
protected static final int SLEEP_MILLIS
protected HashMap hmConnectionInfo
protected InputQueue qInput
protected Queue qOutput
protected Thread tHandler
protected boolean bHandling
protected ThreadGroup tgConnectionInfo
| Constructor Detail |
public ConnectionHandler(InputQueue qInput,
Queue qOutput)
| Method Detail |
public void registerConnectionInfo(ConnectionInfo info)
This isn't synchronized because this should only be called from the new connection info object.
public void unregisterConnectionInfo(ConnectionInfo info)
This is synchronized (internally) so that it won't be unregistered twice at once (unregister may be called from more than one place) and so that the connection won't be used while it's being closed.
public boolean isHandling()
public void stopHandler()
Create a new handler to start handling I/O again. This will disconnect all the current clients.
public void run()
run in interface Runnable
public void inputMessage(ConnectionInfo conInfo,
byte[] baMsg)
throws MessageTooLargeException
conInfo - the connection info that received the message.baMsg - the message received.MessageTooLargeException - when the input message
exceeded protocol limits.public ThreadGroup getConnectionInfoThreadGroup()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||