net.sf.cindy.session.nio
Class ServerSocketChannelSession

java.lang.Object
  extended by net.sf.cindy.session.AbstractSession
      extended by net.sf.cindy.session.nio.AbstractChannelSession
          extended by net.sf.cindy.session.nio.ServerSocketChannelSession
All Implemented Interfaces:
Session

public class ServerSocketChannelSession
extends AbstractChannelSession

Server socket channel session. Application can override buildSession method to build custom session.

Version:
$id$
Author:
Roger Chen

Nested Class Summary
 
Nested classes/interfaces inherited from class net.sf.cindy.session.nio.AbstractChannelSession
AbstractChannelSession.ChannelReactorHandler
 
Constructor Summary
ServerSocketChannelSession()
           
 
Method Summary
protected  void buildSession(java.nio.channels.SocketChannel sc)
          Build accepted session.
protected  void doClose()
           
protected  void doStart()
           
 java.nio.channels.ServerSocketChannel getChannel()
          Get the server socket channel associted with the session.
 java.net.SocketAddress getLocalAddress()
          Get the local address which the session bind with.
protected  ReactorHandler getReactorHandler()
          Get reactor handler.
 java.net.SocketAddress getRemoteAddress()
          Get the remote address which the session connmected to.
 SessionType getSessionType()
          Get session type.
 java.net.ServerSocket getSocket()
          Get the server socket associted with the session.
 Future send(Packet packet, int priority)
           
 void setChannel(java.nio.channels.ServerSocketChannel ssc)
          Set the server socket channel which the session will used.
 void setLocalPort(int port)
          Set the port the server socket session listen to.
 
Methods inherited from class net.sf.cindy.session.nio.AbstractChannelSession
close, getReactor, isStarted, send, start
 
Methods inherited from class net.sf.cindy.session.AbstractSession
addSessionFilter, addSessionFilter, containsAttribute, dispatchException, flush, flush, getAttribute, getAttributes, getPacketDecoder, getPacketEncoder, getReadPacketSize, getSessionFilter, getSessionFilterChain, getSessionFilterChain, getSessionFilters, getSessionHandler, getSessionTimeout, removeAttribute, removeSessionFilter, send, send, setAttribute, setLocalAddress, setPacketDecoder, setPacketEncoder, setReadPacketSize, setRemoteAddress, setSessionHandler, setSessionTimeout
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServerSocketChannelSession

public ServerSocketChannelSession()
Method Detail

getSessionType

public SessionType getSessionType()
Description copied from interface: Session
Get session type.

Returns:
session type

getRemoteAddress

public java.net.SocketAddress getRemoteAddress()
Description copied from interface: Session
Get the remote address which the session connmected to.

Specified by:
getRemoteAddress in interface Session
Overrides:
getRemoteAddress in class AbstractSession
Returns:
the remote address

getLocalAddress

public java.net.SocketAddress getLocalAddress()
Description copied from interface: Session
Get the local address which the session bind with.

Specified by:
getLocalAddress in interface Session
Overrides:
getLocalAddress in class AbstractSession
Returns:
the local address

setLocalPort

public void setLocalPort(int port)
Set the port the server socket session listen to.

Parameters:
port - listen port
Throws:
java.lang.IllegalStateException

setChannel

public void setChannel(java.nio.channels.ServerSocketChannel ssc)
Set the server socket channel which the session will used.

Parameters:
ssc - server socket channel
Throws:
java.lang.IllegalStateException

getChannel

public java.nio.channels.ServerSocketChannel getChannel()
Get the server socket channel associted with the session.

Returns:
server socket channel

getSocket

public java.net.ServerSocket getSocket()
Get the server socket associted with the session.

Returns:
server socket

send

public Future send(Packet packet,
                   int priority)

getReactorHandler

protected ReactorHandler getReactorHandler()
Description copied from class: AbstractChannelSession
Get reactor handler.

Specified by:
getReactorHandler in class AbstractChannelSession
Returns:
reactor handler

buildSession

protected void buildSession(java.nio.channels.SocketChannel sc)
Build accepted session. Application can choose to start a session or close the channel. The default action is close the socket channel.

Parameters:
sc - the socket channel that server socket session accepted

doStart

protected void doStart()
                throws java.io.IOException
Overrides:
doStart in class AbstractChannelSession
Throws:
java.io.IOException

doClose

protected void doClose()
Overrides:
doClose in class AbstractChannelSession