org.codehaus.spice.netserve.connection.impl
Class DefaultAcceptorManager

java.lang.Object
  extended byorg.codehaus.spice.netserve.connection.impl.DefaultAcceptorManager
All Implemented Interfaces:
SocketAcceptorManager
Direct Known Subclasses:
AvalonAcceptorManager, DNAAcceptorManager, PicoAcceptorManager

public class DefaultAcceptorManager
extends Object
implements SocketAcceptorManager

Default implementation of SocketAcceptorManager that uses a thread per acceptor approach.

Note that on some OS/JVM combinations soTimeout must be set to non-0 value or else the ServerSocket will never get out of accept() system call and we wont be able to shutdown the server socket properly. However it can introduce performance problems if constantly timing out.

Version:
$Revision: 1.3 $ $Date: 2004/03/21 23:42:59 $
Author:
Peter Donald, Mauro Talevi

Constructor Summary
DefaultAcceptorManager()
           
 
Method Summary
 void connect(String name, ServerSocket socket, RequestHandler handler)
          Start accepting connections from a socket and passing connections to specified handler.
 void disconnect(String name)
          This shuts down the acceptor and the associated ServerSocket.
protected  AcceptorMonitor getMonitor()
          Return the monitor used by manager.
protected  int getShutdownTimeout()
          Return the shutdownTimeout.
 boolean isConnected(String name)
          Return true if acceptor with specified name exists.
 void setMonitor(AcceptorMonitor monitor)
          Set the AcceptorMonitor that receives events when changes occur.
 void setShutdownTimeout(int shutdownTimeout)
          Set timeout for shutting down handlers.
 void setSoTimeout(int soTimeout)
          Set the value that we are to set SO_TIMEOUT to if the user has not already set the timeout.
 void shutdownAcceptors()
          Dispose the ConnectionManager which involves shutting down all the connected acceptors.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultAcceptorManager

public DefaultAcceptorManager()
Method Detail

setMonitor

public void setMonitor(AcceptorMonitor monitor)
Set the AcceptorMonitor that receives events when changes occur.

Parameters:
monitor - the AcceptorMonitor that receives events when changes occur.

setSoTimeout

public void setSoTimeout(int soTimeout)
Set the value that we are to set SO_TIMEOUT to if the user has not already set the timeout. Defaults to 1000 (1s timeout).

Parameters:
soTimeout - the timeout value

setShutdownTimeout

public void setShutdownTimeout(int shutdownTimeout)
Set timeout for shutting down handlers. The timeout defaults to 0 which means wait indefinetly.

Parameters:
shutdownTimeout - the timeout

getShutdownTimeout

protected int getShutdownTimeout()
Return the shutdownTimeout.

Returns:
the shutdownTimeout

shutdownAcceptors

public void shutdownAcceptors()
Dispose the ConnectionManager which involves shutting down all the connected acceptors.


connect

public void connect(String name,
                    ServerSocket socket,
                    RequestHandler handler)
             throws Exception
Start accepting connections from a socket and passing connections to specified handler.

Specified by:
connect in interface SocketAcceptorManager
Parameters:
name - the name of connection. This serves as a key used to shutdown acceptor.
socket - the ServerSocket from which connections are accepted
Throws:
Exception - if unable to initiate connection management. This could be due to the key already being used for another acceptor, the serversocket being closed, the handler being null etc.

isConnected

public boolean isConnected(String name)
Return true if acceptor with specified name exists.

Specified by:
isConnected in interface SocketAcceptorManager
Parameters:
name - the name
Returns:
true if acceptor with specified name exists.

disconnect

public void disconnect(String name)
This shuts down the acceptor and the associated ServerSocket.

Specified by:
disconnect in interface SocketAcceptorManager
Parameters:
name - the name of connection
Throws:
IllegalArgumentException - if no connection with specified name

getMonitor

protected AcceptorMonitor getMonitor()
Return the monitor used by manager.

Returns:
the monitor used by manager.


Copyright © 1999-2004 Codehaus. All Rights Reserved.