Class TcpSendingMessageHandler

java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.handler.MessageHandlerSupport
org.springframework.integration.handler.AbstractMessageHandler
org.springframework.integration.ip.tcp.TcpSendingMessageHandler
All Implemented Interfaces:
org.reactivestreams.Subscriber<org.springframework.messaging.Message<?>>, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware, org.springframework.context.Lifecycle, org.springframework.core.Ordered, org.springframework.integration.context.ExpressionCapable, org.springframework.integration.context.Orderable, org.springframework.integration.IntegrationPattern, ClientModeCapable, TcpSender, org.springframework.integration.support.context.NamedComponent, org.springframework.integration.support.management.IntegrationManagement, org.springframework.integration.support.management.ManageableLifecycle, org.springframework.integration.support.management.TrackableComponent, org.springframework.messaging.MessageHandler, reactor.core.CoreSubscriber<org.springframework.messaging.Message<?>>

public class TcpSendingMessageHandler
extends org.springframework.integration.handler.AbstractMessageHandler
implements TcpSender, org.springframework.integration.support.management.ManageableLifecycle, ClientModeCapable
Tcp outbound channel adapter using a TcpConnection to send data - if the connection factory is a server factory, the TcpListener owns the connections. If it is a client factory, this object owns the connection.
Since:
2.0
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement

    org.springframework.integration.support.management.IntegrationManagement.ManagementOverrides
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static long DEFAULT_RETRY_INTERVAL
    A default retry interval for the ClientModeConnectionManager rescheduling.
    protected java.lang.Object lifecycleMonitor  

    Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport

    EXPRESSION_PARSER, logger

    Fields inherited from interface org.springframework.integration.support.management.IntegrationManagement

    METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAME

    Fields inherited from interface org.springframework.core.Ordered

    HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
  • Constructor Summary

    Constructors 
    Constructor Description
    TcpSendingMessageHandler()  
  • Method Summary

    Modifier and Type Method Description
    void addNewConnection​(TcpConnection connection)
    When we are using sockets owned by a TcpListener, this method is called each time a new connection is made.
    protected TcpConnection doWrite​(org.springframework.messaging.Message<?> message)
    Method that actually does the write.
    protected ConnectionFactory getClientConnectionFactory()  
    java.lang.String getComponentType()  
    protected java.util.Map<java.lang.String,​TcpConnection> getConnections()  
    long getRetryInterval()  
    protected ConnectionFactory getServerConnectionFactory()  
    void handleMessageInternal​(org.springframework.messaging.Message<?> message)
    Writes the message payload to the underlying socket, using the specified message format.
    boolean isClientMode()  
    boolean isClientModeConnected()  
    boolean isRunning()  
    protected TcpConnection obtainConnection​(org.springframework.messaging.Message<?> message)  
    protected void onInit()  
    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)
    Sets the client or server connection factory; for this (an outbound adapter), if the factory is a server connection factory, the sockets are owned by a receiving channel adapter and this adapter is used to send replies.
    void setRetryInterval​(long retryInterval)  
    void start()  
    void stop()  

    Methods inherited from class org.springframework.integration.handler.AbstractMessageHandler

    handleMessage, onComplete, onError, onNext, onSubscribe

    Methods inherited from class org.springframework.integration.handler.MessageHandlerSupport

    buildSendTimer, destroy, getIntegrationPatternType, getManagedName, getManagedType, getMetricsCaptor, getOrder, getOverrides, isLoggingEnabled, registerMetricsCaptor, sendTimer, setLoggingEnabled, setManagedName, setManagedType, setOrder, setShouldTrack, shouldTrack

    Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport

    afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface reactor.core.CoreSubscriber

    currentContext

    Methods inherited from interface org.springframework.integration.support.management.IntegrationManagement

    getThisAs

    Methods inherited from interface org.springframework.integration.support.context.NamedComponent

    getBeanName, getComponentName
  • Field Details

  • Constructor Details

  • Method Details

    • obtainConnection

      protected TcpConnection obtainConnection​(org.springframework.messaging.Message<?> message)
    • handleMessageInternal

      public void handleMessageInternal​(org.springframework.messaging.Message<?> message)
      Writes the message payload to the underlying socket, using the specified message format.
      Specified by:
      handleMessageInternal in class org.springframework.integration.handler.AbstractMessageHandler
      See Also:
      MessageHandler.handleMessage(org.springframework.messaging.Message)
    • doWrite

      protected TcpConnection doWrite​(org.springframework.messaging.Message<?> message)
      Method that actually does the write.
      Parameters:
      message - The message to write.
      Returns:
      the connection.
    • setConnectionFactory

      public void setConnectionFactory​(AbstractConnectionFactory connectionFactory)
      Sets the client or server connection factory; for this (an outbound adapter), if the factory is a server connection factory, the sockets are owned by a receiving channel adapter and this adapter is used to send replies.
      Parameters:
      connectionFactory - the connectionFactory to set
    • 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()
      Specified by:
      getComponentType in interface org.springframework.integration.support.context.NamedComponent
      Overrides:
      getComponentType in class org.springframework.integration.handler.MessageHandlerSupport
    • onInit

      protected void onInit()
      Overrides:
      onInit in class org.springframework.integration.context.IntegrationObjectSupport
    • start

      public void start()
      Specified by:
      start in interface org.springframework.context.Lifecycle
      Specified by:
      start in interface org.springframework.integration.support.management.ManageableLifecycle
    • stop

      public void stop()
      Specified by:
      stop in interface org.springframework.context.Lifecycle
      Specified by:
      stop in interface org.springframework.integration.support.management.ManageableLifecycle
    • isRunning

      public boolean isRunning()
      Specified by:
      isRunning in interface org.springframework.context.Lifecycle
      Specified by:
      isRunning in interface org.springframework.integration.support.management.ManageableLifecycle
    • getClientConnectionFactory

      protected ConnectionFactory getClientConnectionFactory()
      Returns:
      the clientConnectionFactory
    • getServerConnectionFactory

      protected ConnectionFactory getServerConnectionFactory()
      Returns:
      the serverConnectionFactory
    • getConnections

      protected java.util.Map<java.lang.String,​TcpConnection> getConnections()
      Returns:
      the connections
    • 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)
      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