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:
Aware
,BeanFactoryAware
,BeanNameAware
,InitializingBean
,ApplicationContextAware
,ApplicationEventPublisherAware
,Lifecycle
,ExpressionCapable
,ConnectionFactory
,NamedComponent
,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
- Author:
- Gary Russell, Artem Bilan
-
Field Summary
Fields inherited from class org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory
DEFAULT_REPLY_TIMEOUT, lifecycleMonitor
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, logger
-
Constructor Summary
Constructors Constructor Description AbstractClientConnectionFactory(String host, int port)
Construct a factory that will established connections to the host and port. -
Method Summary
Modifier and Type Method Description protected TcpConnectionSupport
buildNewConnection()
void
enableManualListenerRegistration()
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.TcpConnectionSupport
getConnection()
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.protected Predicate<TcpConnectionSupport>
getConnectionTest()
Get aPredicate
that will be invoked to test a new connection; return true to accept the connection, false the reject.protected Duration
getConnectTimeout()
protected TcpConnectionSupport
getTheConnection()
protected void
initializeConnection(TcpConnectionSupport connection, Socket socket)
Transfer attributes such as (de)serializers, singleUse etc to a new connection.protected TcpConnectionSupport
obtainConnection()
protected TcpConnectionSupport
obtainNewConnection()
protected TcpConnectionSupport
obtainSharedConnection()
void
setConnectionTest(Predicate<TcpConnectionSupport> connectionTest)
Set aPredicate
that will be invoked to test a new connection; return true to accept the connection, false the reject.void
setConnectTimeout(int connectTimeout)
Set the connection timeout in seconds.protected void
setTheConnection(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, wrapConnection
Methods 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
Construct 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
-
enableManualListenerRegistration
public void enableManualListenerRegistration()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.- Since:
- 1.4.5
-
getConnectionTest
Get aPredicate
that will be invoked to test a new connection; return true to accept the connection, false the reject.- Returns:
- the predicate.
- Since:
- 5.3
-
setConnectionTest
Set aPredicate
that 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
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.- Throws:
InterruptedException
- if interrupted.
-
obtainConnection
- Throws:
InterruptedException
-
obtainSharedConnection
- Throws:
InterruptedException
-
obtainNewConnection
- Throws:
InterruptedException
-
buildNewConnection
-
initializeConnection
Transfer 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.
-