More information: http://www.cs.berkeley.edu/~mdw/proj/seda/

seda.sandStorm.lib.aSocket
Class ATcpConnection

java.lang.Object
  |
  +--seda.sandStorm.core.SimpleSink
        |
        +--seda.sandStorm.lib.aSocket.ATcpConnection
All Implemented Interfaces:
ProfilableIF, QueueElementIF, SinkIF

public class ATcpConnection
extends SimpleSink
implements QueueElementIF

An ATcpConnection represents an established connection on an asynchronous socket. It is used to send outgoing packets over the connection, and to initiate packet reads from the connection. When a packet arrives on this connection, an ATcpInPacket object will be pushed to the SinkIF specified by the startReader() call. The ATcpInPacket will contain a pointer to this ATcpConnection. This object also allows the connection to be flushed or closed.

Author:
Matt Welsh
See Also:
ATcpInPacket

Field Summary
 SockState sockState
           
 java.lang.Object userTag
          The application may use this field to associate some application-specific state with this connection.
 
Constructor Summary
protected ATcpConnection()
           
  ATcpConnection(ATcpClientSocket cliSock, java.net.InetAddress address, int port)
           
  ATcpConnection(ATcpServerSocket servSock, java.net.InetAddress address, int port)
           
 
Method Summary
 void close(SinkIF compQ)
          Close the socket.
 boolean enqueue_lossy(QueueElementIF buf)
          Enqueue an outgoing packet to be written to this socket.
 void enqueue_many(QueueElementIF[] bufarr)
          Enqueue a set of outgoing packets to be written to this socket.
 void enqueue(QueueElementIF buf)
          Enqueue an outgoing packet to be written to this socket.
 void flush(SinkIF compQ)
          Flush the socket.
 java.net.InetAddress getAddress()
          Return the address of the peer.
 ATcpClientSocket getClientSocket()
          Return the ATcpClientSocket from which this connection came.
 int getPort()
          Return the port of the peer.
 long getSequenceNumber()
          Returns the next sequence number for packets arriving on this connection.
 ATcpServerSocket getServerSocket()
          Return the ATcpServerSocket from which this connection came.
 int profileSize()
          Returns the profile size of this connection.
 int size()
          Returns the number of elements currently waiting in the sink.
 void startReader(SinkIF receiveQ)
          Associate a SinkIF with this connection and allow data to start flowing into it.
 void startReader(SinkIF receiveQ, int readClogTries)
          Associate a SinkIF with this connection and allow data to start flowing into it.
 java.lang.String toString()
           
 
Methods inherited from class seda.sandStorm.core.SimpleSink
enqueue_abort, enqueue_commit, enqueue_prepare, getEnqueuePredicate, setEnqueuePredicate
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

sockState

public SockState sockState

userTag

public java.lang.Object userTag
The application may use this field to associate some application-specific state with this connection. The aSocket layer will not read or modify this field in any way.
Constructor Detail

ATcpConnection

public ATcpConnection(ATcpClientSocket cliSock,
                      java.net.InetAddress address,
                      int port)

ATcpConnection

public ATcpConnection(ATcpServerSocket servSock,
                      java.net.InetAddress address,
                      int port)

ATcpConnection

protected ATcpConnection()
Method Detail

getAddress

public java.net.InetAddress getAddress()
Return the address of the peer.

getPort

public int getPort()
Return the port of the peer.

getServerSocket

public ATcpServerSocket getServerSocket()
Return the ATcpServerSocket from which this connection came. Returns null if this connection resulted from an ATcpClientSocket.

getClientSocket

public ATcpClientSocket getClientSocket()
Return the ATcpClientSocket from which this connection came. Returns null if this connection resulted from an ATcpServerSocket.

startReader

public void startReader(SinkIF receiveQ)
Associate a SinkIF with this connection and allow data to start flowing into it. When data is read, ATcpInPacket objects will be pushed into the given SinkIF. If this sink is full, the connection will attempt to allow packets to queue up in the O/S network stack (i.e. by not issuing further read calls on the socket). Until this method is called, no data will be read from the socket.

startReader

public void startReader(SinkIF receiveQ,
                        int readClogTries)
Associate a SinkIF with this connection and allow data to start flowing into it. When data is read, ATcpInPacket objects will be pushed into the given SinkIF. If this queue is full, the connection will attempt to allow packets to queue up in the O/S network stack (i.e. by not issuing further read calls on the socket). Until this method is called, no data will be read from the socket.
Parameters:
readClogTries - The number of times the aSocket layer will attempt to push a new entry onto the given SinkIF while the SinkIF is full. The queue entry will be dropped after this many tries. The default value is -1, which indicates that the aSocket layer will attempt to push the queue entry indefinitely.

enqueue

public void enqueue(QueueElementIF buf)
             throws SinkException
Enqueue an outgoing packet to be written to this socket.
Overrides:
enqueue in class SimpleSink
Following copied from interface: seda.sandStorm.api.SinkIF
Parameters:
element - The QueueElementIF to enqueue
Throws:
SinkFullException - Indicates that the sink is temporarily full.
SinkClosedException - Indicates that the sink is no longer being serviced.

enqueue_lossy

public boolean enqueue_lossy(QueueElementIF buf)
Enqueue an outgoing packet to be written to this socket. Drops the packet if it cannot be enqueued.
Overrides:
enqueue_lossy in class SimpleSink
Following copied from interface: seda.sandStorm.api.SinkIF
Parameters:
element - The QueueElementIF to enqueue
Returns:
true if the element was enqueued, false otherwise.

enqueue_many

public void enqueue_many(QueueElementIF[] bufarr)
                  throws SinkException
Enqueue a set of outgoing packets to be written to this socket.
Overrides:
enqueue_many in class SimpleSink
Following copied from interface: seda.sandStorm.api.SinkIF
Parameters:
elements - The element array to enqueue
Throws:
SinkFullException - Indicates that the sink is temporarily full.
SinkClosedException - Indicates that the sink is no longer being serviced.

close

public void close(SinkIF compQ)
           throws SinkClosedException
Close the socket. A SinkClosedEvent will be posted on the given compQ when the close is complete.

flush

public void flush(SinkIF compQ)
           throws SinkClosedException
Flush the socket. A SinkFlushedEvent will be posted on the given compQ when the close is complete.

size

public int size()
Returns the number of elements currently waiting in the sink.
Overrides:
size in class SimpleSink

getSequenceNumber

public long getSequenceNumber()
Returns the next sequence number for packets arriving on this connection. Returns 0 if this connection is not active. Note that this method may return an inaccurate sequence number since the call is not synchronized with new message arrivals that may increment the sequence number.

profileSize

public int profileSize()
Returns the profile size of this connection.
Overrides:
profileSize in class SimpleSink

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

More information: http://www.cs.berkeley.edu/~mdw/proj/seda/