Class AbstractServerConnectionFactory

All Implemented Interfaces:
Runnable, Aware, BeanFactoryAware, BeanNameAware, InitializingBean, ApplicationContextAware, ApplicationEventPublisherAware, Lifecycle, ExpressionCapable, OrderlyShutdownCapable, ConnectionFactory, TcpServerConnectionFactory, NamedComponent, ManageableLifecycle, SchedulingAwareRunnable
Direct Known Subclasses:
TcpNetServerConnectionFactory, TcpNioServerConnectionFactory

public abstract class AbstractServerConnectionFactory extends AbstractConnectionFactory implements TcpServerConnectionFactory, SchedulingAwareRunnable, 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.
Gary Russell, Artem Bilan
  • Constructor Details

    • AbstractServerConnectionFactory

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

    • isLongLived

      public boolean isLongLived()
      Specified by:
      isLongLived in interface SchedulingAwareRunnable
    • getServerSocketAddress

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

      public void start()
      Specified by:
      start in interface Lifecycle
      Specified by:
      start in interface ManageableLifecycle
      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)
      listening - the listening to set
    • isListening

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

      protected boolean isShuttingDown()
    • initializeConnection

      protected void initializeConnection(TcpConnectionSupport connection, 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.
      connection - The new connection.
      socket - The new socket.
    • postProcessServerSocket

      protected void postProcessServerSocket(ServerSocket serverSocket)
    • getLocalAddress

      @Nullable public String getLocalAddress()
      the localAddress
    • setLocalAddress

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

      public int getBacklog()
      The number of sockets in the server connection backlog.
      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.
      backlog - The backlog to set.
    • 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
      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
      The number of active messages if available.
    • publishServerExceptionEvent

      protected void publishServerExceptionEvent(Exception ex)
    • publishServerListeningEvent

      protected void publishServerListeningEvent(int port)