Class TcpConnectionSupport

java.lang.Object
org.springframework.integration.ip.tcp.connection.TcpConnectionSupport
All Implemented Interfaces:
Runnable, TcpConnection
Direct Known Subclasses:
TcpConnectionInterceptorSupport, TcpNetConnection, TcpNioConnection

public abstract class TcpConnectionSupport extends Object implements TcpConnection
Base class for TcpConnections. TcpConnections are established by client connection factories (outgoing) or server connection factories (incoming).
Since:
2.0
Author:
Gary Russell, Artem Bilan
  • Field Details

    • logger

      protected final Log logger
  • Constructor Details

    • TcpConnectionSupport

      public TcpConnectionSupport()
    • TcpConnectionSupport

      public TcpConnectionSupport(@Nullable ApplicationEventPublisher applicationEventPublisher)
    • TcpConnectionSupport

      public TcpConnectionSupport(Socket socket, boolean server, boolean lookupHost, @Nullable ApplicationEventPublisher applicationEventPublisher, @Nullable String connectionFactoryName)
      Create a TcpConnectionSupport object and publishes a TcpConnectionOpenEvent, if an event publisher is provided.
      Parameters:
      socket - the underlying socket.
      server - true if this connection is a server connection
      lookupHost - true if reverse lookup of the host name should be performed, otherwise, the ip address will be used for identification purposes.
      applicationEventPublisher - the publisher to which open, close and exception events will be sent; may be null if event publishing is not required.
      connectionFactoryName - the name of the connection factory creating this connection; used during event publishing, may be null, in which case "unknown" will be used.
  • Method Details

    • close

      public void close()
      Close this connection.
      Specified by:
      close in interface TcpConnection
    • closeConnection

      protected void closeConnection(boolean isException)
      If we have been intercepted, propagate the close from the outermost interceptor; otherwise, just call close().
      Parameters:
      isException - true when this call is the result of an Exception.
    • getMapper

      public TcpMessageMapper getMapper()
      Returns:
      the mapper
    • setMapper

      public void setMapper(TcpMessageMapper mapper)
      Parameters:
      mapper - the mapper to set
    • getDeserializer

      public Deserializer<?> getDeserializer()
      Specified by:
      getDeserializer in interface TcpConnection
      Returns:
      the deserializer
    • setDeserializer

      public void setDeserializer(Deserializer<?> deserializer)
      Parameters:
      deserializer - the deserializer to set
    • getSerializer

      public Serializer<?> getSerializer()
      Specified by:
      getSerializer in interface TcpConnection
      Returns:
      the serializer
    • setSerializer

      public void setSerializer(Serializer<?> serializer)
      Parameters:
      serializer - the serializer to set
    • setNeedsTest

      public void setNeedsTest(boolean needsTest)
      Set to true to use a temporary listener for just the first incoming message.
      Parameters:
      needsTest - true for a temporary listener.
      Since:
      5.3
    • registerListener

      public void registerListener(@Nullable TcpListener listener)
      Set the listener that will receive incoming Messages.
      Parameters:
      listener - The listener.
    • registerTestListener

      public void registerTestListener(TcpListener tListener)
      Set a temporary listener to receive just the first incoming message. Used in conjunction with a connectionTest in a client connection factory.
      Parameters:
      tListener - the test listener.
      Since:
      5.3
    • enableManualListenerRegistration

      public void enableManualListenerRegistration()
      Set whether or not automatic or manual registration of the TcpListener is to be used. (Default automatic). When manual registration is in place, incoming messages will be delayed until the listener is registered.
      Since:
      1.4.5
    • registerSender

      public void registerSender(@Nullable TcpSender senderToRegister)
      Register a sender. Used on server side connections so a sender can determine which connection to send a reply to.
      Parameters:
      senderToRegister - the sender.
    • registerSenders

      public void registerSenders(List<TcpSender> sendersToRegister)
      Register the senders. Used on server side connections so a sender can determine which connection to send a reply to.
      Parameters:
      sendersToRegister - the sender.
      Since:
      5.4
    • getListener

      @Nullable public TcpListener getListener()
      Specified by:
      getListener in interface TcpConnection
      Returns:
      the listener
    • getSender

      @Nullable public TcpSender getSender()
      Returns:
      the first sender, if present.
    • getSenders

      public List<TcpSender> getSenders()
      Return the list of senders.
      Returns:
      the senders.
      Since:
      5.4
    • isServer

      public boolean isServer()
      Specified by:
      isServer in interface TcpConnection
      Returns:
      True if connection is used once.
    • incrementAndGetConnectionSequence

      public long incrementAndGetConnectionSequence()
      Specified by:
      incrementAndGetConnectionSequence in interface TcpConnection
      Returns:
      the next sequence number for a message received on this socket
    • getHostAddress

      public String getHostAddress()
      Specified by:
      getHostAddress in interface TcpConnection
      Returns:
      the host address
    • getHostName

      public String getHostName()
      Specified by:
      getHostName in interface TcpConnection
      Returns:
      the host name
    • getConnectionId

      public String getConnectionId()
      Specified by:
      getConnectionId in interface TcpConnection
      Returns:
      a string uniquely representing a connection.
    • getSocketInfo

      public SocketInfo getSocketInfo()
      Description copied from interface: TcpConnection
      Provides getters for Socket properties.
      Specified by:
      getSocketInfo in interface TcpConnection
      Returns:
      the socketInfo - may be null, for example in interceptors; interceptors should override and delegate to the actual TcpConnection.
      Since:
      4.2.5
    • setWrapped

      public void setWrapped(boolean wrapped)
      Set to true if intercepted.
      Parameters:
      wrapped - true if wrapped.
      Since:
      5.4.5
    • setWrapper

      public void setWrapper(TcpConnectionSupport wrapper)
      Set the wrapper.
      Parameters:
      wrapper - the wrapper.
      Since:
      5.4.6
    • getConnectionFactoryName

      public String getConnectionFactoryName()
    • isNoReadErrorOnClose

      protected boolean isNoReadErrorOnClose()
    • setNoReadErrorOnClose

      protected void setNoReadErrorOnClose(boolean noReadErrorOnClose)
    • sendExceptionToListener

      protected final void sendExceptionToListener(Exception e)
    • publishConnectionOpenEvent

      protected void publishConnectionOpenEvent()
    • publishConnectionCloseEvent

      protected void publishConnectionCloseEvent()
    • publishConnectionExceptionEvent

      protected void publishConnectionExceptionEvent(Throwable t)
    • publishEvent

      public void publishEvent(TcpConnectionEvent event)
      Allow interceptors etc to publish events, perhaps subclasses of TcpConnectionEvent. The event source must be this connection.
      Parameters:
      event - the event to publish.
    • toString

      public String toString()
      Overrides:
      toString in class Object