Spring Integration

org.springframework.integration.ip.tcp
Class TcpInboundGateway

java.lang.Object
  extended by org.springframework.integration.context.IntegrationObjectSupport
      extended by org.springframework.integration.endpoint.AbstractEndpoint
          extended by org.springframework.integration.gateway.MessagingGatewaySupport
              extended by org.springframework.integration.ip.tcp.TcpInboundGateway
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, OrderlyShutdownCapable, TrackableComponent, ClientModeCapable, TcpListener, TcpSender

public class TcpInboundGateway
extends MessagingGatewaySupport
implements TcpListener, TcpSender, ClientModeCapable, OrderlyShutdownCapable

Inbound Gateway using a server connection factory - threading is controlled by the factory. For java.net connections, each socket can process only one message at a time. For java.nio connections, messages may be multiplexed but the client will need to provide correlation logic. If the client is a TcpOutboundGateway multiplexing is not used, but multiple concurrent connections can be used if the connection factory uses single-use connections. For true asynchronous bi-directional communication, a pair of inbound / outbound channel adapters should be used.

Since:
2.0
Author:
Gary Russell

Field Summary
 
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
logger
 
Constructor Summary
TcpInboundGateway()
           
 
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.
 int afterShutdown()
          Called after normal shutdown of schedulers, executors etc, and after the shutdown delay has elapsed, but before any forced shutdown of any remaining active scheduler/executor threads.Can optionally return the number of active messages still in process.
 int beforeShutdown()
          Called before shutdown begins.
protected  void doStart()
          Subclasses must implement this method with the start behavior.
protected  void doStop()
          Subclasses must implement this method with the stop behavior.
 java.lang.String getComponentType()
          Subclasses may implement this method to provide component type information.
 long getRetryInterval()
           
 boolean isClientMode()
           
 boolean isClientModeConnected()
           
 boolean isListening()
           
protected  void onInit()
          Subclasses may implement this for initialization logic.
 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 retryConnection()
          Immediately attempt to establish the connection.
 void setClientMode(boolean isClientMode)
           
 void setConnectionFactory(AbstractConnectionFactory connectionFactory)
          Must be AbstractClientConnectionFactory or AbstractServerConnectionFactory.
 void setRetryInterval(long retryInterval)
           
 void setScheduler(org.springframework.scheduling.TaskScheduler scheduler)
          Deprecated. Use AbstractEndpoint.setTaskScheduler(TaskScheduler)
 
Methods inherited from class org.springframework.integration.gateway.MessagingGatewaySupport
receive, send, sendAndReceive, sendAndReceiveMessage, setErrorChannel, setReplyChannel, setReplyMapper, setReplyTimeout, setRequestChannel, setRequestMapper, setRequestTimeout, setShouldTrack
 
Methods inherited from class org.springframework.integration.endpoint.AbstractEndpoint
getPhase, isAutoStartup, isRunning, setAutoStartup, setPhase, setTaskScheduler, start, stop, stop
 
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, getBeanFactory, getComponentName, getConversionService, getTaskScheduler, setBeanFactory, setBeanName, setComponentName, setConversionService, 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

TcpInboundGateway

public TcpInboundGateway()
Method Detail

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

isListening

public boolean isListening()
Returns:
true if the associated connection factory is listening.

setConnectionFactory

public void setConnectionFactory(AbstractConnectionFactory connectionFactory)
Must be AbstractClientConnectionFactory or AbstractServerConnectionFactory.

Parameters:
connectionFactory - the Connection Factory

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.

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 MessagingGatewaySupport

onInit

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

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

doStart

protected void doStart()
Description copied from class: AbstractEndpoint
Subclasses must implement this method with the start behavior. This method will be invoked while holding the AbstractEndpoint.lifecycleLock.

Overrides:
doStart in class MessagingGatewaySupport

doStop

protected void doStop()
Description copied from class: AbstractEndpoint
Subclasses must implement this method with the stop behavior. This method will be invoked while holding the AbstractEndpoint.lifecycleLock.

Overrides:
doStop in class MessagingGatewaySupport

isClientMode

public boolean isClientMode()
Specified by:
isClientMode in interface ClientModeCapable
Returns:
the isClientMode

setClientMode

public void setClientMode(boolean isClientMode)
Parameters:
isClientMode - the isClientMode to set

setScheduler

@Deprecated
public void setScheduler(org.springframework.scheduling.TaskScheduler scheduler)
Deprecated. Use AbstractEndpoint.setTaskScheduler(TaskScheduler)

Parameters:
scheduler - the scheduler to set

getRetryInterval

public long getRetryInterval()
Returns:
the retryInterval

setRetryInterval

public void setRetryInterval(long retryInterval)
Parameters:
retryInterval - the retryInterval to set

isClientModeConnected

public boolean isClientModeConnected()
Specified by:
isClientModeConnected in interface ClientModeCapable
Returns:
true if the endpoint is running in client mode.

retryConnection

public void retryConnection()
Description copied from interface: ClientModeCapable
Immediately attempt to establish the connection.

Specified by:
retryConnection in interface ClientModeCapable

beforeShutdown

public int beforeShutdown()
Description copied from interface: OrderlyShutdownCapable
Called before shutdown begins. Implementations should stop accepting new messages. Can optionally return the number of active messages in process.

Specified by:
beforeShutdown in interface OrderlyShutdownCapable
Returns:
The number of active messages if available.

afterShutdown

public int afterShutdown()
Description copied from interface: OrderlyShutdownCapable
Called after normal shutdown of schedulers, executors etc, and after the shutdown delay has elapsed, but before any forced shutdown of any remaining active scheduler/executor threads.Can optionally return the number of active messages still in process.

Specified by:
afterShutdown in interface OrderlyShutdownCapable
Returns:
The number of active messages if available.

Spring Integration