com.maverick.nio
Class SocketConnection

java.lang.Object
  extended by com.maverick.nio.SocketConnection
All Implemented Interfaces:
SelectorRegistrationListener, SocketHandler

public class SocketConnection
extends java.lang.Object
implements SocketHandler

This class implements a SocketHandler using a standard socket.

Author:
Lee David Painter

Field Summary
protected  boolean closed
           
protected  Daemon daemon
           
protected  DaemonContext daemonContext
           
protected  java.nio.channels.SelectionKey key
           
protected  ProtocolEngine protocolEngine
           
protected  SelectorThread selectorThread
           
protected  java.nio.channels.SocketChannel socketChannel
           
protected  java.nio.ByteBuffer socketDataIn
           
protected  java.nio.ByteBuffer socketDataOut
           
 
Constructor Summary
SocketConnection()
          Construct the socket.
 
Method Summary
 void closeConnection()
          Close this socket connection.
 DaemonContext getDaemonContext()
          Get the daemon process for this socket.
 IdleStateManager getIdleStates()
          Get the idle state manager.
 int getInterestedOps()
          Get the initial interested ops for this socket.
 java.net.SocketAddress getLocalAddress()
          Returns the local address to which the remote socket is connected.
 int getLocalPort()
          Returns the local port to which the remote socket is connected.
 int getPort()
          Returns the local port to which the remote socket is connected.
 ProtocolEngine getProtocolEngine()
          Get the protocol engine for this socket.
 java.net.SocketAddress getRemoteAddress()
          Returns the address of the remote socket.
 java.nio.channels.SocketChannel getSocketChannel()
          Get the SocketChannel for this socket.
 SelectorThread getThread()
          Get the selector thread for this connection
 void initialize(ProtocolEngine protocolEngine, Daemon daemon)
          Initialize the socket with the protocol engine and the daemon process.
protected  boolean isConnected()
          Is the socket still connected?
 boolean isSelectorThread()
          Is the current thread this sockets SelectorThread?
 boolean processReadEvent()
          The selector is ready to be read.
 boolean processWriteEvent()
          The selector is ready to be written to.
 void registrationCompleted(java.nio.channels.SelectableChannel channel, java.nio.channels.SelectionKey key, SelectorThread selectorThread)
          The sockets channel has completed registration.
 void setThread(SelectorThread thread)
          Set the selector thread for this connection
 void setWriteState(boolean wantsWrite)
          Sets the write state of the socket.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

socketChannel

protected java.nio.channels.SocketChannel socketChannel

protocolEngine

protected ProtocolEngine protocolEngine

daemonContext

protected DaemonContext daemonContext

selectorThread

protected SelectorThread selectorThread

key

protected java.nio.channels.SelectionKey key

daemon

protected Daemon daemon

socketDataIn

protected java.nio.ByteBuffer socketDataIn

socketDataOut

protected java.nio.ByteBuffer socketDataOut

closed

protected boolean closed
Constructor Detail

SocketConnection

public SocketConnection()
Construct the socket.

Method Detail

initialize

public void initialize(ProtocolEngine protocolEngine,
                       Daemon daemon)
Initialize the socket with the protocol engine and the daemon process.

Specified by:
initialize in interface SocketHandler
Parameters:
protocolEngine - ProtocolEngine
daemon - Daemon

registrationCompleted

public void registrationCompleted(java.nio.channels.SelectableChannel channel,
                                  java.nio.channels.SelectionKey key,
                                  SelectorThread selectorThread)
The sockets channel has completed registration.

Specified by:
registrationCompleted in interface SelectorRegistrationListener
Parameters:
channel - SelectableChannel
key - SelectionKey
selectorThread - SelectorThread

closeConnection

public void closeConnection()
Close this socket connection.


getProtocolEngine

public ProtocolEngine getProtocolEngine()
Get the protocol engine for this socket.

Returns:
ProtocolEngine

getDaemonContext

public DaemonContext getDaemonContext()
Get the daemon process for this socket.

Returns:
DaemonContext

getLocalAddress

public java.net.SocketAddress getLocalAddress()
Returns the local address to which the remote socket is connected.

Returns:

getLocalPort

public int getLocalPort()
Returns the local port to which the remote socket is connected.

Returns:

getPort

public int getPort()
Returns the local port to which the remote socket is connected.

Returns:

getRemoteAddress

public java.net.SocketAddress getRemoteAddress()
Returns the address of the remote socket.

Returns:

getSocketChannel

public java.nio.channels.SocketChannel getSocketChannel()
Get the SocketChannel for this socket.

Returns:
SocketChannel

getIdleStates

public IdleStateManager getIdleStates()
Get the idle state manager.

Returns:
IdleStateManager

isSelectorThread

public boolean isSelectorThread()
Is the current thread this sockets SelectorThread?

Returns:
boolean

setWriteState

public void setWriteState(boolean wantsWrite)
Sets the write state of the socket.

Parameters:
wantsWrite - boolean

isConnected

protected boolean isConnected()
Is the socket still connected?

Returns:
boolean

getThread

public SelectorThread getThread()
Get the selector thread for this connection

Returns:
SelectorThread

getInterestedOps

public int getInterestedOps()
Get the initial interested ops for this socket.

Specified by:
getInterestedOps in interface SocketHandler
Returns:
int

processReadEvent

public boolean processReadEvent()
The selector is ready to be read.

Specified by:
processReadEvent in interface SocketHandler
Returns:
boolean

processWriteEvent

public boolean processWriteEvent()
The selector is ready to be written to.

Specified by:
processWriteEvent in interface SocketHandler
Returns:
boolean

setThread

public void setThread(SelectorThread thread)
Set the selector thread for this connection

Specified by:
setThread in interface SocketHandler
Parameters:
thread - SelectorThread


Copyright © 2003-2008 SSHTools LTD. All Rights Reserved.