Class TcpInboundGateway

All Implemented Interfaces:
Aware, BeanFactoryAware, BeanNameAware, DisposableBean, InitializingBean, ApplicationContextAware, Lifecycle, Phased, SmartLifecycle, ComponentSourceAware, ExpressionCapable, OrderlyShutdownCapable, IntegrationPattern, ClientModeCapable, TcpListener, TcpSender, NamedComponent, IntegrationInboundManagement, IntegrationManagement, ManageableLifecycle, ManageableSmartLifecycle, TrackableComponent

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, Artem Bilan
  • Field Details

    • DEFAULT_RETRY_INTERVAL

      public static final long DEFAULT_RETRY_INTERVAL
      A default retry interval in milliseconds - 60000L.
      See Also:
  • Constructor Details

    • TcpInboundGateway

      public TcpInboundGateway()
  • Method Details

    • 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)
      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 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()
      Description copied from class: IntegrationObjectSupport
      Subclasses may implement this for initialization logic.
      Overrides:
      onInit in class MessagingGatewaySupport
    • 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
    • getRetryInterval

      public long getRetryInterval()
      Returns:
      the retryInterval
    • setRetryInterval

      public void setRetryInterval(long retryInterval)
      Configure a retry interval. Defaults to DEFAULT_RETRY_INTERVAL.
      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.