|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Thread
org.exolab.core.mipc.MultiplexConnection
public class 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
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.lang.Thread |
---|
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler |
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)
|
org.exolab.core.mipc.MessageOutput |
register(java.lang.String label,
org.exolab.core.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, clone, 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 |
---|
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
java.net.UnknownHostException
java.io.IOException
public MultiplexConnection(java.net.Socket socket) throws java.io.IOException
socket
- The existing socket to wrap.
java.io.IOException
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
java.io.IOException
Method Detail |
---|
public void finish()
finish
in interface MultiplexConnectionIfc
public void setDisconnectionEventListener(DisconnectionEventListener listener)
setDisconnectionEventListener
in interface MultiplexConnectionIfc
listener
- - the disconnection event listenerpublic void run()
run
in interface java.lang.Runnable
run
in interface MultiplexConnectionIfc
run
in class java.lang.Thread
public org.exolab.core.mipc.MessageOutput register(java.lang.String label, org.exolab.core.mipc.MessageOutput out)
register
in interface MultiplexConnectionIfc
label
- The channel name to register formessageOutput
- Inbound messages are placed here
public void deregister(java.lang.String label)
deregister
in interface MultiplexConnectionIfc
label
- the name of the channel to unregisterpublic void disconnected()
disconnected
in interface MultiplexConnectionIfc
public java.lang.String getHost()
getHost
in interface MultiplexConnectionIfc
public int getPort()
getPort
in interface MultiplexConnectionIfc
protected void init(java.net.Socket socket) throws java.io.IOException
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |