public class FailoverClientConnectionFactory extends AbstractClientConnectionFactory
TcpConnection
s
that can iterate over a connection from each factory until the write
succeeds or the list is exhausted.DEFAULT_REPLY_TIMEOUT, lifecycleMonitor
EXPRESSION_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, getConnectionTest, getConnectTimeout, getTheConnection, initializeConnection, obtainNewConnection, obtainSharedConnection, setConnectionTest, setConnectTimeout, setTheConnection
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
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
public 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 Long.MAX_VALUE
- meaning only fail back when
the current connection fails. 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()
IntegrationObjectSupport
onInit
in class AbstractConnectionFactory
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 AbstractConnectionFactory
listener
- the TcpListener.public void registerSender(TcpSender sender)
AbstractConnectionFactory
registerSender
in class AbstractConnectionFactory
sender
- The senderprotected TcpConnectionSupport obtainConnection() throws InterruptedException
obtainConnection
in class AbstractClientConnectionFactory
InterruptedException
public void start()
start
in interface Lifecycle
start
in interface ManageableLifecycle
start
in class AbstractConnectionFactory
public void stop()
AbstractConnectionFactory
stop
in interface Lifecycle
stop
in interface ManageableLifecycle
stop
in class AbstractConnectionFactory
public boolean isRunning()
isRunning
in interface Lifecycle
isRunning
in interface ManageableLifecycle
isRunning
in class AbstractConnectionFactory