net.officefloor.plugin.socket.server.impl
Class SocketListener<CH extends ConnectionHandler>

java.lang.Object
  extended by net.officefloor.plugin.socket.server.impl.SocketListener<CH>
All Implemented Interfaces:
Task<ConnectionManager<CH>,SocketListener.SocketListenerDependencies,Indexed>, ConnectionHandlerContext, IdleContext, ReadContext, WriteContext

public class SocketListener<CH extends ConnectionHandler>
extends Object
implements Task<ConnectionManager<CH>,SocketListener.SocketListenerDependencies,Indexed>, ReadContext, WriteContext, IdleContext

Listens to Socket instances.

Author:
Daniel Sagenschneider

Nested Class Summary
static class SocketListener.SocketListenerDependencies
          Keys for the dependencies for the SocketListener.
 
Field Summary
static int UNBOUNDED_MAX_CONNECTIONS
          Value to indicate an unbounded number of Connection instances can be registered.
 
Constructor Summary
SocketListener(SelectorFactory selectorFactory, Server<CH> server, int maxCommunications)
          Initiate.
 
Method Summary
 Object doTask(TaskContext<ConnectionManager<CH>,SocketListener.SocketListenerDependencies,Indexed> context)
           
 Object getContextObject()
          Obtains the context bound object.
 InputBufferStream getInputBufferStream()
          Obtains the InputBufferStream to read data from the client.
 long getTime()
           Obtains the current time in milliseconds.
 void processRequest(Object attachment)
          Flags that the request has been received.
 void setCloseConnection(boolean isClose)
          Flags to close the Connection.
 void setContextObject(Object contextObject)
          Specifies the context bound object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNBOUNDED_MAX_CONNECTIONS

public static final int UNBOUNDED_MAX_CONNECTIONS
Value to indicate an unbounded number of Connection instances can be registered.

See Also:
Constant Field Values
Constructor Detail

SocketListener

public SocketListener(SelectorFactory selectorFactory,
                      Server<CH> server,
                      int maxCommunications)
Initiate.

Parameters:
selectorFactory - SelectorFactory.
server - Server.
maxCommunications - Maximum number of Connection instances that can be registered with this SocketListener.
Method Detail

doTask

public Object doTask(TaskContext<ConnectionManager<CH>,SocketListener.SocketListenerDependencies,Indexed> context)
              throws Exception
Specified by:
doTask in interface Task<ConnectionManager<CH extends ConnectionHandler>,SocketListener.SocketListenerDependencies,Indexed>
Throws:
Exception

setCloseConnection

public void setCloseConnection(boolean isClose)
Description copied from interface: ConnectionHandlerContext
Flags to close the Connection.

Specified by:
setCloseConnection in interface ConnectionHandlerContext
Parameters:
isClose - true to close the Connection.

getTime

public long getTime()
Description copied from interface: ConnectionHandlerContext

Obtains the current time in milliseconds.

This should return similar to System.currentTimeMillis() but is provided to cache time for multiple quick operations that require only estimates of time.

Note CPU operations should be in the nanoseconds.

Specified by:
getTime in interface ConnectionHandlerContext
Returns:
Time measured in milliseconds.

getContextObject

public Object getContextObject()
Description copied from interface: ConnectionHandlerContext
Obtains the context bound object.

Specified by:
getContextObject in interface ConnectionHandlerContext
Returns:
Context bound object.

setContextObject

public void setContextObject(Object contextObject)
Description copied from interface: ConnectionHandlerContext
Specifies the context bound object.

Specified by:
setContextObject in interface ConnectionHandlerContext
Parameters:
contextObject - Context bound object.

getInputBufferStream

public InputBufferStream getInputBufferStream()
Description copied from interface: ReadContext
Obtains the InputBufferStream to read data from the client.

Specified by:
getInputBufferStream in interface ReadContext
Returns:
InputBufferStream.

processRequest

public void processRequest(Object attachment)
                    throws IOException
Description copied from interface: ReadContext
Flags that the request has been received. This will subsequently have the Server process the request.

Specified by:
processRequest in interface ReadContext
Parameters:
attachment - Optional attachment for the request. May be null.
Throws:
IOException - If fails to process request.


Copyright © 2005-2011. All Rights Reserved.