org.neo.swarm.util.network.tcp
Class NIOTcpServer

java.lang.Object
  extended byjava.lang.Thread
      extended byorg.neo.swarm.util.network.tcp.NIOTcpServer
All Implemented Interfaces:
java.lang.Runnable, TcpServiceAPI

public class NIOTcpServer
extends java.lang.Thread
implements TcpServiceAPI

NBlocking ServerSocketFactory - pumps out incoming events onto the associated channels SocketStream that gets processed by the next available thread in the pool.

Author:
neil.avery

Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
NIOTcpServer(ListenCallback callback, ThreadPool pool, int bufferSize, java.net.InetAddress bind, int port, long timeout)
           
 
Method Summary
 boolean isStarted()
           
 void listen()
           
protected  void readDataFromSocket(java.nio.channels.SelectionKey key)
          Sample data handler method for a channel with data ready to read.
protected  void registerChannel(java.nio.channels.Selector selector, java.nio.channels.SelectableChannel channel, int ops, java.lang.Object attach)
          Register the given channel with the given selector for the given operations of interest
 void run()
           
 void startServer()
          Start the server pool, processing threads and bind to the inet address
 void stopListening()
           
 void stopServer()
          Stop the server from processing and more TCP incoming requests
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NIOTcpServer

public NIOTcpServer(ListenCallback callback,
                    ThreadPool pool,
                    int bufferSize,
                    java.net.InetAddress bind,
                    int port,
                    long timeout)
Method Detail

run

public void run()
Specified by:
run in interface java.lang.Runnable

listen

public void listen()
            throws java.lang.Exception
Throws:
java.lang.Exception

stopListening

public void stopListening()
                   throws java.lang.Exception
Throws:
java.lang.Exception

registerChannel

protected void registerChannel(java.nio.channels.Selector selector,
                               java.nio.channels.SelectableChannel channel,
                               int ops,
                               java.lang.Object attach)
                        throws java.lang.Exception
Register the given channel with the given selector for the given operations of interest

Throws:
java.lang.Exception

readDataFromSocket

protected void readDataFromSocket(java.nio.channels.SelectionKey key)
                           throws java.lang.Exception
Sample data handler method for a channel with data ready to read.

Parameters:
key - A SelectionKey object associated with a channel determined by the selector to be ready for reading. If the channel returns an EOF condition, it is closed here, which automatically invalidates the associated key. The selector will then de-register the channel on the next select call.
Throws:
java.lang.Exception

isStarted

public boolean isStarted()
Returns:
Returns the isStarted.

startServer

public void startServer()
Start the server pool, processing threads and bind to the inet address

Specified by:
startServer in interface TcpServiceAPI

stopServer

public void stopServer()
                throws java.lang.Exception
Stop the server from processing and more TCP incoming requests

Specified by:
stopServer in interface TcpServiceAPI
Throws:
java.lang.Exception


Copyright © 2001-2004 SWARM-ONE -First Generation (S)calable(W)ide(AR)ea(M)esh. All Rights Reserved.