Class AbstractChainManager


  • public abstract class AbstractChainManager
    extends java.lang.Object
    Base class for a manager that takes responsibility for dynamically creating and managing instances of a transport plug-in.

    The connectivity configuration files should specify one or more dynamic chain manager instances for each transport, each of which will be instantiated with their own configuration. A manager instance can create and destroy chains, and also provides a method to create a new instance of the associated transport plug-in for each chain that has been created. Subclasses must provide a constructor with the same signature as AbstractChainManager(org.slf4j.Logger, ChainManagerConstructorParameters).

    See ChainManagerConstructorParameters for more information.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      java.util.Collection<ChainDefinition> chainDefinitions
      The configuration of the dynamic chain definitions that contain the transport associated with this manager.
      ChainManagerHost host
      The interface through which the host provides services required by chain managers.
      org.slf4j.Logger logger
      A slf4j logger to be used by this manager for anything which needs to be written to the host's log.
      java.lang.String managerName
      The name used in the configuration file for this dynamic chain manager.
      java.lang.String transportPluginName
      The name used in the configuration file for the transport plug-in that created this chain manager.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract AbstractTransport createTransport​(org.slf4j.Logger logger, ManagedTransportConstructorParameters params)
      Called by the connectivity framework creation of each chain, to request the manager to create and return a new instance of its associated transport.
      ChainDefinition getChainDefinition()
      Helper method to get the chain definition containing the transport associated with this manager, assuming there is only one.
      ChainDefinition getChainDefinition​(java.lang.String chainDefinitionId)
      Helper method to get the chain definition matching the specified id, or a singleton chain definition if no id was specified (null or empty).
      StatusReporter getStatusReporter()
      Allows reporting status information from this plug-in, such as connected/disconnected status and number of messages sent/received in each direction.
      abstract void shutdown()
      Called during host shutdown to indicate that the chain manager should stop any background processes and disconnect any remote connections.
      abstract void start()
      Called after the chain manager is created to indicate that it can register a channel lifecycle listener, make external connections, create threads, and create chains.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • logger

        public final org.slf4j.Logger logger
        A slf4j logger to be used by this manager for anything which needs to be written to the host's log. The host will take care of adding the transport and manager name to the messages logged using this object.
      • managerName

        public final java.lang.String managerName
        The name used in the configuration file for this dynamic chain manager.
      • transportPluginName

        public final java.lang.String transportPluginName
        The name used in the configuration file for the transport plug-in that created this chain manager.
      • host

        public final ChainManagerHost host
        The interface through which the host provides services required by chain managers.
      • chainDefinitions

        public final java.util.Collection<ChainDefinition> chainDefinitions
        The configuration of the dynamic chain definitions that contain the transport associated with this manager. The manager can use one or more of these when creating chains. Use of the helper methods getChainDefinition() and getChainDefinition(String) is recommended for most use cases. This data structure should usually not be modified after the constructor has returned, but if it is the caller must provide locking as it is not thread-safe.
    • Constructor Detail

      • AbstractChainManager

        public AbstractChainManager​(org.slf4j.Logger logger,
                                    ChainManagerConstructorParameters params)
                             throws java.lang.IllegalArgumentException,
                                    java.lang.Exception
        Constructor. A subclass should provide its own constructor with the same signature as this one.

        The constructor will be called once for each dynamic chain manager instance specified in the configuration. A typical implementation will check and process any manager configuration that was passed in; creation of threads, connections etc should not happen until the start() method is called.

        Parameters:
        logger - a slf4j Logger object which can be used to log to the host log file.
        params - an extensible interface providing access to the configuration for this manager and other capabilities.
        Throws:
        java.lang.IllegalArgumentException - should be thrown from the constructor if the configuration is invalid.
        java.lang.Exception - can be thrown by subclasses to indicate an internal error.
    • Method Detail

      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • createTransport

        public abstract AbstractTransport createTransport​(org.slf4j.Logger logger,
                                                          ManagedTransportConstructorParameters params)
                                                   throws java.lang.IllegalArgumentException,
                                                          java.lang.Exception
        Called by the connectivity framework creation of each chain, to request the manager to create and return a new instance of its associated transport.

        This will be called whenever a new chain involving this transport is created, whether that chain is being created by the manager itself or for some other reason such as a static configuration file entry.

        A typical implementation will invoke the constructor of the transport class with the same arguments, and in some cases pass additional information to the transport (such as a reference to the manager instance, or a connection needed by the transport instance) and will usually store a reference to the new transport instance in the chain manager to allow operations to be performed on it later.

        Parameters:
        logger - a slf4j Logger object which can be used to log to the host log file by the new transport.
        params - an extensible interface providing access to the configuration for the transport, and other capabilities.
        Throws:
        java.lang.IllegalArgumentException - should be thrown from if the configuration is invalid.
        java.lang.Exception - can be thrown to indicate an internal error.
      • start

        public abstract void start()
                            throws java.lang.Exception
        Called after the chain manager is created to indicate that it can register a channel lifecycle listener, make external connections, create threads, and create chains.
        Throws:
        java.lang.Exception - only if a fatal error occurred during startup.
      • shutdown

        public abstract void shutdown()
                               throws java.lang.Exception
        Called during host shutdown to indicate that the chain manager should stop any background processes and disconnect any remote connections.

        It is recommended that managers should destroy all chains they are managing as part of their implementation of this method.

        Any chains that still exist after the manager shutdown() method has returned will be destroyed automatically.

        ChainManagers must not create new chains or call any other methods on the ChainManagerHost interface after this method has returned.

        .
        Throws:
        java.lang.Exception
      • getChainDefinition

        public ChainDefinition getChainDefinition()
                                           throws java.lang.IllegalArgumentException
        Helper method to get the chain definition containing the transport associated with this manager, assuming there is only one.
        Returns:
        never null.
        Throws:
        java.lang.IllegalArgumentException - if there are zero or more than one chain definitions containing this transport.
      • getChainDefinition

        public ChainDefinition getChainDefinition​(java.lang.String chainDefinitionId)
                                           throws java.lang.IllegalArgumentException
        Helper method to get the chain definition matching the specified id, or a singleton chain definition if no id was specified (null or empty).
        Parameters:
        chainDefinitionId - can be null or empty to indicate that a singleton chain definition should be selected.
        Returns:
        never null.
        Throws:
        java.lang.IllegalArgumentException - if there are no matches, or more than one match and the chainDefinitionId was not specified.
      • getStatusReporter

        public StatusReporter getStatusReporter()
        Allows reporting status information from this plug-in, such as connected/disconnected status and number of messages sent/received in each direction.