Class ConnectionFactory

  • Direct Known Subclasses:
    ConnectionFactoryConnectorPoolImpl, ConnectionFactoryNewConnectorImpl

    public abstract class ConnectionFactory
    extends java.lang.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 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​(java.net.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​(java.net.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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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​(java.net.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​(java.net.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 -