|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectedu.cuny.cat.comm.ListenableConnection<M>
M - the type of messages that can be transmitted through the connection.public class ListenableConnection<M extends Message>
The class wraps the usual querying-based Connection to support
actively pushing Message to a listener.
It should be used in the following way:
Connection<Message> conn;
...
ReactiveConnection<Message> reactiveConn = ListenableConnection.makeReactiveConnection(conn);
reactiveConn.setListener(listener);
reactiveConn.start();
...
reactiveConn.stop();
reactiveConn.setListener(null); // (optional) ...
| Field Summary | |
|---|---|
protected ProactiveConnection<M> |
connection
|
protected ConnectionListener<M> |
listener
|
protected java.lang.Thread |
thread
|
static long |
THREAD_STACK_SIZE
|
protected static java.lang.ThreadGroup |
threadGroup
|
| Constructor Summary | |
|---|---|
ListenableConnection(ProactiveConnection<M> connection)
|
|
| Method Summary | ||
|---|---|---|
void |
close()
TODO: not safe to simply set listener null. |
|
ConnectionListener<M> |
getListener()
|
|
java.lang.String |
getLocalAddressInfo()
|
|
CatpMessage |
getMessage()
|
|
java.lang.String |
getRemoteAddressInfo()
|
|
java.lang.Thread |
getThread()
This is needed only for debug purpose. |
|
boolean |
isClosed()
checks whether the connection is closed or not. |
|
static
|
makeReactiveConnection(Connection<T> conn)
wraps a ProactiveConnection with ListenableConnection if
necessary to make it support registering-and-listening message passing,
i.e. |
|
void |
open()
opens the connection before sending or receiving any message. |
|
void |
run()
loops to attempt to read messages and notifies the listener of the arrival. |
|
void |
sendMessage(M msg)
sends a Message through this connection. |
|
void |
setListener(ConnectionListener<M> listener)
|
|
java.lang.String |
toString()
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final long THREAD_STACK_SIZE
protected ConnectionListener<M extends Message> listener
protected ProactiveConnection<M extends Message> connection
protected java.lang.Thread thread
protected static java.lang.ThreadGroup threadGroup
| Constructor Detail |
|---|
public ListenableConnection(ProactiveConnection<M> connection)
| Method Detail |
|---|
public CatpMessage getMessage()
throws CatException
CatException
public void sendMessage(M msg)
throws CatException
ConnectionMessage through this connection.
sendMessage in interface Connection<M extends Message>msg - message to be sent.
CatExceptionpublic void run()
run in interface java.lang.RunnableConnectionListener.messageArrived(Message)public void setListener(ConnectionListener<M> listener)
setListener in interface ReactiveConnection<M extends Message>public ConnectionListener<M> getListener()
getListener in interface ReactiveConnection<M extends Message>
public void open()
throws ConnectionException
Connection
open in interface Connection<M extends Message>ConnectionException
public void close()
throws ConnectionException
close in interface Connection<M extends Message>ConnectionExceptionpublic boolean isClosed()
Connection
isClosed in interface Connection<M extends Message>public java.lang.String getLocalAddressInfo()
getLocalAddressInfo in interface Connection<M extends Message>public java.lang.String getRemoteAddressInfo()
getRemoteAddressInfo in interface Connection<M extends Message>public static <T extends Message> ReactiveConnection<T> makeReactiveConnection(Connection<T> conn)
ProactiveConnection with ListenableConnection if
necessary to make it support registering-and-listening message passing,
i.e. an instance of ReactiveConnection.
public java.lang.Thread getThread()
connection and call listener to process messages.public java.lang.String toString()
toString in class java.lang.Object
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||