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 Link icon

    • logger Link icon

      protected final Log logger
  • Constructor Details Link icon

    • TcpConnectionSupport Link icon

      public TcpConnectionSupport()
    • TcpConnectionSupport Link icon

      public TcpConnectionSupport(@Nullable ApplicationEventPublisher applicationEventPublisher)
    • TcpConnectionSupport Link icon

      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 Link icon

    • close Link icon

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

      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 Link icon

      public TcpMessageMapper getMapper()
      Returns:
      the mapper
    • setMapper Link icon

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

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

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

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

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

      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 Link icon

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

      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 Link icon

      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 Link icon

      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 Link icon

      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 Link icon

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

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

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

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

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

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

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

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

      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 Link icon

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

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

      public String getConnectionFactoryName()
    • isNoReadErrorOnClose Link icon

      protected boolean isNoReadErrorOnClose()
    • setNoReadErrorOnClose Link icon

      protected void setNoReadErrorOnClose(boolean noReadErrorOnClose)
    • sendExceptionToListener Link icon

      protected final void sendExceptionToListener(Exception e)
    • publishConnectionOpenEvent Link icon

      protected void publishConnectionOpenEvent()
    • publishConnectionCloseEvent Link icon

      protected void publishConnectionCloseEvent()
    • publishConnectionExceptionEvent Link icon

      protected void publishConnectionExceptionEvent(Throwable t)
    • publishEvent Link icon

      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 Link icon

      public String toString()
      Overrides:
      toString in class Object