Spring Integration

org.springframework.integration.ip.tcp
Class TcpOutboundGateway

java.lang.Object
  extended by org.springframework.integration.context.IntegrationObjectSupport
      extended by org.springframework.integration.handler.AbstractMessageHandler
          extended by org.springframework.integration.handler.AbstractReplyProducingMessageHandler
              extended by org.springframework.integration.ip.tcp.TcpOutboundGateway
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanClassLoaderAware, 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, org.springframework.core.Ordered, NamedComponent, Orderable, MessageHandler, MessageProducer, TrackableComponent, TcpListener, TcpSender

public class TcpOutboundGateway
extends AbstractReplyProducingMessageHandler
implements TcpSender, TcpListener, org.springframework.context.SmartLifecycle

TCP outbound gateway that uses a client connection factory. If the factory is configured for single-use connections, each request is sent on a new connection; if the factory does not use single use connections, each request is blocked until the previous response is received (or times out). Asynchronous requests/responses over the same connection are not supported - use a pair of outbound/inbound adapters for that use case.

SmartLifecycle methods delegate to the underlying AbstractConnectionFactory

Since:
2.0
Author:
Gary Russell

Nested Class Summary
 
Nested classes/interfaces inherited from class org.springframework.integration.handler.AbstractReplyProducingMessageHandler
AbstractReplyProducingMessageHandler.RequestHandler
 
Field Summary
 
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
logger
 
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
 
Constructor Summary
TcpOutboundGateway()
           
 
Method Summary
 void addNewConnection(TcpConnection connection)
          When we are using sockets owned by a TcpListener, this method is called each time a new connection is made.
 java.lang.String getComponentType()
          Subclasses may implement this method to provide component type information.
protected  AbstractConnectionFactory getConnectionFactory()
           
 int getPhase()
           
protected  java.lang.Object handleRequestMessage(Message<?> requestMessage)
          Subclasses must implement this method to handle the request Message.
 boolean isAutoStartup()
           
 boolean isRunning()
           
 boolean onMessage(Message<?> message)
          Called by a TCPConnection when a new message arrives.
 void removeDeadConnection(TcpConnection connection)
          When we are using sockets owned by a TcpListener, this method is called each time a connection is closed.
 void setAutoStartup(boolean autoStartup)
           
 void setConnectionFactory(AbstractConnectionFactory connectionFactory)
           
 void setPhase(int phase)
           
 void setRemoteTimeout(long remoteTimeout)
           
 void setReplyChannel(MessageChannel replyChannel)
          Specify the Spring Integration reply channel.
 void setRequestTimeout(long requestTimeout)
           
 void setSendTimeout(long sendTimeout)
          Set the timeout for sending reply Messages.
 void start()
           
 void stop()
           
 void stop(java.lang.Runnable callback)
           
 
Methods inherited from class org.springframework.integration.handler.AbstractReplyProducingMessageHandler
getMessagingTemplate, handleMessageInternal, onInit, setAdviceChain, setBeanClassLoader, setChannelResolver, setOutputChannel, setRequiresReply, shouldCopyRequestHeaders
 
Methods inherited from class org.springframework.integration.handler.AbstractMessageHandler
getOrder, handleMessage, setOrder, setShouldTrack
 
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, getBeanFactory, getComponentName, 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
 
Methods inherited from interface org.springframework.integration.context.NamedComponent
getComponentName
 

Constructor Detail

TcpOutboundGateway

public TcpOutboundGateway()
Method Detail

setRequestTimeout

public void setRequestTimeout(long requestTimeout)
Parameters:
requestTimeout - the requestTimeout to set

setRemoteTimeout

public void setRemoteTimeout(long remoteTimeout)
Parameters:
remoteTimeout - the remoteTimeout to set

setSendTimeout

public void setSendTimeout(long sendTimeout)
Description copied from class: AbstractReplyProducingMessageHandler
Set the timeout for sending reply Messages.

Overrides:
setSendTimeout in class AbstractReplyProducingMessageHandler

handleRequestMessage

protected java.lang.Object handleRequestMessage(Message<?> requestMessage)
Description copied from class: AbstractReplyProducingMessageHandler
Subclasses must implement this method to handle the request Message. The return value may be a Message, a MessageBuilder, or any plain Object. The base class will handle the final creation of a reply Message from any of those starting points. If the return value is null, the Message flow will end here.

Specified by:
handleRequestMessage in class AbstractReplyProducingMessageHandler

onMessage

public boolean onMessage(Message<?> message)
Description copied from interface: TcpListener
Called by a TCPConnection when a new message arrives.

Specified by:
onMessage in interface TcpListener
Parameters:
message - The message.
Returns:
true if the message was intercepted

setConnectionFactory

public void setConnectionFactory(AbstractConnectionFactory connectionFactory)

addNewConnection

public void addNewConnection(TcpConnection connection)
Description copied from interface: TcpSender
When we are using sockets owned by a TcpListener, this method is called each time a new connection is made.

Specified by:
addNewConnection in interface TcpSender
Parameters:
connection - The connection.

removeDeadConnection

public void removeDeadConnection(TcpConnection connection)
Description copied from interface: TcpSender
When we are using sockets owned by a TcpListener, this method is called each time a connection is closed.

Specified by:
removeDeadConnection in interface TcpSender
Parameters:
connection - The connection.

setReplyChannel

public void setReplyChannel(MessageChannel replyChannel)
Specify the Spring Integration reply channel. If this property is not set the gateway will check for a 'replyChannel' header on the request.


getComponentType

public java.lang.String getComponentType()
Description copied from class: IntegrationObjectSupport
Subclasses may implement this method to provide component type information.

Specified by:
getComponentType in interface NamedComponent
Overrides:
getComponentType in class AbstractMessageHandler

start

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

stop

public void stop()
Specified by:
stop in interface org.springframework.context.Lifecycle

isRunning

public boolean isRunning()
Specified by:
isRunning in interface org.springframework.context.Lifecycle

getPhase

public int getPhase()
Specified by:
getPhase in interface org.springframework.context.Phased

isAutoStartup

public boolean isAutoStartup()
Specified by:
isAutoStartup in interface org.springframework.context.SmartLifecycle

stop

public void stop(java.lang.Runnable callback)
Specified by:
stop in interface org.springframework.context.SmartLifecycle

setAutoStartup

public void setAutoStartup(boolean autoStartup)

setPhase

public void setPhase(int phase)

getConnectionFactory

protected AbstractConnectionFactory getConnectionFactory()
Returns:
the connectionFactory

Spring Integration