Spring Integration

org.springframework.integration.ip.tcp.connection
Class FailoverClientConnectionFactory

java.lang.Object
  extended by org.springframework.integration.context.IntegrationObjectSupport
      extended by org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory
          extended by org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory
              extended by org.springframework.integration.ip.tcp.connection.FailoverClientConnectionFactory
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle, NamedComponent, ConnectionFactory

public class FailoverClientConnectionFactory
extends AbstractClientConnectionFactory

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

Field Summary
 
Fields inherited from class org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory
DEFAULT_REPLY_TIMEOUT, lifecycleMonitor
 
Constructor Summary
FailoverClientConnectionFactory(java.util.List<AbstractClientConnectionFactory> factories)
           
 
Method Summary
 void close()
          Closes the server.
 boolean isRunning()
          Returns true if all factories are running
protected  TcpConnection 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 start()
           
 void stop()
          Stops the server.
 
Methods inherited from class org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory
getConnection, getTheConnection, initializeConnection, setTheConnection
 
Methods inherited from class org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory
addConnection, checkActive, doAccept, getDeserializer, getHost, getListener, getMapper, getPhase, getPoolSize, getPort, getSender, getSerializer, getSoLinger, getSoReceiveBufferSize, getSoSendBufferSize, getSoTimeout, getSoTrafficClass, getTaskExecutor, getTcpSocketSupport, harvestClosedConnections, isActive, isAutoStartup, isLookupHost, isSingleUse, isSoKeepAlive, isSoTcpNoDelay, processNioSelections, setActive, setDeserializer, setInterceptorFactoryChain, setLookupHost, setMapper, setNioHarvestInterval, setPoolSize, setSerializer, setSingleUse, setSocketAttributes, setSoKeepAlive, setSoLinger, setSoReceiveBufferSize, setSoSendBufferSize, setSoTcpNoDelay, setSoTimeout, setSoTrafficClass, setTaskExecutor, setTcpSocketSupport, stop, wrapConnection
 
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, getBeanFactory, getComponentName, getComponentType, getConversionService, getTaskScheduler, setBeanFactory, setBeanName, setComponentName, setConversionService, setTaskScheduler, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FailoverClientConnectionFactory

public FailoverClientConnectionFactory(java.util.List<AbstractClientConnectionFactory> factories)
Method Detail

onInit

protected void onInit()
               throws java.lang.Exception
Description copied from class: IntegrationObjectSupport
Subclasses may implement this for initialization logic.

Overrides:
onInit in class IntegrationObjectSupport
Throws:
java.lang.Exception

registerListener

public void registerListener(TcpListener listener)
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 class AbstractConnectionFactory
Parameters:
listener - the TcpListener.

registerSender

public void registerSender(TcpSender sender)
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 class AbstractConnectionFactory
Parameters:
sender - The sender

obtainConnection

protected TcpConnection obtainConnection()
                                  throws java.lang.Exception
Specified by:
obtainConnection in class AbstractClientConnectionFactory
Throws:
java.lang.Exception

close

public void close()
Description copied from class: AbstractConnectionFactory
Closes the server.

Specified by:
close in class AbstractConnectionFactory

start

public void start()
Specified by:
start in interface org.springframework.context.Lifecycle
Overrides:
start in class AbstractConnectionFactory

stop

public void stop()
Description copied from class: AbstractConnectionFactory
Stops the server.

Specified by:
stop in interface org.springframework.context.Lifecycle
Overrides:
stop in class AbstractConnectionFactory

isRunning

public boolean isRunning()
Returns true if all factories are running

Specified by:
isRunning in interface org.springframework.context.Lifecycle
Overrides:
isRunning in class AbstractConnectionFactory

Spring Integration