edu.cuny.cat.comm
Class QueueBasedCatpConnection

java.lang.Object
  extended by edu.cuny.cat.comm.QueueBasedCatpConnection
All Implemented Interfaces:
Connection<CatpMessage>, ProactiveConnection<CatpMessage>

public class QueueBasedCatpConnection
extends java.lang.Object
implements ProactiveConnection<CatpMessage>

The implementation of Connection when QueueBasedInfrastructureImpl is used.

Version:
$Revision: 1.12 $
Author:
Jinzhong Niu

Field Summary
protected  java.lang.Object connector
          the Connector that requested to create this connection
protected  java.lang.String id
          an identifier for this connection
protected  org.apache.commons.collections15.Buffer<CatpMessage> messages
          the queue buffering incoming messages
protected  QueueBasedCatpConnection peer
          the other side of the connection that may call relayMessage(CatpMessage) to transmit messages.
 
Constructor Summary
QueueBasedCatpConnection(java.lang.Object connector, java.lang.String id)
           
 
Method Summary
 void close()
          closes this connection.
 java.lang.Object getConnector()
           
 java.lang.String getLocalAddressInfo()
           
 CatpMessage getMessage()
          reads a Message from this connection.
 QueueBasedCatpConnection getPeer()
           
 java.lang.String getRemoteAddressInfo()
           
 boolean isClosed()
          checks whether the connection is closed or not.
 void open()
          opens the connection before sending or receiving any message.
 void relayMessage(CatpMessage msg)
           
 void sendMessage(CatpMessage msg)
          sends a Message through this connection.
 void setConnector(java.lang.Object connector)
           
 void setPeer(QueueBasedCatpConnection peer)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

connector

protected java.lang.Object connector
the Connector that requested to create this connection


peer

protected QueueBasedCatpConnection peer
the other side of the connection that may call relayMessage(CatpMessage) to transmit messages.


messages

protected org.apache.commons.collections15.Buffer<CatpMessage> messages
the queue buffering incoming messages


id

protected java.lang.String id
an identifier for this connection

Constructor Detail

QueueBasedCatpConnection

public QueueBasedCatpConnection(java.lang.Object connector,
                                java.lang.String id)
Method Detail

getConnector

public java.lang.Object getConnector()

setConnector

public void setConnector(java.lang.Object connector)

getPeer

public QueueBasedCatpConnection getPeer()

setPeer

public void setPeer(QueueBasedCatpConnection peer)

sendMessage

public void sendMessage(CatpMessage msg)
                 throws CatException
Description copied from interface: Connection
sends a Message through this connection.

Specified by:
sendMessage in interface Connection<CatpMessage>
Parameters:
msg - message to be sent.
Throws:
CatException

relayMessage

public void relayMessage(CatpMessage msg)
                  throws CatException
Throws:
CatException

getMessage

public CatpMessage getMessage()
                       throws CatException
Description copied from interface: ProactiveConnection
reads a Message from this connection. It blocks if no messages are available.

Specified by:
getMessage in interface ProactiveConnection<CatpMessage>
Returns:
message received over the connection.
Throws:
MessageException
CatException

open

public void open()
          throws ConnectionException
Description copied from interface: Connection
opens the connection before sending or receiving any message.

Specified by:
open in interface Connection<CatpMessage>
Throws:
ConnectionException

close

public void close()
           throws ConnectionException
Description copied from interface: Connection
closes this connection.

Specified by:
close in interface Connection<CatpMessage>
Throws:
ConnectionException

isClosed

public boolean isClosed()
Description copied from interface: Connection
checks whether the connection is closed or not.

Specified by:
isClosed in interface Connection<CatpMessage>
Returns:
true if closed; false otherwise.

getLocalAddressInfo

public java.lang.String getLocalAddressInfo()
Specified by:
getLocalAddressInfo in interface Connection<CatpMessage>
Returns:
a string describing the address of the local end of this connection

getRemoteAddressInfo

public java.lang.String getRemoteAddressInfo()
Specified by:
getRemoteAddressInfo in interface Connection<CatpMessage>
Returns:
a string describing the address of the remote end of this connection