Class 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 reuse NioSocketConnector instances to improve performance and avoid file handle leaks caused by using too many NioSocketConnector 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 Detail

      • ConnectionFactory

        protected ConnectionFactory​(int timeoutInMillis)
        Create a new factory. Private because one should use getFactory(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 calling dispose(ConnectionFactory).

        Parameters:
        remoteAddress - Destination address
        init - 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 throw InterruptedException. 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 -