Class CachingClientConnectionFactory
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.CachingClientConnectionFactory
- All Implemented Interfaces:
- Aware,- BeanFactoryAware,- BeanNameAware,- DisposableBean,- InitializingBean,- ApplicationContextAware,- ApplicationEventPublisherAware,- Lifecycle,- ExpressionCapable,- ConnectionFactory,- NamedComponent,- ManageableLifecycle
public class CachingClientConnectionFactory
extends AbstractClientConnectionFactory
implements 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
- Author:
- Gary Russell, Christian Tzolov, Artem Bilan
- 
Field SummaryFields inherited from class org.springframework.integration.ip.tcp.connection.AbstractConnectionFactoryconnections, connectionsMonitor, DEFAULT_REPLY_TIMEOUT, lifecycleMonitorFields inherited from class org.springframework.integration.context.IntegrationObjectSupportEXPRESSION_PARSER, logger
- 
Constructor SummaryConstructorsConstructorDescriptionCachingClientConnectionFactory(AbstractClientConnectionFactory target, int poolSize) Construct a caching connection factory that delegates to the provided factory, with the provided pool size.
- 
Method SummaryModifier and TypeMethodDescriptionbooleancloseConnection(String connectionId) Close a connection with the specified connection id.voiddestroy()voidSet whether to automatically (default) or manually add aTcpListenerto the connections created by this factory.booleanvoidforceClose(TcpConnection connection) Force close the connection and null the field if it's a shared connection.intintSubclasses may implement this method to provide component type information.Deserializer<?> getHost()intintintgetPort()Serializer<?> intintintintintinthashCode()booleanbooleanbooleanbooleanbooleanvoidregisterListener(TcpListener listener) Delegate TCP Client Connection factories that are used to receive data need a Listener to send the messages to.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.voidsetComponentName(String componentName) Sets the name of this component.voidsetConnectionWaitTimeout(int connectionWaitTimeout) voidsetDeserializer(Deserializer<?> deserializer) voidsetInterceptorFactoryChain(TcpConnectionInterceptorFactoryChain interceptorFactoryChain) voidsetLookupHost(boolean lookupHost) If true, DNS reverse lookup is done on the remote ip address.voidsetMapper(TcpMessageMapper mapper) voidsetPoolSize(int poolSize) voidsetSerializer(Serializer<?> serializer) voidsetSingleUse(boolean singleUse) Ignored on this factory; connections are always cached in the pool.voidsetSoKeepAlive(boolean soKeepAlive) voidsetSoLinger(int soLinger) voidsetSoReceiveBufferSize(int soReceiveBufferSize) voidsetSoSendBufferSize(int soSendBufferSize) voidsetSoTcpNoDelay(boolean soTcpNoDelay) voidsetSoTimeout(int soTimeout) voidsetSoTrafficClass(int soTrafficClass) voidsetTaskExecutor(Executor taskExecutor) voidstart()voidstop()Stops the server.Methods inherited from class org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactorybuildNewConnection, getConnection, getConnectionTest, getConnectTimeout, getTheConnection, initializeConnection, obtainNewConnection, obtainSharedConnection, setConnectionTest, setConnectTimeout, setTheConnectionMethods inherited from class org.springframework.integration.ip.tcp.connection.AbstractConnectionFactoryaddConnection, checkActive, delayRead, doAccept, getApplicationEventPublisher, getDelayedReads, getLifecycleMonitor, getListener, getOpenConnectionIds, getReadDelay, getSenders, getSslHandshakeTimeout, getTaskExecutor, getTcpSocketSupport, harvestClosedConnections, isActive, onInit, processNioSelections, setActive, setApplicationEventPublisher, setHost, setLeaveOpen, setNioHarvestInterval, setPort, setReadDelay, setSocketAttributes, setSslHandshakeTimeout, setTcpSocketSupport, toString, unregisterSender, wrapConnectionMethods inherited from class org.springframework.integration.context.IntegrationObjectSupportafterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler
- 
Constructor Details- 
CachingClientConnectionFactoryConstruct 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- 
setConnectionWaitTimeoutpublic void setConnectionWaitTimeout(int connectionWaitTimeout) - Parameters:
- connectionWaitTimeout- the new timeout.
- See Also:
 
- 
setPoolSizepublic void setPoolSize(int poolSize) - Parameters:
- poolSize- the new pool size.
- See Also:
 
- 
getPoolSizepublic int getPoolSize()- Returns:
- the pool size.
- See Also:
 
- 
getIdleCountpublic int getIdleCount()- Returns:
- the idle count.
- See Also:
 
- 
getActiveCountpublic int getActiveCount()- Returns:
- the active count.
- See Also:
 
- 
getAllocatedCountpublic int getAllocatedCount()- Returns:
- the allocated count.
- See Also:
 
- 
obtainConnection- Overrides:
- obtainConnectionin class- AbstractClientConnectionFactory
 
- 
isRunningpublic boolean isRunning()- Specified by:
- isRunningin interface- Lifecycle
- Specified by:
- isRunningin interface- ManageableLifecycle
- Overrides:
- isRunningin class- AbstractConnectionFactory
 
- 
hashCode
- 
setComponentNameDescription copied from class:IntegrationObjectSupportSets the name of this component.- Overrides:
- setComponentNamein class- IntegrationObjectSupport
- Parameters:
- componentName- The component name.
 
- 
getComponentTypeDescription copied from class:IntegrationObjectSupportSubclasses may implement this method to provide component type information.- Specified by:
- getComponentTypein interface- NamedComponent
- Overrides:
- getComponentTypein class- IntegrationObjectSupport
 
- 
equals
- 
getSoTimeoutpublic int getSoTimeout()- Overrides:
- getSoTimeoutin class- AbstractConnectionFactory
- Returns:
- the soTimeout
 
- 
setSoTimeoutpublic void setSoTimeout(int soTimeout) - Overrides:
- setSoTimeoutin class- AbstractConnectionFactory
- Parameters:
- soTimeout- the soTimeout to set
 
- 
getSoReceiveBufferSizepublic int getSoReceiveBufferSize()- Overrides:
- getSoReceiveBufferSizein class- AbstractConnectionFactory
- Returns:
- the soReceiveBufferSize
 
- 
setSoReceiveBufferSizepublic void setSoReceiveBufferSize(int soReceiveBufferSize) - Overrides:
- setSoReceiveBufferSizein class- AbstractConnectionFactory
- Parameters:
- soReceiveBufferSize- the soReceiveBufferSize to set
 
- 
getSoSendBufferSizepublic int getSoSendBufferSize()- Overrides:
- getSoSendBufferSizein class- AbstractConnectionFactory
- Returns:
- the soSendBufferSize
 
- 
setSoSendBufferSizepublic void setSoSendBufferSize(int soSendBufferSize) - Overrides:
- setSoSendBufferSizein class- AbstractConnectionFactory
- Parameters:
- soSendBufferSize- the soSendBufferSize to set
 
- 
isSoTcpNoDelaypublic boolean isSoTcpNoDelay()- Overrides:
- isSoTcpNoDelayin class- AbstractConnectionFactory
- Returns:
- the soTcpNoDelay
 
- 
setSoTcpNoDelaypublic void setSoTcpNoDelay(boolean soTcpNoDelay) - Overrides:
- setSoTcpNoDelayin class- AbstractConnectionFactory
- Parameters:
- soTcpNoDelay- the soTcpNoDelay to set
 
- 
getSoLingerpublic int getSoLinger()- Overrides:
- getSoLingerin class- AbstractConnectionFactory
- Returns:
- the soLinger
 
- 
setSoLingerpublic void setSoLinger(int soLinger) - Overrides:
- setSoLingerin class- AbstractConnectionFactory
- Parameters:
- soLinger- the soLinger to set
 
- 
isSoKeepAlivepublic boolean isSoKeepAlive()- Overrides:
- isSoKeepAlivein class- AbstractConnectionFactory
- Returns:
- the soKeepAlive
 
- 
setSoKeepAlivepublic void setSoKeepAlive(boolean soKeepAlive) - Overrides:
- setSoKeepAlivein class- AbstractConnectionFactory
- Parameters:
- soKeepAlive- the soKeepAlive to set
 
- 
getSoTrafficClasspublic int getSoTrafficClass()- Overrides:
- getSoTrafficClassin class- AbstractConnectionFactory
- Returns:
- the soTrafficClass
 
- 
setSoTrafficClasspublic void setSoTrafficClass(int soTrafficClass) - Overrides:
- setSoTrafficClassin class- AbstractConnectionFactory
- Parameters:
- soTrafficClass- the soTrafficClass to set
 
- 
getHost- Overrides:
- getHostin class- AbstractConnectionFactory
- Returns:
- the host
 
- 
getPortpublic int getPort()- Overrides:
- getPortin class- AbstractConnectionFactory
- Returns:
- the port
 
- 
getSender- Overrides:
- getSenderin class- AbstractConnectionFactory
- Returns:
- the first sender, if present.
 
- 
getSerializer- Overrides:
- getSerializerin class- AbstractConnectionFactory
- Returns:
- the serializer
 
- 
getDeserializer- Overrides:
- getDeserializerin class- AbstractConnectionFactory
- Returns:
- the deserializer
 
- 
getMapper- Overrides:
- getMapperin class- AbstractConnectionFactory
- Returns:
- the mapper
 
- 
registerListenerDelegate 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:
- registerListenerin class- AbstractConnectionFactory
- Parameters:
- listener- the TcpListener.
 
- 
registerSenderDescription 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 class- AbstractConnectionFactory
- Parameters:
- sender- The sender
 
- 
setTaskExecutor- Overrides:
- setTaskExecutorin class- AbstractConnectionFactory
- Parameters:
- taskExecutor- the taskExecutor to set
 
- 
setDeserializer- Overrides:
- setDeserializerin class- AbstractConnectionFactory
- Parameters:
- deserializer- the deserializer to set
 
- 
setSerializer- Overrides:
- setSerializerin class- AbstractConnectionFactory
- Parameters:
- serializer- the serializer to set
 
- 
setMapper- Overrides:
- setMapperin class- AbstractConnectionFactory
- Parameters:
- mapper- the mapper to set; defaults to a- TcpMessageMapper
 
- 
isSingleUsepublic boolean isSingleUse()- Overrides:
- isSingleUsein class- AbstractConnectionFactory
- Returns:
- the singleUse
 
- 
setSingleUsepublic 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:
- setSingleUsein class- AbstractConnectionFactory
- Parameters:
- singleUse- the singleUse.
 
- 
setInterceptorFactoryChainpublic void setInterceptorFactoryChain(TcpConnectionInterceptorFactoryChain interceptorFactoryChain) - Overrides:
- setInterceptorFactoryChainin class- AbstractConnectionFactory
 
- 
setLookupHostpublic void setLookupHost(boolean lookupHost) Description copied from class:AbstractConnectionFactoryIf 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:
- setLookupHostin class- AbstractConnectionFactory
- Parameters:
- lookupHost- the lookupHost to set
 
- 
isLookupHostpublic boolean isLookupHost()- Overrides:
- isLookupHostin class- AbstractConnectionFactory
- Returns:
- the lookupHost
 
- 
forceCloseDescription copied from class:AbstractClientConnectionFactoryForce close the connection and null the field if it's a shared connection.- Overrides:
- forceClosein class- AbstractClientConnectionFactory
- Parameters:
- connection- The connection.
 
- 
enableManualListenerRegistrationpublic 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 class- AbstractClientConnectionFactory
 
- 
closeConnectionDescription copied from class:AbstractConnectionFactoryClose a connection with the specified connection id.- Overrides:
- closeConnectionin class- AbstractConnectionFactory
- Parameters:
- connectionId- the connection id.
- Returns:
- true if the connection was closed.
 
- 
startpublic void start()- Specified by:
- startin interface- Lifecycle
- Specified by:
- startin interface- ManageableLifecycle
- Overrides:
- startin class- AbstractConnectionFactory
 
- 
stoppublic void stop()Description copied from class:AbstractConnectionFactoryStops the server.- Specified by:
- stopin interface- Lifecycle
- Specified by:
- stopin interface- ManageableLifecycle
- Overrides:
- stopin class- AbstractConnectionFactory
 
- 
destroypublic void destroy()- Specified by:
- destroyin interface- DisposableBean
 
 
-