Class AbstractClientConnectionFactory

All Implemented Interfaces:
Aware, BeanFactoryAware, BeanNameAware, InitializingBean, ApplicationContextAware, ApplicationEventPublisherAware, Lifecycle, ExpressionCapable, ConnectionFactory, NamedComponent, ManageableLifecycle
Direct Known Subclasses:
CachingClientConnectionFactory, FailoverClientConnectionFactory, TcpNetClientConnectionFactory, TcpNioClientConnectionFactory, ThreadAffinityClientConnectionFactory

public abstract class AbstractClientConnectionFactory extends AbstractConnectionFactory
Abstract class for client connection factories; client connection factories establish outgoing connections.
Since:
2.0
Author:
Gary Russell, Artem Bilan, Trung Pham
  • Constructor Details

    • AbstractClientConnectionFactory

      public AbstractClientConnectionFactory(String host, int port)
      Construct a factory that will established connections to the host and port.
      Parameters:
      host - The host.
      port - The port.
  • Method Details

    • setConnectTimeout

      public void setConnectTimeout(int connectTimeout)
      Set the connection timeout in seconds. Defaults to 60.
      Parameters:
      connectTimeout - the timeout.
      Since:
      5.2
    • getConnectTimeout

      protected Duration getConnectTimeout()
    • enableManualListenerRegistration

      public void enableManualListenerRegistration()
      Set whether to automatically (default) or manually add a TcpListener to the connections created by this factory. By default, the factory automatically configures the listener. When manual registration is in place, incoming messages will be delayed until the listener is registered.
      Since:
      1.4.5
    • getConnectionTest

      @Nullable protected Predicate<TcpConnectionSupport> getConnectionTest()
      Get a Predicate that will be invoked to test a new connection; return true to accept the connection, false the reject.
      Returns:
      the predicate.
      Since:
      5.3
    • setConnectionTest

      public void setConnectionTest(@Nullable Predicate<TcpConnectionSupport> connectionTest)
      Set a Predicate that will be invoked to test a new connection; return true to accept the connection, false the reject.
      Parameters:
      connectionTest - the predicate.
      Since:
      5.3
    • getConnection

      public TcpConnectionSupport getConnection() throws InterruptedException
      Obtain a connection - if AbstractConnectionFactory.setSingleUse(boolean) was called with true, a new connection is returned; otherwise a single connection is reused for all requests while the connection remains open.
      Throws:
      InterruptedException - if interrupted.
    • obtainConnection

      protected TcpConnectionSupport obtainConnection() throws InterruptedException
      Throws:
      InterruptedException
    • obtainSharedConnection

      @Nullable protected final TcpConnectionSupport obtainSharedConnection() throws InterruptedException
      Throws:
      InterruptedException
    • obtainNewConnection

      protected final TcpConnectionSupport obtainNewConnection() throws InterruptedException
      Throws:
      InterruptedException
    • buildNewConnection

      protected TcpConnectionSupport buildNewConnection()
    • initializeConnection

      protected void initializeConnection(TcpConnectionSupport connection, Socket socket)
      Transfer attributes such as (de)serializers, singleUse etc to a new connection. When the connection factory has a reference to a TCPListener (to read responses), or for single use connections, the connection is executed. Single use connections need to read from the connection in order to close it after the socket timeout.
      Parameters:
      connection - The new connection.
      socket - The new socket.
    • setTheConnection

      protected void setTheConnection(TcpConnectionSupport theConnection)
      Parameters:
      theConnection - the theConnection to set
    • getTheConnection

      @Nullable protected TcpConnectionSupport getTheConnection()
      Returns:
      the theConnection
    • forceClose

      public void forceClose(TcpConnection connection)
      Force close the connection and null the field if it's a shared connection.
      Parameters:
      connection - The connection.