Class FailoverClientConnectionFactory
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.FailoverClientConnectionFactory
- All Implemented Interfaces:
Aware
,BeanFactoryAware
,BeanNameAware
,InitializingBean
,ApplicationContextAware
,ApplicationEventPublisherAware
,Lifecycle
,ComponentSourceAware
,ExpressionCapable
,ConnectionFactory
,NamedComponent
,ManageableLifecycle
Given a list of connection factories, serves up
TcpConnection
s
that can iterate over a connection from each factory until the write
succeeds or the list is exhausted.- Since:
- 2.2
- Author:
- Gary Russell, Christian Tzolov
-
Field Summary
Fields inherited from class org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory
connections, connectionsMonitor, DEFAULT_REPLY_TIMEOUT, lifecycleMonitor
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, logger
-
Constructor Summary
ConstructorDescriptionConstruct an instance with the provided delegate factories. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Return true if all factories are running.protected TcpConnectionSupport
protected void
onInit()
Subclasses may implement this for initialization logic.void
registerListener
(TcpListener listener) Delegate TCP Client Connection factories that are used to receive data need a Listener to send the messages to.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
setCloseOnRefresh
(boolean closeOnRefresh) When using a shared connectionsingleUse
is false, set this to true to close the old shared connection after a refresh.void
setRefreshSharedInterval
(long refreshSharedInterval) When using a shared connectionsingleUse
is false, specify how long to wait before trying to fail back to start from the beginning of the factory list.void
start()
void
stop()
Stops the server.Methods inherited from class org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory
buildNewConnection, enableManualListenerRegistration, forceClose, getConnection, getConnectionTest, getConnectTimeout, getTheConnection, initializeConnection, obtainNewConnection, obtainSharedConnection, setConnectionTest, setConnectTimeout, setTheConnection
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, isSingleUse, isSoKeepAlive, isSoTcpNoDelay, processNioSelections, setActive, setApplicationEventPublisher, setDeserializer, setHost, setInterceptorFactoryChain, setLeaveOpen, setLookupHost, setMapper, setNioHarvestInterval, setPort, setReadDelay, setSerializer, setSingleUse, setSocketAttributes, setSoKeepAlive, setSoLinger, setSoReceiveBufferSize, setSoSendBufferSize, setSoTcpNoDelay, setSoTimeout, setSoTrafficClass, setSslHandshakeTimeout, setTaskExecutor, setTcpSocketSupport, toString, unregisterSender, wrapConnection
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentDescription, getComponentName, getComponentSource, getComponentType, getConversionService, getExpression, getIntegrationProperties, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentDescription, setComponentName, setComponentSource, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler
-
Constructor Details
-
FailoverClientConnectionFactory
Construct an instance with the provided delegate factories.- Parameters:
factories
- the delegates.
-
-
Method Details
-
setCloseOnRefresh
public void setCloseOnRefresh(boolean closeOnRefresh) When using a shared connectionsingleUse
is false, set this to true to close the old shared connection after a refresh. If this is false, the connection will remain open, but unused until its connection factory is again used to get a connection. Default is false for backwards compatibility. Cannot be changed when usingCachingClientConnectionFactory
delegates.- Parameters:
closeOnRefresh
- true to close.- Since:
- 4.3.22
- See Also:
-
onInit
protected void onInit()Description copied from class:IntegrationObjectSupport
Subclasses may implement this for initialization logic.- Overrides:
onInit
in classAbstractConnectionFactory
-
registerListener
Delegate 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 FailoverTcpConnections, 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:
registerListener
in classAbstractConnectionFactory
- Parameters:
listener
- the TcpListener.
-
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
-
obtainConnection
- Overrides:
obtainConnection
in classAbstractClientConnectionFactory
- Throws:
InterruptedException
-
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()Return true if all factories are running.- Specified by:
isRunning
in interfaceLifecycle
- Specified by:
isRunning
in interfaceManageableLifecycle
- Overrides:
isRunning
in classAbstractConnectionFactory