net.officefloor.plugin.socket.server.tcp.protocol
Class TcpConnectionHandler

java.lang.Object
  extended by net.officefloor.plugin.socket.server.tcp.protocol.TcpConnectionHandler
All Implemented Interfaces:
AsynchronousManagedObject, ManagedObject, ConnectionHandler, ServerTcpConnection

public class TcpConnectionHandler
extends Object
implements ConnectionHandler, AsynchronousManagedObject, ServerTcpConnection

TCP ConnectionHandler.

Author:
Daniel Sagenschneider

Constructor Summary
TcpConnectionHandler(Connection connection, long maxIdleTime)
          Initiate.
 
Method Summary
 InputBufferStream getInputBufferStream()
          Obtains the InputBufferStream that provides access to the data sent from the client.
 Object getLock()
          Obtains the lock that may be synchronized on to reduce locking overhead of making multiple calls on this ServerTcpConnection.
 Object getObject()
           
 OutputBufferStream getOutputBufferStream()
           Obtains the OutputBufferStream to write data back to the client.
 void handleIdleConnection(IdleContext context)
          Handles a Connection being idled.
 void handleRead(ReadContext context)
          Handles a read from the SocketChannel.
 void handleWrite(WriteContext context)
          Handles a potential write to the SocketChannel.
 void invokeProcess(int newConnectionFlowIndex, ManagedObjectExecuteContext<Indexed> executeContext)
           Called by the TcpServer to start processing the Connection of this ConnectionHandler.
 void registerAsynchronousCompletionListener(AsynchronousListener listener)
           
 void waitOnClientData()
           Flags for the ManagedObject to not execute another Task until further data is received from the client.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TcpConnectionHandler

public TcpConnectionHandler(Connection connection,
                            long maxIdleTime)
Initiate.

Parameters:
connection - Connection.
maxIdleTime - Maximum idle time for the Connection measured in milliseconds.
Method Detail

invokeProcess

public void invokeProcess(int newConnectionFlowIndex,
                          ManagedObjectExecuteContext<Indexed> executeContext)

Called by the TcpServer to start processing the Connection of this ConnectionHandler.

Called within the lock on the Connection.

Parameters:
newConnectionFlowIndex - Flow index to handle a new connection.
executeContext - ManagedObjectExecuteContext.

handleIdleConnection

public void handleIdleConnection(IdleContext context)
                          throws IOException
Description copied from interface: ConnectionHandler
Handles a Connection being idled.

Specified by:
handleIdleConnection in interface ConnectionHandler
Parameters:
context - IdleContext.
Throws:
IOException - If fails to handle idle Connection. Possibly from attempting to close it.

handleRead

public void handleRead(ReadContext context)
                throws IOException
Description copied from interface: ConnectionHandler
Handles a read from the SocketChannel.

Specified by:
handleRead in interface ConnectionHandler
Parameters:
context - ReadContext.
Throws:
IOException - If fails to obtain data from the ReadContext.

handleWrite

public void handleWrite(WriteContext context)
Description copied from interface: ConnectionHandler
Handles a potential write to the SocketChannel.

Specified by:
handleWrite in interface ConnectionHandler
Parameters:
context - WriteContext.

registerAsynchronousCompletionListener

public void registerAsynchronousCompletionListener(AsynchronousListener listener)
Specified by:
registerAsynchronousCompletionListener in interface AsynchronousManagedObject

getObject

public Object getObject()
Specified by:
getObject in interface ManagedObject

getLock

public Object getLock()
Description copied from interface: ServerTcpConnection
Obtains the lock that may be synchronized on to reduce locking overhead of making multiple calls on this ServerTcpConnection. In other words, it allows course grained locking.

Specified by:
getLock in interface ServerTcpConnection
Returns:
Lock that governs this ServerTcpConnection.

getInputBufferStream

public InputBufferStream getInputBufferStream()
Description copied from interface: ServerTcpConnection
Obtains the InputBufferStream that provides access to the data sent from the client.

Specified by:
getInputBufferStream in interface ServerTcpConnection
Returns:
InputBufferStream.

waitOnClientData

public void waitOnClientData()
                      throws IOException
Description copied from interface: ServerTcpConnection

Flags for the ManagedObject to not execute another Task until further data is received from the client.

On calling this the next time a Task is invoked using this ManagedObject, data will be available from the InputBufferStream.

Specified by:
waitOnClientData in interface ServerTcpConnection
Throws:
IOException - If fails to initiate waiting on client.

getOutputBufferStream

public OutputBufferStream getOutputBufferStream()
Description copied from interface: ServerTcpConnection

Obtains the OutputBufferStream to write data back to the client.

Closing the OutputBufferStream will result in closing the Connection.

Specified by:
getOutputBufferStream in interface ServerTcpConnection
Returns:
OutputBufferStream.


Copyright © 2005-2011. All Rights Reserved.