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
TcpConnections
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, lifecycleMonitorFields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, logger -
Constructor Summary
ConstructorsConstructorDescriptionConstruct an instance with the provided delegate factories. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturn true if all factories are running.protected TcpConnectionSupportprotected voidonInit()Subclasses may implement this for initialization logic.voidregisterListener(TcpListener listener) Delegate TCP Client Connection factories that are used to receive data need a Listener to send the messages to.voidregisterSender(TcpSender sender) Registers a TcpSender; for server sockets, used to provide connection information so a sender can be used to reply to incoming messages.voidsetCloseOnRefresh(boolean closeOnRefresh) When using a shared connectionsingleUseis false, set this to true to close the old shared connection after a refresh.voidsetRefreshSharedInterval(long refreshSharedInterval) When using a shared connectionsingleUseis false, specify how long to wait before trying to fail back to start from the beginning of the factory list.voidstart()voidstop()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, setTheConnectionMethods 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, wrapConnectionMethods 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 connectionsingleUseis 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 usingCachingClientConnectionFactorydelegates.- Parameters:
closeOnRefresh- true to close.- Since:
- 4.3.22
- See Also:
-
onInit
protected void onInit()Description copied from class:IntegrationObjectSupportSubclasses may implement this for initialization logic.- Overrides:
onInitin 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:
registerListenerin classAbstractConnectionFactory- Parameters:
listener- the TcpListener.
-
registerSender
Description copied from class:AbstractConnectionFactoryRegisters a TcpSender; for server sockets, used to provide connection information so a sender can be used to reply to incoming messages.- Overrides:
registerSenderin classAbstractConnectionFactory- Parameters:
sender- The sender
-
obtainConnection
- Overrides:
obtainConnectionin classAbstractClientConnectionFactory- Throws:
InterruptedException
-
start
public void start()- Specified by:
startin interfaceLifecycle- Specified by:
startin interfaceManageableLifecycle- Overrides:
startin classAbstractConnectionFactory
-
stop
public void stop()Description copied from class:AbstractConnectionFactoryStops the server.- Specified by:
stopin interfaceLifecycle- Specified by:
stopin interfaceManageableLifecycle- Overrides:
stopin classAbstractConnectionFactory
-
isRunning
public boolean isRunning()Return true if all factories are running.- Specified by:
isRunningin interfaceLifecycle- Specified by:
isRunningin interfaceManageableLifecycle- Overrides:
isRunningin classAbstractConnectionFactory