public class FailoverClientConnectionFactory extends AbstractClientConnectionFactory
TcpConnections
that can iterate over a connection from each factory until the write
succeeds or the list is exhausted.DEFAULT_REPLY_TIMEOUT, lifecycleMonitorEXPRESSION_PARSER, logger| Constructor and Description |
|---|
FailoverClientConnectionFactory(List<AbstractClientConnectionFactory> factories)
Construct an instance with the provided delegate factories.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
isRunning()
Returns true if all factories are running
|
protected TcpConnectionSupport |
obtainConnection() |
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 connection
singleUse is false,
set this to true to close the old shared connection after a refresh. |
void |
setRefreshSharedInterval(long refreshSharedInterval)
When using a shared connection
singleUse 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.
|
buildNewConnection, enableManualListenerRegistration, forceClose, getConnection, getTheConnection, initializeConnection, obtainNewConnection, obtainSharedConnection, setTheConnectionaddConnection, checkActive, closeConnection, delayRead, doAccept, getApplicationEventPublisher, getDelayedReads, getDeserializer, getHost, getListener, getMapper, getOpenConnectionIds, getPhase, getPort, getReadDelay, getSender, getSerializer, getSoLinger, getSoReceiveBufferSize, getSoSendBufferSize, getSoTimeout, getSoTrafficClass, getSslHandshakeTimeout, getTaskExecutor, getTcpSocketSupport, harvestClosedConnections, isActive, isAutoStartup, isLookupHost, isSingleUse, isSoKeepAlive, isSoTcpNoDelay, processNioSelections, setActive, setApplicationEventPublisher, setDeserializer, setInterceptorFactoryChain, setLookupHost, setMapper, setNioHarvestInterval, setReadDelay, setSerializer, setSingleUse, setSocketAttributes, setSoKeepAlive, setSoLinger, setSoReceiveBufferSize, setSoSendBufferSize, setSoTcpNoDelay, setSoTimeout, setSoTrafficClass, setSslHandshakeTimeout, setTaskExecutor, setTcpSocketSupport, stop, toString, wrapConnectionafterPropertiesSet, extractTypeIfPossible, getApplicationContext, getApplicationContextId, getBeanFactory, getChannelResolver, getComponentName, getComponentType, getConversionService, getExpression, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskSchedulerpublic FailoverClientConnectionFactory(List<AbstractClientConnectionFactory> factories)
factories - the delegates.public void setRefreshSharedInterval(long refreshSharedInterval)
singleUse is false,
specify how long to wait before trying to fail back to start from the beginning of
the factory list. Default is 0 for backwards compatibility to always try to get a
connection to the primary server. If you don't want to fail back until the current
connection is closed, set this to Long.MAX_VALUE.
Cannot be changed when using CachingClientConnectionFactory delegates.refreshSharedInterval - the interval in milliseconds.AbstractConnectionFactory.setSingleUse(boolean),
setCloseOnRefresh(boolean)public void setCloseOnRefresh(boolean closeOnRefresh)
singleUse 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 using CachingClientConnectionFactory delegates.closeOnRefresh - true to close.AbstractConnectionFactory.setSingleUse(boolean),
setRefreshSharedInterval(long)protected void onInit()
throws Exception
IntegrationObjectSupportonInit in class AbstractConnectionFactoryException - Any exception.public void registerListener(TcpListener listener)
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.
registerListener in class AbstractConnectionFactorylistener - the TcpListener.public void registerSender(TcpSender sender)
AbstractConnectionFactoryregisterSender in class AbstractConnectionFactorysender - The senderprotected TcpConnectionSupport obtainConnection() throws Exception
obtainConnection in class AbstractClientConnectionFactoryExceptionpublic void start()
start in interface Lifecyclestart in class AbstractConnectionFactorypublic void stop()
AbstractConnectionFactorystop in interface Lifecyclestop in class AbstractConnectionFactorypublic boolean isRunning()
isRunning in interface LifecycleisRunning in class AbstractConnectionFactory