Class FailoverClientConnectionFactory

java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware, org.springframework.context.ApplicationEventPublisherAware, org.springframework.context.Lifecycle, org.springframework.integration.context.ExpressionCapable, ConnectionFactory, org.springframework.integration.support.context.NamedComponent, org.springframework.integration.support.management.ManageableLifecycle

public class FailoverClientConnectionFactory
extends AbstractClientConnectionFactory
Given a list of connection factories, serves up TcpConnections that can iterate over a connection from each factory until the write succeeds or the list is exhausted.
Since:
2.2
  • Constructor Details

  • Method Details

    • setRefreshSharedInterval

      public void setRefreshSharedInterval​(long refreshSharedInterval)
      When using a shared connection singleUse is false, specify how long to wait before trying to fail back to start from the beginning of the factory list. Default is Long.MAX_VALUE - meaning only fail back when the current connection fails. Cannot be changed when using CachingClientConnectionFactory delegates.
      Parameters:
      refreshSharedInterval - the interval in milliseconds.
      Since:
      4.3.22
      See Also:
      AbstractConnectionFactory.setSingleUse(boolean), setCloseOnRefresh(boolean)
    • setCloseOnRefresh

      public void setCloseOnRefresh​(boolean closeOnRefresh)
      When using a shared connection singleUse is false, set this to true to close the old shared connection after a refresh. If this is false, the connection will remain open, but unused until its connection factory is again used to get a connection. Default is false for backwards compatibility. Cannot be changed when using CachingClientConnectionFactory delegates.
      Parameters:
      closeOnRefresh - true to close.
      Since:
      4.3.22
      See Also:
      AbstractConnectionFactory.setSingleUse(boolean), setRefreshSharedInterval(long)
    • onInit

      protected void onInit()
      Overrides:
      onInit in class AbstractConnectionFactory
    • registerListener

      public void registerListener​(TcpListener listener)
      Delegate TCP Client Connection factories that are used to receive data need a Listener to send the messages to. This applies to client factories used for outbound gateways or for a pair of collaborating channel adapters.

      During initialization, if a factory detects it has no listener it's listening logic (active thread) is terminated.

      The listener registered with a factory is provided to each connection it creates so it can call the onMessage() method.

      This code satisfies the first requirement in that this listener signals to the factory that it needs to run its listening logic.

      When we wrap actual connections with FailoverTcpConnections, the connection is given the wrapper as a listener, so it can enhance the headers in onMessage(); the wrapper then invokes the real listener supplied here, with the modified message.

      Overrides:
      registerListener in class AbstractConnectionFactory
      Parameters:
      listener - the TcpListener.
    • registerSender

      public void registerSender​(TcpSender sender)
      Description copied from class: AbstractConnectionFactory
      Registers a TcpSender; for server sockets, used to provide connection information so a sender can be used to reply to incoming messages.
      Overrides:
      registerSender in class AbstractConnectionFactory
      Parameters:
      sender - The sender
    • obtainConnection

      protected TcpConnectionSupport obtainConnection() throws java.lang.InterruptedException
      Overrides:
      obtainConnection in class AbstractClientConnectionFactory
      Throws:
      java.lang.InterruptedException
    • start

      public void start()
      Specified by:
      start in interface org.springframework.context.Lifecycle
      Specified by:
      start in interface org.springframework.integration.support.management.ManageableLifecycle
      Overrides:
      start in class AbstractConnectionFactory
    • stop

      public void stop()
      Description copied from class: AbstractConnectionFactory
      Stops the server.
      Specified by:
      stop in interface org.springframework.context.Lifecycle
      Specified by:
      stop in interface org.springframework.integration.support.management.ManageableLifecycle
      Overrides:
      stop in class AbstractConnectionFactory
    • isRunning

      public boolean isRunning()
      Returns true if all factories are running
      Specified by:
      isRunning in interface org.springframework.context.Lifecycle
      Specified by:
      isRunning in interface org.springframework.integration.support.management.ManageableLifecycle
      Overrides:
      isRunning in class AbstractConnectionFactory