Class ConnectionFactory
- java.lang.Object
-
- org.opennms.netmgt.provision.support.ConnectionFactory
-
- Direct Known Subclasses:
ConnectionFactoryConnectorPoolImpl
,ConnectionFactoryNewConnectorImpl
public abstract class ConnectionFactory extends Object
Factory that controls creation of MINA
NioSocketConnector
connections. This will allow us to reuseNioSocketConnector
instances to improve performance and avoid file handle leaks caused by using too manyNioSocketConnector
instances simultaneously.Because of the way that the MINA API works, there will be one
ConnectionFactory
for each discrete connection timeout value.- Author:
- Seth, ranger, Duncan Mackintosh
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ConnectionFactory(int timeoutInMillis)
Create a new factory.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract org.apache.mina.core.future.ConnectFuture
connect(SocketAddress remoteAddress, org.apache.mina.core.session.IoSessionInitializer<? extends org.apache.mina.core.future.ConnectFuture> init, org.apache.mina.core.service.IoHandler handler)
Connect to a remote socket.protected abstract void
dispose()
Dispose of any resources that are held by the connection.static void
dispose(ConnectionFactory factory)
Free up the resources used by a connection and connection factory.static ConnectionFactory
getFactory(int timeoutInMillis)
Get a new ConnectionFactory.long
getTimeout()
abstract org.apache.mina.core.future.ConnectFuture
reConnect(SocketAddress remoteAddress, org.apache.mina.core.session.IoSessionInitializer<? extends org.apache.mina.core.future.ConnectFuture> init, org.apache.mina.core.service.IoHandler handler)
Retry a connection.
-
-
-
Constructor Detail
-
ConnectionFactory
protected ConnectionFactory(int timeoutInMillis)
Create a new factory. Private because one should usegetFactory(int)
-
-
Method Detail
-
getTimeout
public final long getTimeout()
- Returns:
- the timeout
-
getFactory
public static final 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 abstract org.apache.mina.core.future.ConnectFuture connect(SocketAddress remoteAddress, org.apache.mina.core.session.IoSessionInitializer<? extends org.apache.mina.core.future.ConnectFuture> init, org.apache.mina.core.service.IoHandler handler)
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 the
ConnectionFactory
when done by callingdispose(ConnectionFactory)
.- Parameters:
remoteAddress
- Destination addressinit
- Initialiser for the IoSession- Returns:
- ConnectFuture from a Mina connect call
-
reConnect
public abstract org.apache.mina.core.future.ConnectFuture reConnect(SocketAddress remoteAddress, org.apache.mina.core.session.IoSessionInitializer<? extends org.apache.mina.core.future.ConnectFuture> init, org.apache.mina.core.service.IoHandler handler)
Retry a connection. This does not consume a connection slot, so will not block or throwInterruptedException
. Use only if you have already acquired a connection slot using#connect(SocketAddress, IoSessionInitializer)
.- Parameters:
remoteAddress
-init
-- Returns:
-
dispose
protected abstract void dispose()
Dispose of any resources that are held by the connection.
-
dispose
public static final void dispose(ConnectionFactory factory)
Free up the resources used by a connection and connection factory.- Parameters:
factory
-connection
-
-
-