org.apache.james.util.connection
Class SimpleConnectionManager

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.james.util.connection.SimpleConnectionManager
All Implemented Interfaces:
org.apache.avalon.cornerstone.services.connection.ConnectionManager, org.apache.avalon.framework.activity.Disposable, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.logger.LogEnabled, org.apache.avalon.framework.service.Serviceable, JamesConnectionManager

public class SimpleConnectionManager
extends org.apache.avalon.framework.logger.AbstractLogEnabled
implements JamesConnectionManager, org.apache.avalon.framework.service.Serviceable, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.activity.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.


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.james.services.JamesConnectionManager
ROLE
 
Constructor Summary
SimpleConnectionManager()
           
 
Method Summary
 void configure(org.apache.avalon.framework.configuration.Configuration configuration)
           
 void connect(java.lang.String name, java.net.ServerSocket socket, org.apache.avalon.cornerstone.services.connection.ConnectionHandlerFactory handlerFactory)
          Start managing a connection.
 void connect(java.lang.String name, java.net.ServerSocket socket, org.apache.avalon.cornerstone.services.connection.ConnectionHandlerFactory handlerFactory, int maxOpenConnections)
          Start managing a connection.
 void connect(java.lang.String name, java.net.ServerSocket socket, org.apache.avalon.cornerstone.services.connection.ConnectionHandlerFactory handlerFactory, org.apache.excalibur.thread.ThreadPool threadPool)
          Start managing a connection.
 void connect(java.lang.String name, java.net.ServerSocket socket, org.apache.avalon.cornerstone.services.connection.ConnectionHandlerFactory handlerFactory, org.apache.excalibur.thread.ThreadPool threadPool, int maxOpenConnections)
          Start managing a connection.
 void disconnect(java.lang.String name)
          This shuts down all handlers and socket, waiting for each to gracefully shutdown.
 void disconnect(java.lang.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
 void service(org.apache.avalon.framework.service.ServiceManager componentManager)
           
 
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(org.apache.avalon.framework.configuration.Configuration configuration)
               throws org.apache.avalon.framework.configuration.ConfigurationException
Specified by:
configure in interface org.apache.avalon.framework.configuration.Configurable
Throws:
org.apache.avalon.framework.configuration.ConfigurationException
See Also:
Configurable.configure(Configuration)

service

public void service(org.apache.avalon.framework.service.ServiceManager componentManager)
             throws org.apache.avalon.framework.service.ServiceException
Specified by:
service in interface org.apache.avalon.framework.service.Serviceable
Throws:
org.apache.avalon.framework.service.ServiceException
See Also:
Serviceable.service(ServiceManager)

dispose

public void dispose()
Disconnects all the underlying ServerConnections

Specified by:
dispose in interface org.apache.avalon.framework.activity.Disposable

connect

public void connect(java.lang.String name,
                    java.net.ServerSocket socket,
                    org.apache.avalon.cornerstone.services.connection.ConnectionHandlerFactory handlerFactory,
                    org.apache.excalibur.thread.ThreadPool threadPool,
                    int maxOpenConnections)
             throws java.lang.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 JamesConnectionManager
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:
java.lang.Exception - if an error occurs

connect

public void connect(java.lang.String name,
                    java.net.ServerSocket socket,
                    org.apache.avalon.cornerstone.services.connection.ConnectionHandlerFactory handlerFactory,
                    org.apache.excalibur.thread.ThreadPool threadPool)
             throws java.lang.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 org.apache.avalon.cornerstone.services.connection.ConnectionManager
Specified by:
connect in interface JamesConnectionManager
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:
java.lang.Exception - if an error occurs

connect

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

Specified by:
connect in interface org.apache.avalon.cornerstone.services.connection.ConnectionManager
Specified by:
connect in interface JamesConnectionManager
Parameters:
name - the name of connection
socket - the ServerSocket from which to
handlerFactory - the factory from which to acquire handlers
Throws:
java.lang.Exception - if an error occurs

connect

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

Specified by:
connect in interface JamesConnectionManager
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:
java.lang.Exception - if an error occurs

disconnect

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

Specified by:
disconnect in interface org.apache.avalon.cornerstone.services.connection.ConnectionManager
Parameters:
name - the name of connection
Throws:
java.lang.Exception - if an error occurs

disconnect

public void disconnect(java.lang.String name,
                       boolean tearDown)
                throws java.lang.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 org.apache.avalon.cornerstone.services.connection.ConnectionManager
Parameters:
name - the name of connection
tearDown - if true will forcefully tear down all handlers
Throws:
java.lang.Exception - if an error occurs

getMaximumNumberOfOpenConnections

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

Specified by:
getMaximumNumberOfOpenConnections in interface JamesConnectionManager
Returns:
the maximum number of connections


Copyright ? 2002-2009 The Apache Software Foundation. All Rights Reserved.