Class ThreadAffinityClientConnectionFactory
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory
org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory
org.springframework.integration.ip.tcp.connection.ThreadAffinityClientConnectionFactory
- All Implemented Interfaces:
Aware,BeanFactoryAware,BeanNameAware,InitializingBean,ApplicationContextAware,ApplicationEventPublisherAware,Lifecycle,ExpressionCapable,ConnectionFactory,NamedComponent,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
- Author:
- Gary Russell
-
Field Summary
Fields inherited from class org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory
DEFAULT_REPLY_TIMEOUT, lifecycleMonitorFields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, logger -
Constructor Summary
Constructors Constructor Description ThreadAffinityClientConnectionFactory(AbstractClientConnectionFactory connectionFactory) -
Method Summary
Modifier and Type Method Description booleancloseConnection(String connectionId)Close a connection with the specified connection id.voidenableManualListenerRegistration()Set whether to automatically (default) or manually add aTcpListenerto the connections created by this factory.voidforceClose(TcpConnection connection)Force close the connection and null the field if it's a shared connection.StringgetApplicationContextId()Returns theApplicationContext.getId()if theApplicationContextis available.ApplicationEventPublishergetApplicationEventPublisher()StringgetComponentName()Will return the name of this component identified byIntegrationObjectSupport.componentNamefield.StringgetComponentType()Subclasses may implement this method to provide component type information.TcpConnectionSupportgetConnection()Obtain a connection - ifAbstractConnectionFactory.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.ConversionServicegetConversionService()Deserializer<?>getDeserializer()ExpressiongetExpression()Return the primary SpEL expression if this component is expression-based.StringgetHost()TcpListenergetListener()TcpMessageMappergetMapper()List<String>getOpenConnectionIds()Returns a list of (currently) openTcpConnectionconnection ids; allows, for example, broadcast operations to all open connections.intgetPort()TcpSendergetSender()List<TcpSender>getSenders()Return the list of senders.Serializer<?>getSerializer()intgetSoLinger()intgetSoReceiveBufferSize()intgetSoSendBufferSize()intgetSoTimeout()intgetSoTrafficClass()booleanisLookupHost()booleanisRunning()booleanisSoKeepAlive()booleanisSoTcpNoDelay()voidregisterListener(TcpListener listener)Registers a TcpListener to receive messages after the payload has been converted from the input data.voidregisterSender(TcpSender sender)Registers a TcpSender; for server sockets, used to provide connection information so a sender can be used to reply to incoming messages.voidreleaseConnection()voidsetApplicationContext(ApplicationContext applicationContext)voidsetApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)voidsetBeanFactory(BeanFactory beanFactory)voidsetChannelResolver(DestinationResolver<MessageChannel> channelResolver)Specify theDestinationResolverstrategy to use.voidsetComponentName(String componentName)Sets the name of this component.voidsetDeserializer(Deserializer<?> deserializer)voidsetHost(String host)Set the host; requires the factory to be stopped.voidsetInterceptorFactoryChain(TcpConnectionInterceptorFactoryChain interceptorFactoryChain)voidsetLookupHost(boolean lookupHost)If true, DNS reverse lookup is done on the remote ip address.voidsetMapper(TcpMessageMapper mapper)voidsetMessageBuilderFactory(MessageBuilderFactory messageBuilderFactory)voidsetNioHarvestInterval(int nioHarvestInterval)How often we clean up closed NIO connections if soTimeout is 0.voidsetPort(int port)Set the port; requires the factory to be stopped.voidsetReadDelay(long readDelay)The delay (in milliseconds) before retrying a read after the previous attempt failed due to insufficient threads.voidsetSerializer(Serializer<?> serializer)voidsetSoKeepAlive(boolean soKeepAlive)voidsetSoLinger(int soLinger)voidsetSoReceiveBufferSize(int soReceiveBufferSize)voidsetSoSendBufferSize(int soSendBufferSize)voidsetSoTcpNoDelay(boolean soTcpNoDelay)voidsetSoTimeout(int soTimeout)voidsetSoTrafficClass(int soTrafficClass)voidsetSslHandshakeTimeout(int sslHandshakeTimeout)Set the handshake timeout used when waiting for SSL handshake data; only applies to SSL connections, when using NIO.voidsetTaskExecutor(Executor taskExecutor)voidsetTcpSocketSupport(TcpSocketSupport tcpSocketSupport)voidstart()voidstop()Stops the server.StringtoString()Methods inherited from class org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory
buildNewConnection, getConnectionTest, getConnectTimeout, getTheConnection, initializeConnection, obtainConnection, obtainNewConnection, obtainSharedConnection, setConnectionTest, setConnectTimeout, setTheConnectionMethods inherited from class org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory
addConnection, checkActive, delayRead, doAccept, getDelayedReads, getLifecycleMonitor, getReadDelay, getSslHandshakeTimeout, getTaskExecutor, getTcpSocketSupport, harvestClosedConnections, isActive, isSingleUse, onInit, processNioSelections, setActive, setLeaveOpen, setSingleUse, setSocketAttributes, unregisterSender, wrapConnectionMethods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, isInitialized, setBeanName, setConversionService, setPrimaryExpression, setTaskScheduler
-
Constructor Details
-
Method Details
-
getConnection
Description copied from class:AbstractClientConnectionFactoryObtain a connection - ifAbstractConnectionFactory.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:
getConnectionin interfaceConnectionFactory- Overrides:
getConnectionin classAbstractClientConnectionFactory- Throws:
InterruptedException- if interrupted.
-
releaseConnection
public void releaseConnection() -
enableManualListenerRegistration
public void enableManualListenerRegistration()Description copied from class:AbstractClientConnectionFactorySet whether to automatically (default) or manually add aTcpListenerto 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:
enableManualListenerRegistrationin classAbstractClientConnectionFactory
-
getComponentName
Description copied from class:IntegrationObjectSupportWill return the name of this component identified byIntegrationObjectSupport.componentNamefield. IfIntegrationObjectSupport.componentNamewas not set this method will default to the 'beanName' of this component;- Specified by:
getComponentNamein interfaceNamedComponent- Overrides:
getComponentNamein classIntegrationObjectSupport
-
setComponentName
Description copied from class:IntegrationObjectSupportSets the name of this component.- Overrides:
setComponentNamein classIntegrationObjectSupport- Parameters:
componentName- The component name.
-
setApplicationEventPublisher
- Specified by:
setApplicationEventPublisherin interfaceApplicationEventPublisherAware- Overrides:
setApplicationEventPublisherin classAbstractConnectionFactory
-
getComponentType
Description copied from class:IntegrationObjectSupportSubclasses may implement this method to provide component type information.- Specified by:
getComponentTypein interfaceNamedComponent- Overrides:
getComponentTypein classIntegrationObjectSupport
-
setBeanFactory
- Specified by:
setBeanFactoryin interfaceBeanFactoryAware- Overrides:
setBeanFactoryin classIntegrationObjectSupport
-
setApplicationContext
- Specified by:
setApplicationContextin interfaceApplicationContextAware- Overrides:
setApplicationContextin classIntegrationObjectSupport- Throws:
BeansException
-
getApplicationEventPublisher
- Overrides:
getApplicationEventPublisherin classAbstractConnectionFactory
-
setChannelResolver
Description copied from class:IntegrationObjectSupportSpecify theDestinationResolverstrategy to use. The default is a BeanFactoryChannelResolver.- Overrides:
setChannelResolverin classIntegrationObjectSupport- Parameters:
channelResolver- The channel resolver.
-
getExpression
Description copied from interface:ExpressionCapableReturn the primary SpEL expression if this component is expression-based.- Specified by:
getExpressionin interfaceExpressionCapable- Overrides:
getExpressionin classIntegrationObjectSupport- Returns:
- the expression as a String.
-
forceClose
Description copied from class:AbstractClientConnectionFactoryForce close the connection and null the field if it's a shared connection.- Overrides:
forceClosein classAbstractClientConnectionFactory- Parameters:
connection- The connection.
-
getSoTimeout
public int getSoTimeout()- Overrides:
getSoTimeoutin classAbstractConnectionFactory- Returns:
- the soTimeout
-
setSoTimeout
public void setSoTimeout(int soTimeout)- Overrides:
setSoTimeoutin classAbstractConnectionFactory- Parameters:
soTimeout- the soTimeout to set
-
getSoReceiveBufferSize
public int getSoReceiveBufferSize()- Overrides:
getSoReceiveBufferSizein classAbstractConnectionFactory- Returns:
- the soReceiveBufferSize
-
setSoReceiveBufferSize
public void setSoReceiveBufferSize(int soReceiveBufferSize)- Overrides:
setSoReceiveBufferSizein classAbstractConnectionFactory- Parameters:
soReceiveBufferSize- the soReceiveBufferSize to set
-
getSoSendBufferSize
public int getSoSendBufferSize()- Overrides:
getSoSendBufferSizein classAbstractConnectionFactory- Returns:
- the soSendBufferSize
-
setSoSendBufferSize
public void setSoSendBufferSize(int soSendBufferSize)- Overrides:
setSoSendBufferSizein classAbstractConnectionFactory- Parameters:
soSendBufferSize- the soSendBufferSize to set
-
isSoTcpNoDelay
public boolean isSoTcpNoDelay()- Overrides:
isSoTcpNoDelayin classAbstractConnectionFactory- Returns:
- the soTcpNoDelay
-
setSoTcpNoDelay
public void setSoTcpNoDelay(boolean soTcpNoDelay)- Overrides:
setSoTcpNoDelayin classAbstractConnectionFactory- Parameters:
soTcpNoDelay- the soTcpNoDelay to set
-
getSoLinger
public int getSoLinger()- Overrides:
getSoLingerin classAbstractConnectionFactory- Returns:
- the soLinger
-
setSoLinger
public void setSoLinger(int soLinger)- Overrides:
setSoLingerin classAbstractConnectionFactory- Parameters:
soLinger- the soLinger to set
-
isSoKeepAlive
public boolean isSoKeepAlive()- Overrides:
isSoKeepAlivein classAbstractConnectionFactory- Returns:
- the soKeepAlive
-
setSoKeepAlive
public void setSoKeepAlive(boolean soKeepAlive)- Overrides:
setSoKeepAlivein classAbstractConnectionFactory- Parameters:
soKeepAlive- the soKeepAlive to set
-
getConversionService
- Overrides:
getConversionServicein classIntegrationObjectSupport
-
getSoTrafficClass
public int getSoTrafficClass()- Overrides:
getSoTrafficClassin classAbstractConnectionFactory- Returns:
- the soTrafficClass
-
setSoTrafficClass
public void setSoTrafficClass(int soTrafficClass)- Overrides:
setSoTrafficClassin classAbstractConnectionFactory- Parameters:
soTrafficClass- the soTrafficClass to set
-
setHost
Description copied from class:AbstractConnectionFactorySet the host; requires the factory to be stopped.- Overrides:
setHostin classAbstractConnectionFactory- Parameters:
host- the host.
-
getHost
- Overrides:
getHostin classAbstractConnectionFactory- Returns:
- the host
-
setPort
public void setPort(int port)Description copied from class:AbstractConnectionFactorySet the port; requires the factory to be stopped.- Overrides:
setPortin classAbstractConnectionFactory- Parameters:
port- the port.
-
getApplicationContextId
Description copied from class:IntegrationObjectSupportReturns theApplicationContext.getId()if theApplicationContextis available.- Overrides:
getApplicationContextIdin classIntegrationObjectSupport- Returns:
- The id, or null if there is no application context.
-
getPort
public int getPort()- Overrides:
getPortin classAbstractConnectionFactory- Returns:
- the port
-
getListener
- Overrides:
getListenerin classAbstractConnectionFactory- Returns:
- the listener
-
getSender
- Overrides:
getSenderin classAbstractConnectionFactory- Returns:
- the first sender, if present.
-
getSenders
Description copied from class:AbstractConnectionFactoryReturn the list of senders.- Overrides:
getSendersin classAbstractConnectionFactory- Returns:
- the senders.
-
getSerializer
- Overrides:
getSerializerin classAbstractConnectionFactory- Returns:
- the serializer
-
getDeserializer
- Overrides:
getDeserializerin classAbstractConnectionFactory- Returns:
- the deserializer
-
getMapper
- Overrides:
getMapperin classAbstractConnectionFactory- Returns:
- the mapper
-
registerListener
Description copied from class:AbstractConnectionFactoryRegisters a TcpListener to receive messages after the payload has been converted from the input data.- Overrides:
registerListenerin classAbstractConnectionFactory- Parameters:
listener- the TcpListener.
-
setMessageBuilderFactory
- Overrides:
setMessageBuilderFactoryin classIntegrationObjectSupport
-
registerSender
Description copied from class:AbstractConnectionFactoryRegisters a TcpSender; for server sockets, used to provide connection information so a sender can be used to reply to incoming messages.- Overrides:
registerSenderin classAbstractConnectionFactory- Parameters:
sender- The sender
-
setTaskExecutor
- Overrides:
setTaskExecutorin classAbstractConnectionFactory- Parameters:
taskExecutor- the taskExecutor to set
-
setDeserializer
- Overrides:
setDeserializerin classAbstractConnectionFactory- Parameters:
deserializer- the deserializer to set
-
setSerializer
- Overrides:
setSerializerin classAbstractConnectionFactory- Parameters:
serializer- the serializer to set
-
setMapper
- Overrides:
setMapperin classAbstractConnectionFactory- Parameters:
mapper- the mapper to set; defaults to aTcpMessageMapper
-
setInterceptorFactoryChain
public void setInterceptorFactoryChain(TcpConnectionInterceptorFactoryChain interceptorFactoryChain)- Overrides:
setInterceptorFactoryChainin classAbstractConnectionFactory
-
setLookupHost
public void setLookupHost(boolean lookupHost)Description copied from class:AbstractConnectionFactoryIf true, DNS reverse lookup is done on the remote ip address. Default true.- Overrides:
setLookupHostin classAbstractConnectionFactory- Parameters:
lookupHost- the lookupHost to set
-
isLookupHost
public boolean isLookupHost()- Overrides:
isLookupHostin classAbstractConnectionFactory- Returns:
- the lookupHost
-
setNioHarvestInterval
public void setNioHarvestInterval(int nioHarvestInterval)Description copied from class:AbstractConnectionFactoryHow often we clean up closed NIO connections if soTimeout is 0. Ignored whensoTimeout > 0because the clean up process is run as part of the timeout handling. Default 2000 milliseconds.- Overrides:
setNioHarvestIntervalin classAbstractConnectionFactory- Parameters:
nioHarvestInterval- The interval in milliseconds.
-
setSslHandshakeTimeout
public void setSslHandshakeTimeout(int sslHandshakeTimeout)Description copied from class:AbstractConnectionFactorySet the handshake timeout used when waiting for SSL handshake data; only applies to SSL connections, when using NIO.- Overrides:
setSslHandshakeTimeoutin classAbstractConnectionFactory- Parameters:
sslHandshakeTimeout- the timeout.
-
setReadDelay
public void setReadDelay(long readDelay)Description copied from class:AbstractConnectionFactoryThe delay (in milliseconds) before retrying a read after the previous attempt failed due to insufficient threads. Default 100.- Overrides:
setReadDelayin classAbstractConnectionFactory- Parameters:
readDelay- the readDelay to set.
-
start
public void start()- Specified by:
startin interfaceLifecycle- Specified by:
startin interfaceManageableLifecycle- Overrides:
startin classAbstractConnectionFactory
-
stop
public void stop()Description copied from class:AbstractConnectionFactoryStops the server.- Specified by:
stopin interfaceLifecycle- Specified by:
stopin interfaceManageableLifecycle- Overrides:
stopin classAbstractConnectionFactory
-
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceLifecycle- Specified by:
isRunningin interfaceManageableLifecycle- Overrides:
isRunningin classAbstractConnectionFactory
-
setTcpSocketSupport
- Overrides:
setTcpSocketSupportin classAbstractConnectionFactory
-
getOpenConnectionIds
Description copied from class:AbstractConnectionFactoryReturns a list of (currently) openTcpConnectionconnection ids; allows, for example, broadcast operations to all open connections.- Overrides:
getOpenConnectionIdsin classAbstractConnectionFactory- Returns:
- the list of connection ids.
-
closeConnection
Description copied from class:AbstractConnectionFactoryClose a connection with the specified connection id.- Overrides:
closeConnectionin classAbstractConnectionFactory- Parameters:
connectionId- the connection id.- Returns:
- true if the connection was closed.
-
toString
- Overrides:
toStringin classAbstractConnectionFactory
-