Class CachingClientConnectionFactory

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.DisposableBean, 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 CachingClientConnectionFactory extends AbstractClientConnectionFactory implements org.springframework.beans.factory.DisposableBean
Connection factory that caches connections from the underlying target factory. The underlying factory will be reconfigured to have singleUse=true in order for the connection to be returned to the cache after use. Users should not subsequently set the underlying property to false, or cache starvation will result.
Since:
2.2
  • Constructor Details

    • CachingClientConnectionFactory

      public CachingClientConnectionFactory(AbstractClientConnectionFactory target, int poolSize)
      Construct a caching connection factory that delegates to the provided factory, with the provided pool size.
      Parameters:
      target - the target factory.
      poolSize - the number of connections to allow.
  • Method Details

    • setConnectionWaitTimeout

      public void setConnectionWaitTimeout(int connectionWaitTimeout)
      Parameters:
      connectionWaitTimeout - the new timeout.
      See Also:
      • SimplePool.setWaitTimeout(long)
    • setPoolSize

      public void setPoolSize(int poolSize)
      Parameters:
      poolSize - the new pool size.
      See Also:
      • SimplePool.setPoolSize(int)
    • getPoolSize

      public int getPoolSize()
      Returns:
      the pool size.
      See Also:
      • SimplePool.getPoolSize()
    • getIdleCount

      public int getIdleCount()
      Returns:
      the idle count.
      See Also:
      • SimplePool.getIdleCount()
    • getActiveCount

      public int getActiveCount()
      Returns:
      the active count.
      See Also:
      • SimplePool.getActiveCount()
    • getAllocatedCount

      public int getAllocatedCount()
      Returns:
      the allocated count.
      See Also:
      • SimplePool.getAllocatedCount()
    • obtainConnection

      public TcpConnectionSupport obtainConnection()
      Overrides:
      obtainConnection in class AbstractClientConnectionFactory
    • isRunning

      public boolean isRunning()
      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
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • setComponentName

      public void setComponentName(String componentName)
      Overrides:
      setComponentName in class org.springframework.integration.context.IntegrationObjectSupport
    • getComponentType

      public String getComponentType()
      Specified by:
      getComponentType in interface org.springframework.integration.support.context.NamedComponent
      Overrides:
      getComponentType in class org.springframework.integration.context.IntegrationObjectSupport
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • getSoTimeout

      public int getSoTimeout()
      Overrides:
      getSoTimeout in class AbstractConnectionFactory
      Returns:
      the soTimeout
    • setSoTimeout

      public void setSoTimeout(int soTimeout)
      Overrides:
      setSoTimeout in class AbstractConnectionFactory
      Parameters:
      soTimeout - the soTimeout to set
    • getSoReceiveBufferSize

      public int getSoReceiveBufferSize()
      Overrides:
      getSoReceiveBufferSize in class AbstractConnectionFactory
      Returns:
      the soReceiveBufferSize
    • setSoReceiveBufferSize

      public void setSoReceiveBufferSize(int soReceiveBufferSize)
      Overrides:
      setSoReceiveBufferSize in class AbstractConnectionFactory
      Parameters:
      soReceiveBufferSize - the soReceiveBufferSize to set
    • getSoSendBufferSize

      public int getSoSendBufferSize()
      Overrides:
      getSoSendBufferSize in class AbstractConnectionFactory
      Returns:
      the soSendBufferSize
    • setSoSendBufferSize

      public void setSoSendBufferSize(int soSendBufferSize)
      Overrides:
      setSoSendBufferSize in class AbstractConnectionFactory
      Parameters:
      soSendBufferSize - the soSendBufferSize to set
    • isSoTcpNoDelay

      public boolean isSoTcpNoDelay()
      Overrides:
      isSoTcpNoDelay in class AbstractConnectionFactory
      Returns:
      the soTcpNoDelay
    • setSoTcpNoDelay

      public void setSoTcpNoDelay(boolean soTcpNoDelay)
      Overrides:
      setSoTcpNoDelay in class AbstractConnectionFactory
      Parameters:
      soTcpNoDelay - the soTcpNoDelay to set
    • getSoLinger

      public int getSoLinger()
      Overrides:
      getSoLinger in class AbstractConnectionFactory
      Returns:
      the soLinger
    • setSoLinger

      public void setSoLinger(int soLinger)
      Overrides:
      setSoLinger in class AbstractConnectionFactory
      Parameters:
      soLinger - the soLinger to set
    • isSoKeepAlive

      public boolean isSoKeepAlive()
      Overrides:
      isSoKeepAlive in class AbstractConnectionFactory
      Returns:
      the soKeepAlive
    • setSoKeepAlive

      public void setSoKeepAlive(boolean soKeepAlive)
      Overrides:
      setSoKeepAlive in class AbstractConnectionFactory
      Parameters:
      soKeepAlive - the soKeepAlive to set
    • getSoTrafficClass

      public int getSoTrafficClass()
      Overrides:
      getSoTrafficClass in class AbstractConnectionFactory
      Returns:
      the soTrafficClass
    • setSoTrafficClass

      public void setSoTrafficClass(int soTrafficClass)
      Overrides:
      setSoTrafficClass in class AbstractConnectionFactory
      Parameters:
      soTrafficClass - the soTrafficClass to set
    • getHost

      public String getHost()
      Overrides:
      getHost in class AbstractConnectionFactory
      Returns:
      the host
    • getPort

      public int getPort()
      Overrides:
      getPort in class AbstractConnectionFactory
      Returns:
      the port
    • getSender

      public TcpSender getSender()
      Overrides:
      getSender in class AbstractConnectionFactory
      Returns:
      the first sender, if present.
    • getSerializer

      public org.springframework.core.serializer.Serializer<?> getSerializer()
      Overrides:
      getSerializer in class AbstractConnectionFactory
      Returns:
      the serializer
    • getDeserializer

      public org.springframework.core.serializer.Deserializer<?> getDeserializer()
      Overrides:
      getDeserializer in class AbstractConnectionFactory
      Returns:
      the deserializer
    • getMapper

      public TcpMessageMapper getMapper()
      Overrides:
      getMapper in class AbstractConnectionFactory
      Returns:
      the mapper
    • 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 CachedConnections, 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
    • setTaskExecutor

      public void setTaskExecutor(Executor taskExecutor)
      Overrides:
      setTaskExecutor in class AbstractConnectionFactory
      Parameters:
      taskExecutor - the taskExecutor to set
    • setDeserializer

      public void setDeserializer(org.springframework.core.serializer.Deserializer<?> deserializer)
      Overrides:
      setDeserializer in class AbstractConnectionFactory
      Parameters:
      deserializer - the deserializer to set
    • setSerializer

      public void setSerializer(org.springframework.core.serializer.Serializer<?> serializer)
      Overrides:
      setSerializer in class AbstractConnectionFactory
      Parameters:
      serializer - the serializer to set
    • setMapper

      public void setMapper(TcpMessageMapper mapper)
      Overrides:
      setMapper in class AbstractConnectionFactory
      Parameters:
      mapper - the mapper to set; defaults to a TcpMessageMapper
    • isSingleUse

      public boolean isSingleUse()
      Overrides:
      isSingleUse in class AbstractConnectionFactory
      Returns:
      the singleUse
    • setSingleUse

      public void setSingleUse(boolean singleUse)
      Ignored on this factory; connections are always cached in the pool. The underlying connection factory will have its singleUse property coerced to true (causing the connection to be returned). Setting it to false on the underlying factory after initialization will cause cache starvation.
      Overrides:
      setSingleUse in class AbstractConnectionFactory
      Parameters:
      singleUse - the singleUse.
    • setInterceptorFactoryChain

      public void setInterceptorFactoryChain(TcpConnectionInterceptorFactoryChain interceptorFactoryChain)
      Overrides:
      setInterceptorFactoryChain in class AbstractConnectionFactory
    • setLookupHost

      public void setLookupHost(boolean lookupHost)
      Description copied from class: AbstractConnectionFactory
      If true, DNS reverse lookup is done on the remote ip address. Default false: not all environments (e.g. Docker containers) perform reliable DNS resolution.
      Overrides:
      setLookupHost in class AbstractConnectionFactory
      Parameters:
      lookupHost - the lookupHost to set
    • isLookupHost

      public boolean isLookupHost()
      Overrides:
      isLookupHost in class AbstractConnectionFactory
      Returns:
      the lookupHost
    • forceClose

      public void forceClose(TcpConnection connection)
      Description copied from class: AbstractClientConnectionFactory
      Force close the connection and null the field if it's a shared connection.
      Overrides:
      forceClose in class AbstractClientConnectionFactory
      Parameters:
      connection - The connection.
    • enableManualListenerRegistration

      public void enableManualListenerRegistration()
      Description copied from class: AbstractClientConnectionFactory
      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.
      Overrides:
      enableManualListenerRegistration in class AbstractClientConnectionFactory
    • 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
    • destroy

      public void destroy() throws Exception
      Specified by:
      destroy in interface org.springframework.beans.factory.DisposableBean
      Throws:
      Exception