com.faunos.util.net
Class HandletServer

java.lang.Object
  extended by com.faunos.util.net.HandletServer
Direct Known Subclasses:
HttpServer

public abstract class HandletServer
extends Object

A Handlet container implementing the server-side of a network protocol.

Author:
Babak Farhang

Field Summary
protected  Logger logger
           
 
Constructor Summary
  HandletServer(InetAddress host, int port, ExecutorService exec)
          Constructs a new instance with the given local host address and port number.
protected HandletServer(InetAddress host, int port, ExecutorService exec, Logger logger)
          Constructs a new instance with the given local host address and port number.
 
Method Summary
protected  ScatteringByteChannel inputChannel(SocketChannel socket)
          Returns a ScatteringByteChannel facade for the given socket.
 boolean isAlive()
          Determines whether the server is still running.
protected abstract  Handlet newHandlet()
          Returns a protocol-specific handlet.
protected  GatheringByteChannel outputChannel(SocketChannel socket)
          Returns a GatheringByteChannel facade for the given socket.
 void setProcessingHintThreshold(int threshold)
          Sets the threshold at which this container's HandletContext hints handlets that they should try processing non-network I/O based tasks asynchronously.
 void start()
          Starts the server.
 void stop()
          Stops the server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final Logger logger
Constructor Detail

HandletServer

public HandletServer(InetAddress host,
                     int port,
                     ExecutorService exec)
              throws IOException
Constructs a new instance with the given local host address and port number. The instance will run on the given exec service. The exec parameter is also exposed to Handlets through the HandletContext.executor() implementation provided by this class.

On return, the instance is listening on the specified port. To begin servicing requests, invoke start().

The logger's hierarchical name is set to the class name of this base implementation.

Throws:
IOException

HandletServer

protected HandletServer(InetAddress host,
                        int port,
                        ExecutorService exec,
                        Logger logger)
                 throws IOException
Constructs a new instance with the given local host address and port number. The instance will run on the given exec service. The exec parameter is also exposed to Handlets through the HandletContext.executor() implementation provided by this class.

On return, the instance is listening on the specified port. To begin servicing requests, invoke start().

Parameters:
logger - the logger used by the server. If null, then a logger using the class name of the implementation subclass is used.
Throws:
IOException
Method Detail

setProcessingHintThreshold

public void setProcessingHintThreshold(int threshold)
Sets the threshold at which this container's HandletContext hints handlets that they should try processing non-network I/O based tasks asynchronously.

The threshold works as follows. If the number of selected channels following a selection operation exceeds the threshold specified, then the hint is triggered for all HandletContexts exposed by this class.


start

public void start()
Starts the server.


isAlive

public final boolean isAlive()
Determines whether the server is still running.


stop

public void stop()
Stops the server.


newHandlet

protected abstract Handlet newHandlet()
Returns a protocol-specific handlet.


inputChannel

protected ScatteringByteChannel inputChannel(SocketChannel socket)
Returns a ScatteringByteChannel facade for the given socket. This base implementation just returns the argument.


outputChannel

protected GatheringByteChannel outputChannel(SocketChannel socket)
Returns a GatheringByteChannel facade for the given socket. This base implementation just returns the argument.



SourceForge.net Logo