org.apache.james.util.connection
Class SimpleConnectionManager

java.lang.Object
  |
  +--org.apache.avalon.framework.logger.AbstractLogEnabled
        |
        +--org.apache.james.util.connection.SimpleConnectionManager
All Implemented Interfaces:
Composable, Configurable, ConnectionManager, Disposable, LogEnabled

public class SimpleConnectionManager
extends AbstractLogEnabled
implements ConnectionManager, Composable, Configurable, Disposable

An implementation of ConnectionManager that supports configurable idle timeouts and a configurable value for the maximum number of client connections to a particular port.

Author:
Andrei Ivanov, Peter M. Goldstein

Field Summary
protected  int maxOpenConn
          The maximum number of client connections allowed per server connection.
protected  int timeout
          The idle timeout for the individual sockets spawed from the server socket.
 
Fields inherited from interface org.apache.avalon.cornerstone.services.connection.ConnectionManager
ROLE
 
Constructor Summary
SimpleConnectionManager()
           
 
Method Summary
 void compose(ComponentManager componentManager)
           
 void configure(Configuration configuration)
           
 void connect(String name, ServerSocket socket, ConnectionHandlerFactory handlerFactory)
          Start managing a connection.
 void connect(String name, ServerSocket socket, ConnectionHandlerFactory handlerFactory, int maxOpenConnections)
          Start managing a connection.
 void connect(String name, ServerSocket socket, ConnectionHandlerFactory handlerFactory, org.apache.avalon.excalibur.thread.ThreadPool threadPool)
          Start managing a connection.
 void connect(String name, ServerSocket socket, ConnectionHandlerFactory handlerFactory, org.apache.avalon.excalibur.thread.ThreadPool threadPool, int maxOpenConnections)
          Start managing a connection.
 void disconnect(String name)
          This shuts down all handlers and socket, waiting for each to gracefully shutdown.
 void disconnect(String name, boolean tearDown)
          This shuts down a connection.
 void dispose()
          Disconnects all the underlying ServerConnections
 int getMaximumNumberOfOpenConnections()
          Returns the default maximum number of open connections supported by this SimpleConnectionManager
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

timeout

protected int timeout
The idle timeout for the individual sockets spawed from the server socket.


maxOpenConn

protected int maxOpenConn
The maximum number of client connections allowed per server connection.

Constructor Detail

SimpleConnectionManager

public SimpleConnectionManager()
Method Detail

configure

public void configure(Configuration configuration)
               throws ConfigurationException
Specified by:
configure in interface Configurable
ConfigurationException
See Also:
Configurable.configure(Configuration)

compose

public void compose(ComponentManager componentManager)
             throws ComponentException
Specified by:
compose in interface Composable
ComponentException
See Also:
Composable.compose(ComponentManager)

dispose

public void dispose()
Disconnects all the underlying ServerConnections

Specified by:
dispose in interface Disposable

connect

public void connect(String name,
                    ServerSocket socket,
                    ConnectionHandlerFactory handlerFactory,
                    org.apache.avalon.excalibur.thread.ThreadPool threadPool,
                    int maxOpenConnections)
             throws Exception
Start managing a connection. Management involves accepting connections and farming them out to threads from pool to be handled.

Parameters:
name - the name of connection
socket - the ServerSocket from which to
handlerFactory - the factory from which to acquire handlers
threadPool - the thread pool to use
maxOpenConnections - the maximum number of open connections allowed for this server socket.
Throws:
Exception - if an error occurs

connect

public void connect(String name,
                    ServerSocket socket,
                    ConnectionHandlerFactory handlerFactory,
                    org.apache.avalon.excalibur.thread.ThreadPool threadPool)
             throws Exception
Start managing a connection. Management involves accepting connections and farming them out to threads from pool to be handled.

Specified by:
connect in interface ConnectionManager
Parameters:
name - the name of connection
socket - the ServerSocket from which to
handlerFactory - the factory from which to acquire handlers
threadPool - the thread pool to use
Throws:
Exception - if an error occurs

connect

public void connect(String name,
                    ServerSocket socket,
                    ConnectionHandlerFactory handlerFactory)
             throws Exception
Start managing a connection. This is similar to other connect method except that it uses default thread pool.

Specified by:
connect in interface ConnectionManager
Parameters:
name - the name of connection
socket - the ServerSocket from which to
handlerFactory - the factory from which to acquire handlers
Throws:
Exception - if an error occurs

connect

public void connect(String name,
                    ServerSocket socket,
                    ConnectionHandlerFactory handlerFactory,
                    int maxOpenConnections)
             throws Exception
Start managing a connection. This is similar to other connect method except that it uses default thread pool.

Parameters:
name - the name of connection
socket - the ServerSocket from which to
handlerFactory - the factory from which to acquire handlers
maxOpenConnections - the maximum number of open connections allowed for this server socket.
Throws:
Exception - if an error occurs

disconnect

public void disconnect(String name)
                throws Exception
This shuts down all handlers and socket, waiting for each to gracefully shutdown.

Specified by:
disconnect in interface ConnectionManager
Parameters:
name - the name of connection
Throws:
Exception - if an error occurs

disconnect

public void disconnect(String name,
                       boolean tearDown)
                throws Exception
This shuts down a connection. If tearDown is true then it will forcefully the connection and try to return as soon as possible. Otherwise it will behave the same as void disconnect( String name );

Specified by:
disconnect in interface ConnectionManager
Parameters:
name - the name of connection
tearDown - if true will forcefully tear down all handlers
Throws:
Exception - if an error occurs

getMaximumNumberOfOpenConnections

public int getMaximumNumberOfOpenConnections()
Returns the default maximum number of open connections supported by this SimpleConnectionManager

Returns:
the maximum number of connections


"Copyright © 1999-2002 Apache Jakarta Project. All Rights Reserved."