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
,ComponentSourceAware
,ExpressionCapable
,ConnectionFactory
,NamedComponent
,ManageableLifecycle
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
connectionsMonitor, DEFAULT_REPLY_TIMEOUT, lifecycleMonitor
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, logger
-
Constructor Summary
ConstructorDescriptionThreadAffinityClientConnectionFactory
(AbstractClientConnectionFactory connectionFactory) -
Method Summary
Modifier and TypeMethodDescriptionboolean
closeConnection
(String connectionId) Close a connection with the specified connection id.void
Set whether to automatically (default) or manually add aTcpListener
to the connections created by this factory.void
forceClose
(TcpConnection connection) Force close the connection and null the field if it's a shared connection.Returns theApplicationContext.getId()
if theApplicationContext
is available.Will return the name of this component identified byIntegrationObjectSupport.componentName
field.Subclasses may implement this method to provide component type information.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.Deserializer<?>
Return the primary SpEL expression if this component is expression-based.getHost()
Returns a list of (currently) openTcpConnection
connection ids; allows, for example, broadcast operations to all open connections.int
getPort()
Return the list of senders.Serializer<?>
int
int
int
int
int
boolean
boolean
boolean
boolean
void
registerListener
(TcpListener listener) Registers a TcpListener to receive messages after the payload has been converted from the input data.void
registerSender
(TcpSender sender) Registers a TcpSender; for server sockets, used to provide connection information so a sender can be used to reply to incoming messages.void
void
setApplicationContext
(ApplicationContext applicationContext) void
setApplicationEventPublisher
(ApplicationEventPublisher applicationEventPublisher) void
setBeanFactory
(BeanFactory beanFactory) void
setChannelResolver
(DestinationResolver<MessageChannel> channelResolver) Specify theDestinationResolver
strategy to use.void
setComponentName
(String componentName) Sets the name of this component.void
setDeserializer
(Deserializer<?> deserializer) void
Set the host; requires the factory to be stopped.void
setInterceptorFactoryChain
(TcpConnectionInterceptorFactoryChain interceptorFactoryChain) void
setLookupHost
(boolean lookupHost) If true, DNS reverse lookup is done on the remote ip address.void
setMapper
(TcpMessageMapper mapper) void
setMessageBuilderFactory
(MessageBuilderFactory messageBuilderFactory) void
setNioHarvestInterval
(int nioHarvestInterval) How often we clean up closed NIO connections if soTimeout is 0.void
setPort
(int port) Set the port; requires the factory to be stopped.void
setReadDelay
(long readDelay) The delay (in milliseconds) before retrying a read after the previous attempt failed due to insufficient threads.void
setSerializer
(Serializer<?> serializer) void
setSoKeepAlive
(boolean soKeepAlive) void
setSoLinger
(int soLinger) void
setSoReceiveBufferSize
(int soReceiveBufferSize) void
setSoSendBufferSize
(int soSendBufferSize) void
setSoTcpNoDelay
(boolean soTcpNoDelay) void
setSoTimeout
(int soTimeout) void
setSoTrafficClass
(int soTrafficClass) void
setSslHandshakeTimeout
(int sslHandshakeTimeout) Set the handshake timeout used when waiting for SSL handshake data; only applies to SSL connections, when using NIO.void
setTaskExecutor
(Executor taskExecutor) void
setTcpSocketSupport
(TcpSocketSupport tcpSocketSupport) void
start()
void
stop()
Stops the server.toString()
Methods inherited from class org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory
buildNewConnection, getConnectionTest, getConnectTimeout, getTheConnection, initializeConnection, obtainConnection, obtainNewConnection, obtainSharedConnection, setConnectionTest, setConnectTimeout, setTheConnection
Methods 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, wrapConnection
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentDescription, getComponentSource, getIntegrationProperties, getMessageBuilderFactory, getTaskScheduler, isInitialized, setBeanName, setComponentDescription, setComponentSource, setConversionService, setPrimaryExpression, setTaskScheduler
-
Constructor Details
-
ThreadAffinityClientConnectionFactory
-
-
Method Details
-
getConnection
Description copied from class:AbstractClientConnectionFactory
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.- Specified by:
getConnection
in interfaceConnectionFactory
- Overrides:
getConnection
in classAbstractClientConnectionFactory
- 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 aTcpListener
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 classAbstractClientConnectionFactory
-
getComponentName
Description copied from class:IntegrationObjectSupport
Will return the name of this component identified byIntegrationObjectSupport.componentName
field. IfIntegrationObjectSupport.componentName
was not set this method will default to the 'beanName' of this component;- Specified by:
getComponentName
in interfaceNamedComponent
- Overrides:
getComponentName
in classIntegrationObjectSupport
-
setComponentName
Description copied from class:IntegrationObjectSupport
Sets the name of this component.- Overrides:
setComponentName
in classIntegrationObjectSupport
- Parameters:
componentName
- The component name.
-
setApplicationEventPublisher
- Specified by:
setApplicationEventPublisher
in interfaceApplicationEventPublisherAware
- Overrides:
setApplicationEventPublisher
in classAbstractConnectionFactory
-
getComponentType
Description copied from class:IntegrationObjectSupport
Subclasses may implement this method to provide component type information.- Specified by:
getComponentType
in interfaceNamedComponent
- Overrides:
getComponentType
in classIntegrationObjectSupport
-
setBeanFactory
- Specified by:
setBeanFactory
in interfaceBeanFactoryAware
- Overrides:
setBeanFactory
in classIntegrationObjectSupport
-
setApplicationContext
- Specified by:
setApplicationContext
in interfaceApplicationContextAware
- Overrides:
setApplicationContext
in classIntegrationObjectSupport
- Throws:
BeansException
-
getApplicationEventPublisher
- Overrides:
getApplicationEventPublisher
in classAbstractConnectionFactory
-
setChannelResolver
Description copied from class:IntegrationObjectSupport
Specify theDestinationResolver
strategy to use. The default is a BeanFactoryChannelResolver.- Overrides:
setChannelResolver
in classIntegrationObjectSupport
- Parameters:
channelResolver
- The channel resolver.
-
getExpression
Description copied from interface:ExpressionCapable
Return the primary SpEL expression if this component is expression-based.- Specified by:
getExpression
in interfaceExpressionCapable
- Overrides:
getExpression
in classIntegrationObjectSupport
- Returns:
- the expression as a String.
-
forceClose
Description copied from class:AbstractClientConnectionFactory
Force close the connection and null the field if it's a shared connection.- Overrides:
forceClose
in classAbstractClientConnectionFactory
- Parameters:
connection
- The connection.
-
getSoTimeout
public int getSoTimeout()- Overrides:
getSoTimeout
in classAbstractConnectionFactory
- Returns:
- the soTimeout
-
setSoTimeout
public void setSoTimeout(int soTimeout) - Overrides:
setSoTimeout
in classAbstractConnectionFactory
- Parameters:
soTimeout
- the soTimeout to set, in milliseconds
-
getSoReceiveBufferSize
public int getSoReceiveBufferSize()- Overrides:
getSoReceiveBufferSize
in classAbstractConnectionFactory
- Returns:
- the soReceiveBufferSize
-
setSoReceiveBufferSize
public void setSoReceiveBufferSize(int soReceiveBufferSize) - Overrides:
setSoReceiveBufferSize
in classAbstractConnectionFactory
- Parameters:
soReceiveBufferSize
- the soReceiveBufferSize to set
-
getSoSendBufferSize
public int getSoSendBufferSize()- Overrides:
getSoSendBufferSize
in classAbstractConnectionFactory
- Returns:
- the soSendBufferSize
-
setSoSendBufferSize
public void setSoSendBufferSize(int soSendBufferSize) - Overrides:
setSoSendBufferSize
in classAbstractConnectionFactory
- Parameters:
soSendBufferSize
- the soSendBufferSize to set
-
isSoTcpNoDelay
public boolean isSoTcpNoDelay()- Overrides:
isSoTcpNoDelay
in classAbstractConnectionFactory
- Returns:
- the soTcpNoDelay
-
setSoTcpNoDelay
public void setSoTcpNoDelay(boolean soTcpNoDelay) - Overrides:
setSoTcpNoDelay
in classAbstractConnectionFactory
- Parameters:
soTcpNoDelay
- the soTcpNoDelay to set
-
getSoLinger
public int getSoLinger()- Overrides:
getSoLinger
in classAbstractConnectionFactory
- Returns:
- the soLinger
-
setSoLinger
public void setSoLinger(int soLinger) - Overrides:
setSoLinger
in classAbstractConnectionFactory
- Parameters:
soLinger
- the soLinger to set
-
isSoKeepAlive
public boolean isSoKeepAlive()- Overrides:
isSoKeepAlive
in classAbstractConnectionFactory
- Returns:
- the soKeepAlive
-
setSoKeepAlive
public void setSoKeepAlive(boolean soKeepAlive) - Overrides:
setSoKeepAlive
in classAbstractConnectionFactory
- Parameters:
soKeepAlive
- the soKeepAlive to set
-
getConversionService
- Overrides:
getConversionService
in classIntegrationObjectSupport
-
getSoTrafficClass
public int getSoTrafficClass()- Overrides:
getSoTrafficClass
in classAbstractConnectionFactory
- Returns:
- the soTrafficClass
-
setSoTrafficClass
public void setSoTrafficClass(int soTrafficClass) - Overrides:
setSoTrafficClass
in classAbstractConnectionFactory
- Parameters:
soTrafficClass
- the soTrafficClass to set
-
setHost
Description copied from class:AbstractConnectionFactory
Set the host; requires the factory to be stopped.- Overrides:
setHost
in classAbstractConnectionFactory
- Parameters:
host
- the host.
-
getHost
- Overrides:
getHost
in classAbstractConnectionFactory
- 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 classAbstractConnectionFactory
- Parameters:
port
- the port.
-
getApplicationContextId
Description copied from class:IntegrationObjectSupport
Returns theApplicationContext.getId()
if theApplicationContext
is available.- Overrides:
getApplicationContextId
in classIntegrationObjectSupport
- Returns:
- The id, or null if there is no application context.
-
getPort
public int getPort()- Overrides:
getPort
in classAbstractConnectionFactory
- Returns:
- the port
-
getListener
- Overrides:
getListener
in classAbstractConnectionFactory
- Returns:
- the listener
-
getSender
- Overrides:
getSender
in classAbstractConnectionFactory
- Returns:
- the first sender, if present.
-
getSenders
Description copied from class:AbstractConnectionFactory
Return the list of senders.- Overrides:
getSenders
in classAbstractConnectionFactory
- Returns:
- the senders.
-
getSerializer
- Overrides:
getSerializer
in classAbstractConnectionFactory
- Returns:
- the serializer
-
getDeserializer
- Overrides:
getDeserializer
in classAbstractConnectionFactory
- Returns:
- the deserializer
-
getMapper
- Overrides:
getMapper
in classAbstractConnectionFactory
- Returns:
- the mapper
-
registerListener
Description copied from class:AbstractConnectionFactory
Registers a TcpListener to receive messages after the payload has been converted from the input data.- Overrides:
registerListener
in classAbstractConnectionFactory
- Parameters:
listener
- the TcpListener.
-
setMessageBuilderFactory
- Overrides:
setMessageBuilderFactory
in classIntegrationObjectSupport
-
registerSender
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 classAbstractConnectionFactory
- Parameters:
sender
- The sender
-
setTaskExecutor
- Overrides:
setTaskExecutor
in classAbstractConnectionFactory
- Parameters:
taskExecutor
- the taskExecutor to set
-
setDeserializer
- Overrides:
setDeserializer
in classAbstractConnectionFactory
- Parameters:
deserializer
- the deserializer to set
-
setSerializer
- Overrides:
setSerializer
in classAbstractConnectionFactory
- Parameters:
serializer
- the serializer to set
-
setMapper
- Overrides:
setMapper
in classAbstractConnectionFactory
- Parameters:
mapper
- the mapper to set; defaults to aTcpMessageMapper
-
setInterceptorFactoryChain
public void setInterceptorFactoryChain(TcpConnectionInterceptorFactoryChain interceptorFactoryChain) - Overrides:
setInterceptorFactoryChain
in classAbstractConnectionFactory
-
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 classAbstractConnectionFactory
- Parameters:
lookupHost
- the lookupHost to set
-
isLookupHost
public boolean isLookupHost()- Overrides:
isLookupHost
in classAbstractConnectionFactory
- 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 whensoTimeout > 0
because the clean up process is run as part of the timeout handling. Default 2000 milliseconds.- Overrides:
setNioHarvestInterval
in classAbstractConnectionFactory
- 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 classAbstractConnectionFactory
- 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 classAbstractConnectionFactory
- Parameters:
readDelay
- the readDelay to set.
-
start
public void start()- Specified by:
start
in interfaceLifecycle
- Specified by:
start
in interfaceManageableLifecycle
- Overrides:
start
in classAbstractConnectionFactory
-
stop
public void stop()Description copied from class:AbstractConnectionFactory
Stops the server.- Specified by:
stop
in interfaceLifecycle
- Specified by:
stop
in interfaceManageableLifecycle
- Overrides:
stop
in classAbstractConnectionFactory
-
isRunning
public boolean isRunning()- Specified by:
isRunning
in interfaceLifecycle
- Specified by:
isRunning
in interfaceManageableLifecycle
- Overrides:
isRunning
in classAbstractConnectionFactory
-
setTcpSocketSupport
- Overrides:
setTcpSocketSupport
in classAbstractConnectionFactory
-
getOpenConnectionIds
Description copied from class:AbstractConnectionFactory
Returns a list of (currently) openTcpConnection
connection ids; allows, for example, broadcast operations to all open connections.- Overrides:
getOpenConnectionIds
in classAbstractConnectionFactory
- Returns:
- the list of connection ids.
-
closeConnection
Description copied from class:AbstractConnectionFactory
Close a connection with the specified connection id.- Overrides:
closeConnection
in classAbstractConnectionFactory
- Parameters:
connectionId
- the connection id.- Returns:
- true if the connection was closed.
-
toString
- Overrides:
toString
in classAbstractConnectionFactory
-