Class ThreadAffinityClientConnectionFactory

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 ThreadAffinityClientConnectionFactory extends AbstractClientConnectionFactory
A client connection factory that binds a connection to a thread. Close operations are ignored; to physically close a connection and release the thread local, invoke releaseConnection().
Since:
5.0
  • Constructor Details

  • Method Details

    • getConnection

      public TcpConnectionSupport getConnection() throws InterruptedException
      Description copied from class: AbstractClientConnectionFactory
      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.
      Specified by:
      getConnection in interface ConnectionFactory
      Overrides:
      getConnection in class AbstractClientConnectionFactory
      Throws:
      InterruptedException - if interrupted.
    • releaseConnection

      public void releaseConnection()
    • 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
    • getComponentName

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

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

      public void setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationEventPublisher)
      Specified by:
      setApplicationEventPublisher in interface org.springframework.context.ApplicationEventPublisherAware
      Overrides:
      setApplicationEventPublisher in class AbstractConnectionFactory
    • getComponentType

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

      public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
      Specified by:
      setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAware
      Overrides:
      setBeanFactory in class org.springframework.integration.context.IntegrationObjectSupport
    • setApplicationContext

      public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException
      Specified by:
      setApplicationContext in interface org.springframework.context.ApplicationContextAware
      Overrides:
      setApplicationContext in class org.springframework.integration.context.IntegrationObjectSupport
      Throws:
      org.springframework.beans.BeansException
    • getApplicationEventPublisher

      @Nullable public org.springframework.context.ApplicationEventPublisher getApplicationEventPublisher()
      Overrides:
      getApplicationEventPublisher in class AbstractConnectionFactory
    • setChannelResolver

      public void setChannelResolver(org.springframework.messaging.core.DestinationResolver<org.springframework.messaging.MessageChannel> channelResolver)
      Overrides:
      setChannelResolver in class org.springframework.integration.context.IntegrationObjectSupport
    • getExpression

      public org.springframework.expression.Expression getExpression()
      Specified by:
      getExpression in interface org.springframework.integration.context.ExpressionCapable
      Overrides:
      getExpression in class org.springframework.integration.context.IntegrationObjectSupport
    • 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.
    • 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
    • getConversionService

      public org.springframework.core.convert.ConversionService getConversionService()
      Overrides:
      getConversionService in class org.springframework.integration.context.IntegrationObjectSupport
    • 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
    • setHost

      public void setHost(String host)
      Description copied from class: AbstractConnectionFactory
      Set the host; requires the factory to be stopped.
      Overrides:
      setHost in class AbstractConnectionFactory
      Parameters:
      host - the host.
    • getHost

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

      public void setPort(int port)
      Description copied from class: AbstractConnectionFactory
      Set the port; requires the factory to be stopped.
      Overrides:
      setPort in class AbstractConnectionFactory
      Parameters:
      port - the port.
    • getApplicationContextId

      public String getApplicationContextId()
      Overrides:
      getApplicationContextId in class org.springframework.integration.context.IntegrationObjectSupport
    • getPort

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

      public TcpListener getListener()
      Overrides:
      getListener in class AbstractConnectionFactory
      Returns:
      the listener
    • getSender

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

      public List<TcpSender> getSenders()
      Description copied from class: AbstractConnectionFactory
      Return the list of senders.
      Overrides:
      getSenders in class AbstractConnectionFactory
      Returns:
      the senders.
    • 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)
      Description copied from class: AbstractConnectionFactory
      Registers a TcpListener to receive messages after the payload has been converted from the input data.
      Overrides:
      registerListener in class AbstractConnectionFactory
      Parameters:
      listener - the TcpListener.
    • setMessageBuilderFactory

      public void setMessageBuilderFactory(org.springframework.integration.support.MessageBuilderFactory messageBuilderFactory)
      Overrides:
      setMessageBuilderFactory in class org.springframework.integration.context.IntegrationObjectSupport
    • 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
    • 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
    • setNioHarvestInterval

      public void setNioHarvestInterval(int nioHarvestInterval)
      Description copied from class: AbstractConnectionFactory
      How often we clean up closed NIO connections if soTimeout is 0. Ignored when soTimeout > 0 because the clean up process is run as part of the timeout handling. Default 2000 milliseconds.
      Overrides:
      setNioHarvestInterval in class AbstractConnectionFactory
      Parameters:
      nioHarvestInterval - The interval in milliseconds.
    • setSslHandshakeTimeout

      public void setSslHandshakeTimeout(int sslHandshakeTimeout)
      Description copied from class: AbstractConnectionFactory
      Set the handshake timeout used when waiting for SSL handshake data; only applies to SSL connections, when using NIO.
      Overrides:
      setSslHandshakeTimeout in class AbstractConnectionFactory
      Parameters:
      sslHandshakeTimeout - the timeout.
    • setReadDelay

      public void setReadDelay(long readDelay)
      Description copied from class: AbstractConnectionFactory
      The delay (in milliseconds) before retrying a read after the previous attempt failed due to insufficient threads. Default 100.
      Overrides:
      setReadDelay in class AbstractConnectionFactory
      Parameters:
      readDelay - the readDelay to set.
    • 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()
      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
    • setTcpSocketSupport

      public void setTcpSocketSupport(TcpSocketSupport tcpSocketSupport)
      Overrides:
      setTcpSocketSupport in class AbstractConnectionFactory
    • getOpenConnectionIds

      public List<String> getOpenConnectionIds()
      Description copied from class: AbstractConnectionFactory
      Returns a list of (currently) open TcpConnection connection ids; allows, for example, broadcast operations to all open connections.
      Overrides:
      getOpenConnectionIds in class AbstractConnectionFactory
      Returns:
      the list of connection ids.
    • closeConnection

      public boolean closeConnection(String connectionId)
      Description copied from class: AbstractConnectionFactory
      Close a connection with the specified connection id.
      Overrides:
      closeConnection in class AbstractConnectionFactory
      Parameters:
      connectionId - the connection id.
      Returns:
      true if the connection was closed.
    • toString

      public String toString()
      Overrides:
      toString in class AbstractConnectionFactory