|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--java.lang.Thread
|
+--jrun.jms.core.kernel.mipc.MultiplexConnection
The MultiplexConnection encapsulates a single network connection. It allows for multiple channels or multiplexed message streams. The object is thread safe and uses threads within it to do its job. The design for the Multiplexed streaming borrows concepts from the book "Java Network Programming : A Complete Guide to Networking, Streams, and Distributed Computing", by Merlin Hughes, Michael Shoffner, Derek Hamner The MultiplexConnection is designed as follows: - users of the connection register themselves as channels. each channel is given a stream to place outbound messages on, and gives the MC a stream to write inbound messages on. Typically this "inbound" stream is a Queue Stream and the user sucks messages off of the queue on a separate thread. That way the multiplex delivery mechanism does not have to wait for a channel handler to process a message. - As channel producers send messages, they are multiplexed and placed on a queue for outbound delivery. A separate MessageCopier thread takes messages from this queue and sends them onto to the "raw" outbound stream. - Inbound messages are handled by Demultiplixer. The Demux manages a list of channels. It unwraps a packet and uses the name encoded in the packet to pass the message onto an output stream. This outputstream is the one passed into "register" by the channel consumer/producer. The Demux runs within the same thread as MultiplexConnection. It is important to note: All activity on the "raw" inbound and outbound streams are synchronized, as well as the objects used to build the MultiplexConnection. So everything is thread-safe.
MultiplexConnectionServer,
MessageCopier,
Demultiplexer| Field Summary | |
protected boolean |
_finished
Used for stopping the thread |
| Fields inherited from class java.lang.Thread |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
| Constructor Summary | |
MultiplexConnection(java.net.Socket socket)
Creates a MultiplexConnection on top of an existing Socket |
|
MultiplexConnection(java.lang.String hostname,
int port)
Creates new MultiplexConnection on the specified host and port. |
|
MultiplexConnection(java.lang.ThreadGroup group,
java.net.Socket socket)
Creates a MultiplexConnection on top of an existing Socket |
|
| Method Summary | |
void |
deregister(java.lang.String label)
Deregister a multiplex channel. |
void |
disconnected()
This is called by the demultiplexer when the channel has been abnormally terminated. |
void |
finish()
Gracefully stop the MultiplexConnection thread. |
java.lang.String |
getHost()
Return the hostname that this connection bound to |
int |
getPort()
Return the port that this connection is bound to |
protected void |
init(java.net.Socket socket)
|
jrun.jms.core.kernel.mipc.MessageOutput |
register(java.lang.String label,
jrun.jms.core.kernel.mipc.MessageOutput out)
Register a new multiplex channel. |
void |
run()
The workhorse for the MultiplexConnection. |
void |
setDisconnectionEventListener(DisconnectionEventListener listener)
Set the listener that will be called back when the multiplex connection is dropped |
| Methods inherited from class java.lang.Thread |
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, 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 |
| Field Detail |
protected boolean _finished
| Constructor Detail |
public MultiplexConnection(java.lang.String hostname,
int port)
throws java.net.UnknownHostException,
java.io.IOException
hostname - the hostname to create a socket connection toport - the port to connect to
public MultiplexConnection(java.net.Socket socket)
throws java.io.IOException
socket - The existing socket to wrap.
public MultiplexConnection(java.lang.ThreadGroup group,
java.net.Socket socket)
throws java.io.IOException
group - the thread group that the connection belongs tosocket - the existing socket to wrap| Method Detail |
public void finish()
finish in interface MultiplexConnectionIfcpublic void setDisconnectionEventListener(DisconnectionEventListener listener)
setDisconnectionEventListener in interface MultiplexConnectionIfclistener - - the disconnection event listenerpublic void run()
run in interface MultiplexConnectionIfcrun in class java.lang.Thread
public jrun.jms.core.kernel.mipc.MessageOutput register(java.lang.String label,
jrun.jms.core.kernel.mipc.MessageOutput out)
register in interface MultiplexConnectionIfclabel - The channel name to register formessageOutput - Inbound messages are placed herepublic void deregister(java.lang.String label)
deregister in interface MultiplexConnectionIfclabel - the name of the channel to unregisterpublic void disconnected()
disconnected in interface MultiplexConnectionIfcpublic java.lang.String getHost()
getHost in interface MultiplexConnectionIfcpublic int getPort()
getPort in interface MultiplexConnectionIfc
protected void init(java.net.Socket socket)
throws java.io.IOException
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||