Class AbstractServerConnectionFactory

java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory
org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory
All Implemented Interfaces:
java.lang.Runnable, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware, org.springframework.context.ApplicationEventPublisherAware, org.springframework.context.Lifecycle, org.springframework.integration.context.ExpressionCapable, org.springframework.integration.context.OrderlyShutdownCapable, ConnectionFactory, TcpServerConnectionFactory, org.springframework.integration.support.context.NamedComponent, org.springframework.integration.support.management.ManageableLifecycle, org.springframework.scheduling.SchedulingAwareRunnable
Direct Known Subclasses:
TcpNetServerConnectionFactory, TcpNioServerConnectionFactory

public abstract class AbstractServerConnectionFactory
extends AbstractConnectionFactory
implements TcpServerConnectionFactory, org.springframework.scheduling.SchedulingAwareRunnable, org.springframework.integration.context.OrderlyShutdownCapable
Base class for all server connection factories. Server connection factories listen on a port for incoming connections and create new TcpConnection objects for each new connection.
Since:
2.0
  • Constructor Details

    • AbstractServerConnectionFactory

      public AbstractServerConnectionFactory​(int port)
      The port on which the factory will listen.
      Parameters:
      port - The port.
  • Method Details

    • isLongLived

      public boolean isLongLived()
      Specified by:
      isLongLived in interface org.springframework.scheduling.SchedulingAwareRunnable
    • getServerSocketAddress

      @Nullable public java.net.SocketAddress getServerSocketAddress()
      Description copied from interface: TcpServerConnectionFactory
      Return the SocketAddress that the underlying ServerSocket is bound to.
      Specified by:
      getServerSocketAddress in interface TcpServerConnectionFactory
      Returns:
      the socket address.
    • start

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

      public TcpConnection getConnection()
      Not supported because the factory manages multiple connections and this method cannot discriminate.
      Specified by:
      getConnection in interface ConnectionFactory
    • setListening

      protected void setListening​(boolean listening)
      Parameters:
      listening - the listening to set
    • isListening

      public boolean isListening()
      Returns:
      true if the server is listening on the port.
    • isShuttingDown

      protected boolean isShuttingDown()
    • initializeConnection

      protected void initializeConnection​(TcpConnectionSupport connection, java.net.Socket socket)
      Transfers attributes such as (de)serializer, mapper etc to a new connection. For single use sockets, enforces a socket timeout (default 10 seconds) to prevent DoS attacks.
      Parameters:
      connection - The new connection.
      socket - The new socket.
    • postProcessServerSocket

      protected void postProcessServerSocket​(java.net.ServerSocket serverSocket)
    • getLocalAddress

      @Nullable public java.lang.String getLocalAddress()
      Returns:
      the localAddress
    • setLocalAddress

      public void setLocalAddress​(java.lang.String localAddress)
      Used on multi-homed systems to enforce the server to listen on a specific network address instead of all network adapters.
      Parameters:
      localAddress - the ip address of the required adapter.
    • getBacklog

      public int getBacklog()
      The number of sockets in the server connection backlog.
      Returns:
      The backlog.
    • setBacklog

      public void setBacklog​(int backlog)
      The number of sockets in the connection backlog. Default 5; increase if you expect high connection rates.
      Parameters:
      backlog - The backlog to set.
    • beforeShutdown

      public int beforeShutdown()
      Specified by:
      beforeShutdown in interface org.springframework.integration.context.OrderlyShutdownCapable
    • afterShutdown

      public int afterShutdown()
      Specified by:
      afterShutdown in interface org.springframework.integration.context.OrderlyShutdownCapable
    • publishServerExceptionEvent

      protected void publishServerExceptionEvent​(java.lang.Exception e)
    • publishServerListeningEvent

      protected void publishServerListeningEvent​(int port)