org.elkoserver.foundation.net
Class TCPConnection

java.lang.Object
  extended by org.elkoserver.foundation.net.ConnectionBase
      extended by org.elkoserver.foundation.net.TCPConnection
All Implemented Interfaces:
Callable<Object>, Connection, MessageReceiver

public class TCPConnection
extends ConnectionBase
implements MessageReceiver, Callable<Object>

An implementation of Connection that manages a non-blocking TCP connection to a single remote host.


Field Summary
 
Fields inherited from class org.elkoserver.foundation.net.ConnectionBase
theCloseMarker
 
Method Summary
 Object call()
          Invoked from the selector thread's work queue when the selector is ready to do a write.
 void close()
          Shut down the connection.
 boolean isWritable()
          Test if this connection is available for writes.
 String label()
          Get a short string for labelling this connection in log entries.
 void receiveMsg(Object message)
          Receive an incoming message from the remote end.
 void sendMsg(Object message)
          Send a message to the other end of the connection.
 String toString()
          Obtain a printable String representation of this connection.
 
Methods inherited from class org.elkoserver.foundation.net.ConnectionBase
connectionDied, enqueueHandlerFactory, enqueueReceivedMessage, id, setDebugMode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

call

public Object call()
Invoked from the selector thread's work queue when the selector is ready to do a write. If this connection has pending output to send, adjusts the selection key so that it will then attend to the availability of write opportunities when select() is called.

Specified by:
call in interface Callable<Object>

close

public void close()
Shut down the connection. Any queued messages will be sent.

Specified by:
close in interface Connection

isWritable

public boolean isWritable()
Test if this connection is available for writes. The idea here is to get an approximate sense, when arbitrating among a series of alternate possible connections to transmit something over. Do not do anything that depends for its correctness on the answer returned by this method being accurate.

Returns:
true if this connection appears to be writable, false if not.

label

public String label()
Get a short string for labelling this connection in log entries.

Returns:
a label for this connection

receiveMsg

public void receiveMsg(Object message)
Receive an incoming message from the remote end. This is called from the select thread. Consequently, it does not actually process the message but simply puts it on the run queue.

Specified by:
receiveMsg in interface MessageReceiver
Parameters:
message - the incoming message.

sendMsg

public void sendMsg(Object message)
Send a message to the other end of the connection.

Specified by:
sendMsg in interface Connection
Parameters:
message - The message to be sent.

toString

public String toString()
Obtain a printable String representation of this connection.

Overrides:
toString in class Object
Returns:
a printable representation of this connection.