|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--com.mischiefbox.pollserve.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. |
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 Thread |
tHandler
The handler thread. |
| Constructor Summary | |
ConnectionHandler(InputQueue qInput,
Queue qOutput)
Create a new connection handler. |
|
| Method Summary | |
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 |
protected static final int SLEEP_MILLIS
protected HashMap hmConnectionInfo
protected InputQueue qInput
protected Queue qOutput
protected Thread tHandler
protected boolean bHandling
| 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
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||