org.opennms.netmgt.provision.support
Class ConnectionFactory

java.lang.Object
  extended by org.opennms.netmgt.provision.support.ConnectionFactory

public class ConnectionFactory
extends Object

Factory for encapsulating a NioSocketConnector in such a way as to allow us to have a Semaphore limiting the number of active Connections across all Connectors.

There will be one ConnectionFactory for each discrete connection timeout value.

Adapted from original ConnectorFactory.

Version:
$Id: $
Author:
ranger, Duncan Mackintosh

Method Summary
 org.apache.mina.core.future.ConnectFuture connect(SocketAddress destination, org.apache.mina.core.session.IoSessionInitializer<? extends org.apache.mina.core.future.ConnectFuture> init)
          Connect to a remote socket.
static void dispose(ConnectionFactory factory, org.apache.mina.core.future.ConnectFuture connection)
          Free up the resources used by a connection and connection factory.
static ConnectionFactory getFactory(int timeoutInMillis)
          Get a new ConnectionFactory.
 org.apache.mina.core.future.ConnectFuture reConnect(SocketAddress destination, org.apache.mina.core.session.IoSessionInitializer<? extends org.apache.mina.core.future.ConnectFuture> init)
          Retry a connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getFactory

public static ConnectionFactory getFactory(int timeoutInMillis)
Get a new ConnectionFactory. If there is already a Factory with the desired timeout, you will get that one; otherwise a new one is created.

If org.opennms.netmgt.provision.maxConcurrentConnectors is set, this may block until a connector is available.

Parameters:
timeoutInMillis - Connection timeout
Returns:
An appropriate Factory

connect

public org.apache.mina.core.future.ConnectFuture connect(SocketAddress destination,
                                                         org.apache.mina.core.session.IoSessionInitializer<? extends org.apache.mina.core.future.ConnectFuture> init)
Connect to a remote socket. If org.opennms.netmgt.provision.maxConcurrentConnections is set, this may block until a connection slot is available.

You must dispose both the ConnectionFactory and ConncetFuture when done by calling dispose(ConnectionFactory, ConnectFuture).

Parameters:
destination - Destination address
init - Initialiser for the IoSession
Returns:
ConnectFuture from a Mina connect call

reConnect

public org.apache.mina.core.future.ConnectFuture reConnect(SocketAddress destination,
                                                           org.apache.mina.core.session.IoSessionInitializer<? extends org.apache.mina.core.future.ConnectFuture> init)
Retry a connection. This does not consume a connection slot, so will not block or throw IntrruptedExceptions. Use only if you have already acquired a connection slot using connect(SocketAddress, IoSessionInitializer).

Parameters:
destination -
init -
Returns:

dispose

public static void dispose(ConnectionFactory factory,
                           org.apache.mina.core.future.ConnectFuture connection)
Free up the resources used by a connection and connection factory.

Parameters:
factory -
connection -


Copyright © 2011. All Rights Reserved.