org.jscience.net
Class NetConnectionServer

java.lang.Object
  extended by java.lang.Thread
      extended by org.jscience.net.NetConnectionServer
All Implemented Interfaces:
java.lang.Runnable, Licensed

public class NetConnectionServer
extends java.lang.Thread
implements Licensed

A NetConnectionServer - once run() is called - listens to incoming requests from NetConnection objects with a signature provided by the ConnectionDispatcher. The server creates and starts a new Thread for each NetConnection with the right signature; the Thread is initialized with a Runnable object provided by the ConnectionDispatcher. The NetConnection objects used by the NetConnectionServer are SocketConnection objects.

See Also:
NetConnectionHandler, ConnectionDispatcher, NetConnection, SocketConnection

Nested Class Summary
static class NetConnectionServer.DefaultDispatcher
          The DefaultDispatcher provides a default ConnectionDispatcher that is used when the NetConnectionServer constructor in the enclosing class is called with a NetConnectionHandler
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
NetConnectionServer(int port, ConnectionDispatcher factory)
          the factory is responsible for providing the runnable objects that handle each connection in a separate thread
NetConnectionServer(int port, ConnectionDispatcher factory, Logger logger)
          if logger is not null, it will be used to log connection handling
NetConnectionServer(int port, NetConnectionHandler handler, java.lang.String signature)
          each connection made will run in a separate thread that delegates every message received to the given handler
NetConnectionServer(int port, NetConnectionHandler handler, java.lang.String signature, Logger logger)
          each connection made will run in a separate thread that delegates every message received to the given handler; if logger is not null, it will be used to log both: connection and message handling
 
Method Summary
protected  void finalize()
          DOCUMENT ME!
 int getLocalPort()
          DOCUMENT ME!
 Logger getLogger()
          DOCUMENT ME!
 java.util.List<NetConnection> getNetConnections()
          returns all NetConnections that have been created with this server
 java.net.ServerSocket getServerSocket()
          DOCUMENT ME!
 java.util.List<java.lang.Thread> getThreads()
          returns the list that contains all Threads that were instanciated by this server to handle incoming connections
 boolean isEnabled()
          DOCUMENT ME!
 void run()
          starts listening and creates a new Thread per every NetConnection made - handled by a NetConnectionHandler
 void setLogger(Logger logger)
          DOCUMENT ME!
 void shutdown()
          shutdown() does not close the connections that have already been established
static NetConnection waitForConnection(int port, java.lang.Object signature, int timeout)
          listens for a single connection to be made and returns a NetConnection if the connection made matches the signature
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NetConnectionServer

public NetConnectionServer(int port,
                           NetConnectionHandler handler,
                           java.lang.String signature)
                    throws java.io.IOException
each connection made will run in a separate thread that delegates every message received to the given handler

Throws:
java.io.IOException

NetConnectionServer

public NetConnectionServer(int port,
                           NetConnectionHandler handler,
                           java.lang.String signature,
                           Logger logger)
                    throws java.io.IOException
each connection made will run in a separate thread that delegates every message received to the given handler; if logger is not null, it will be used to log both: connection and message handling

Throws:
java.io.IOException

NetConnectionServer

public NetConnectionServer(int port,
                           ConnectionDispatcher factory)
                    throws java.io.IOException
the factory is responsible for providing the runnable objects that handle each connection in a separate thread

Throws:
java.io.IOException

NetConnectionServer

public NetConnectionServer(int port,
                           ConnectionDispatcher factory,
                           Logger logger)
                    throws java.io.IOException
if logger is not null, it will be used to log connection handling

Throws:
java.io.IOException
Method Detail

waitForConnection

public static NetConnection waitForConnection(int port,
                                              java.lang.Object signature,
                                              int timeout)
                                       throws java.io.IOException
listens for a single connection to be made and returns a NetConnection if the connection made matches the signature

Parameters:
port - DOCUMENT ME!
signature - DOCUMENT ME!
timeout - specified in milliseconds; if 0, the method waits indefinately until a connection is made or the serverSocket is closed
Returns:
DOCUMENT ME!
Throws:
java.io.IOException - DOCUMENT ME!
See Also:
SocketConnection.createServerConnection(ServerSocket,Object)

run

public void run()
starts listening and creates a new Thread per every NetConnection made - handled by a NetConnectionHandler

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

getLogger

public Logger getLogger()
DOCUMENT ME!

Returns:
DOCUMENT ME!

setLogger

public void setLogger(Logger logger)
DOCUMENT ME!

Parameters:
logger - DOCUMENT ME!

getThreads

public java.util.List<java.lang.Thread> getThreads()
returns the list that contains all Threads that were instanciated by this server to handle incoming connections

Returns:
DOCUMENT ME!

getNetConnections

public java.util.List<NetConnection> getNetConnections()
returns all NetConnections that have been created with this server

Returns:
DOCUMENT ME!

shutdown

public void shutdown()
shutdown() does not close the connections that have already been established


isEnabled

public boolean isEnabled()
DOCUMENT ME!

Returns:
DOCUMENT ME!

getLocalPort

public int getLocalPort()
DOCUMENT ME!

Returns:
DOCUMENT ME!

getServerSocket

public java.net.ServerSocket getServerSocket()
DOCUMENT ME!

Returns:
DOCUMENT ME!

finalize

protected void finalize()
DOCUMENT ME!

Overrides:
finalize in class java.lang.Object