ecologylab.services.distributed.server
Class DoubleThreadedNIOServer
java.lang.Object
ecologylab.generic.Debug
ecologylab.services.distributed.impl.NIOServerBase
ecologylab.services.distributed.server.DoubleThreadedNIOServer
- All Implemented Interfaces:
- StartAndStoppable, NetworkingConstants, ServerConstants, SessionObjects, Shutdownable, NIOServerFrontend, java.lang.Runnable
- Direct Known Subclasses:
- DoubleThreadedAuthNIOServer, HttpGetServer, HTTPPostServer, NIOLoggingServer
public class DoubleThreadedNIOServer
- extends NIOServerBase
- implements ServerConstants
A server that uses NIO and two threads (one for handling IO, the other for
handling interfacing with messages).
Automatically processes and responds to any client RequestMessages.
Subclasses should generally override the generateContextManager hook method,
so that they can use their own, specific ContextManager in place of the
default.
- Author:
- Zachary O. Toups (toupsz@cs.tamu.edu)
|
Constructor Summary |
protected |
DoubleThreadedNIOServer(int portNumber,
java.net.InetAddress[] inetAddresses,
TranslationSpace requestTranslationSpace,
Scope objectRegistry,
int idleConnectionTimeout,
int maxPacketSize)
|
protected |
DoubleThreadedNIOServer(int portNumber,
java.net.InetAddress inetAddress,
TranslationSpace requestTranslationSpace,
Scope objectRegistry,
int idleConnectionTimeout,
int maxPacketSize)
|
|
Method Summary |
protected static java.net.InetAddress[] |
addressToAddresses(java.net.InetAddress address)
|
protected AbstractClientManager |
generateContextManager(java.lang.Object token,
java.nio.channels.SelectionKey sk,
TranslationSpace translationSpaceIn,
Scope registryIn)
Hook method to allow changing the ContextManager to enable specific extra
functionality. |
static DoubleThreadedNIOServer |
getInstance(int portNumber,
java.net.InetAddress[] inetAddress,
TranslationSpace requestTranslationSpace,
Scope objectRegistry,
int idleConnectionTimeout,
int maxPacketSize)
|
static DoubleThreadedNIOServer |
getInstance(int portNumber,
java.net.InetAddress inetAddress,
TranslationSpace requestTranslationSpace,
Scope objectRegistry,
int idleConnectionTimeout,
int maxPacketSize)
|
AbstractClientManager |
invalidate(java.lang.Object sessionId,
boolean permanent)
Performs any internal actions that should be taken whenever a client is disconnected. |
boolean |
isRunning()
|
void |
processRead(java.lang.Object sessionId,
NIOServerBackend base,
java.nio.channels.SelectionKey sk,
java.nio.ByteBuffer bs,
int bytesRead)
|
boolean |
restoreContextManagerFromSessionId(java.lang.Object oldSessionId,
AbstractClientManager newContextManager)
Attempts to switch the ContextManager for a SocketChannel. |
void |
run()
|
void |
shutdown()
Causes this to start to shutdown, and fires a SERVER_SHUTTING_DOWN event to all listeners. |
void |
start()
|
void |
stop()
|
| Methods inherited from class ecologylab.generic.Debug |
classSimpleName, closeLoggingFile, debug, debug, debug, debug, debugA, debugA, debugA, debugI, debugI, debugI, error, error, getClassName, getClassName, getInteractive, getPackageName, getPackageName, getPackageName, initialize, level, level, level, logToFile, print, print, println, println, println, println, println, println, printlnA, printlnA, printlnA, printlnI, printlnI, printlnI, printlnI, setLoggingFile, show, show, superString, toggleInteractive, toString, toString, warning, warning, weird, weird |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
maxPacketSize
protected int maxPacketSize
DoubleThreadedNIOServer
protected DoubleThreadedNIOServer(int portNumber,
java.net.InetAddress[] inetAddresses,
TranslationSpace requestTranslationSpace,
Scope objectRegistry,
int idleConnectionTimeout,
int maxPacketSize)
throws java.io.IOException,
java.net.BindException
- Throws:
java.io.IOException
java.net.BindException
DoubleThreadedNIOServer
protected DoubleThreadedNIOServer(int portNumber,
java.net.InetAddress inetAddress,
TranslationSpace requestTranslationSpace,
Scope objectRegistry,
int idleConnectionTimeout,
int maxPacketSize)
throws java.io.IOException,
java.net.BindException
- Throws:
java.io.IOException
java.net.BindException
addressToAddresses
protected static java.net.InetAddress[] addressToAddresses(java.net.InetAddress address)
getInstance
public static DoubleThreadedNIOServer getInstance(int portNumber,
java.net.InetAddress[] inetAddress,
TranslationSpace requestTranslationSpace,
Scope objectRegistry,
int idleConnectionTimeout,
int maxPacketSize)
throws java.io.IOException,
java.net.BindException
- Throws:
java.io.IOException
java.net.BindException
getInstance
public static DoubleThreadedNIOServer getInstance(int portNumber,
java.net.InetAddress inetAddress,
TranslationSpace requestTranslationSpace,
Scope objectRegistry,
int idleConnectionTimeout,
int maxPacketSize)
throws java.io.IOException,
java.net.BindException
- Throws:
java.io.IOException
java.net.BindException
processRead
public void processRead(java.lang.Object sessionId,
NIOServerBackend base,
java.nio.channels.SelectionKey sk,
java.nio.ByteBuffer bs,
int bytesRead)
throws BadClientException
- Specified by:
processRead in interface NIOServerFrontend
- Throws:
BadClientException - See
ecologylab.services.nio.servers.NIOServerFrontend#process(ecologylab.services.nio.NIOServerBackend,
java.nio.channels.SocketChannel, byte[], int)
generateContextManager
protected AbstractClientManager generateContextManager(java.lang.Object token,
java.nio.channels.SelectionKey sk,
TranslationSpace translationSpaceIn,
Scope registryIn)
- Hook method to allow changing the ContextManager to enable specific extra
functionality.
- Specified by:
generateContextManager in class NIOServerBase
- Parameters:
token - sc - translationSpaceIn - registryIn -
- Returns:
run
public void run()
- Specified by:
run in interface java.lang.Runnable
start
public void start()
- Specified by:
start in interface StartAndStoppable- Overrides:
start in class NIOServerBase
- See Also:
StartAndStoppable.start()
stop
public void stop()
- Specified by:
stop in interface StartAndStoppable- Overrides:
stop in class NIOServerBase
- See Also:
StartAndStoppable.stop()
shutdown
public void shutdown()
- Description copied from interface:
Shutdownable
- Causes this to start to shutdown, and fires a SERVER_SHUTTING_DOWN event to all listeners.
- Specified by:
shutdown in interface Shutdownable
- See Also:
Shutdownable.shutdown()
invalidate
public AbstractClientManager invalidate(java.lang.Object sessionId,
boolean permanent)
- Description copied from interface:
NIOServerFrontend
- Performs any internal actions that should be taken whenever a client is disconnected.
- Specified by:
invalidate in interface NIOServerFrontend
permanent - -
indicates whether the NIOServerFrontend should destroy the context manager object associated with the
given connection.
- Returns:
- the ContextManager object associated with sc that has been removed from the system.
- See Also:
ecologylab.services.distributed.server.NIOServerFrontend#invalidate(java.lang.Object,
ecologylab.services.distributed.impl.NIOServerBackend,
java.nio.channels.SocketChannel)
restoreContextManagerFromSessionId
public boolean restoreContextManagerFromSessionId(java.lang.Object oldSessionId,
AbstractClientManager newContextManager)
- Attempts to switch the ContextManager for a SocketChannel. oldId indicates
the session id that was used for the connection previously (in order to
find the correct ContextManager) and newContextManager is the
recently-created (and now, no longer necessary) ContextManager for the
connection.
- Specified by:
restoreContextManagerFromSessionId in interface NIOServerFrontend
- Parameters:
oldId - newContextManager -
- Returns:
- true if the restore was successful, false if it was not.
isRunning
public boolean isRunning()
- Returns:
- status of server in boolean