|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.lang.Thread | +--gumbo.net.msg.MessageRouterThread
A thread for asynchronously receiving messages and routing them to registered handlers. The reader is used to receive whole messages from the remote. The writer is passed to the router for use by its message handlers to send a response.
Note that the thread is separate from its router since the thread will die if the socket or its connection is lost, but the router should endure in case of a reconnect.
MessageRouter
Field Summary |
Fields inherited from class java.lang.Thread |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
MessageRouterThread(MessageRouter router,
MessageReader reader,
MessageWriter writer)
|
Method Summary | |
boolean |
isRemoteBroken()
Returns true if remote broke the connection for any reason (stream closed or socket exception). |
boolean |
isStopping()
Returns true if pleaseStop() has been called. |
void |
pleaseStop()
Gracefully stops this thread from running by setting a stop flag (see isStopping()) and closing the reader to break any blocked read. |
void |
run()
Runs until the remote breaks the connection or the local closes the socket, such as a result of pleaseStop(). |
void |
setRouter(MessageRouter router)
|
Methods inherited from class java.lang.Thread |
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, 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 |
Constructor Detail |
public MessageRouterThread(MessageRouter router, MessageReader reader, MessageWriter writer) throws java.io.IOException
router
- The message router connected to message handlers.
Null if none. Note that messages received while there is no router
will be lost.reader
- Used to read messages. Never null. To assure thread
safety all entities reading messages should use this reader (i.e. it
is the thread lock).writer
- Sent with routed messages for use by message handlers to
send reply messages. Null if none (i.e. the message handlers can get
the writer through some other means). To assure thread safety all
entities writing messages should use this writer (i.e. it is the thread
lock).Method Detail |
public void setRouter(MessageRouter router)
router
- The message router used to route messages from the remote.
Null if none. Note that messages received while there is no router
will be lost.public boolean isRemoteBroken()
public final void pleaseStop()
public final boolean isStopping()
public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |