Class AbstractClientConnectionFactory
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory
org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory
- 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
- Direct Known Subclasses:
CachingClientConnectionFactory,FailoverClientConnectionFactory,TcpNetClientConnectionFactory,TcpNioClientConnectionFactory,ThreadAffinityClientConnectionFactory
public abstract class AbstractClientConnectionFactory extends AbstractConnectionFactory
Abstract class for client connection factories; client connection factories
establish outgoing connections.
- Since:
- 2.0
-
Field Summary
Fields inherited from class org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory
DEFAULT_REPLY_TIMEOUT, lifecycleMonitor -
Constructor Summary
Constructors Constructor Description AbstractClientConnectionFactory(java.lang.String host, int port)Constructs a factory that will established connections to the host and port. -
Method Summary
Modifier and Type Method Description protected TcpConnectionSupportbuildNewConnection()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.TcpConnectionSupportgetConnection()Obtains 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.protected java.util.function.Predicate<TcpConnectionSupport>getConnectionTest()Get aPredicatethat will be invoked to test a new connection; return true to accept the connection, false the reject.protected java.time.DurationgetConnectTimeout()protected TcpConnectionSupportgetTheConnection()protected voidinitializeConnection(TcpConnectionSupport connection, java.net.Socket socket)Transfers attributes such as (de)serializers, singleUse etc to a new connection.protected TcpConnectionSupportobtainConnection()protected TcpConnectionSupportobtainNewConnection()protected TcpConnectionSupportobtainSharedConnection()voidsetConnectionTest(java.util.function.Predicate<TcpConnectionSupport> connectionTest)Set aPredicatethat will be invoked to test a new connection; return true to accept the connection, false the reject.voidsetConnectTimeout(int connectTimeout)Set the connection timeout in seconds.protected voidsetTheConnection(TcpConnectionSupport theConnection)Methods inherited from class org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory
addConnection, checkActive, closeConnection, delayRead, doAccept, getApplicationEventPublisher, getDelayedReads, getDeserializer, getHost, getLifecycleMonitor, getListener, getMapper, getOpenConnectionIds, getPort, getReadDelay, getSender, getSenders, getSerializer, getSoLinger, getSoReceiveBufferSize, getSoSendBufferSize, getSoTimeout, getSoTrafficClass, getSslHandshakeTimeout, getTaskExecutor, getTcpSocketSupport, harvestClosedConnections, isActive, isLookupHost, isRunning, isSingleUse, isSoKeepAlive, isSoTcpNoDelay, onInit, processNioSelections, registerListener, registerSender, setActive, setApplicationEventPublisher, setDeserializer, setHost, setInterceptorFactoryChain, setLeaveOpen, setLookupHost, setMapper, setNioHarvestInterval, setPort, setReadDelay, setSerializer, setSingleUse, setSocketAttributes, setSoKeepAlive, setSoLinger, setSoReceiveBufferSize, setSoSendBufferSize, setSoTcpNoDelay, setSoTimeout, setSoTrafficClass, setSslHandshakeTimeout, setTaskExecutor, setTcpSocketSupport, start, stop, toString, unregisterSender, wrapConnectionMethods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getComponentType, getConversionService, getExpression, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler
-
Constructor Details
-
AbstractClientConnectionFactory
public AbstractClientConnectionFactory(java.lang.String host, int port)Constructs a factory that will established connections to the host and port.- Parameters:
host- The host.port- The port.
-
-
Method Details
-
setConnectTimeout
public void setConnectTimeout(int connectTimeout)Set the connection timeout in seconds. Defaults to 60.- Parameters:
connectTimeout- the timeout.- Since:
- 5.2
-
getConnectTimeout
protected java.time.Duration getConnectTimeout() -
enableManualListenerRegistration
public void enableManualListenerRegistration()Set 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.- Since:
- 1.4.5
-
getConnectionTest
Get aPredicatethat will be invoked to test a new connection; return true to accept the connection, false the reject.- Returns:
- the predicate.
- Since:
- 5.3
-
setConnectionTest
public void setConnectionTest(@Nullable java.util.function.Predicate<TcpConnectionSupport> connectionTest)Set aPredicatethat will be invoked to test a new connection; return true to accept the connection, false the reject.- Parameters:
connectionTest- the predicate.- Since:
- 5.3
-
getConnection
Obtains 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.- Throws:
java.lang.InterruptedException- if interrupted.
-
obtainConnection
- Throws:
java.lang.InterruptedException
-
obtainSharedConnection
@Nullable protected final TcpConnectionSupport obtainSharedConnection() throws java.lang.InterruptedException- Throws:
java.lang.InterruptedException
-
obtainNewConnection
- Throws:
java.lang.InterruptedException
-
buildNewConnection
-
initializeConnection
Transfers attributes such as (de)serializers, singleUse etc to a new connection. When the connection factory has a reference to a TCPListener (to read responses), or for single use connections, the connection is executed. Single use connections need to read from the connection in order to close it after the socket timeout.- Parameters:
connection- The new connection.socket- The new socket.
-
setTheConnection
- Parameters:
theConnection- the theConnection to set
-
getTheConnection
- Returns:
- the theConnection
-
forceClose
Force close the connection and null the field if it's a shared connection.- Parameters:
connection- The connection.
-