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.
Since:
2.0
Author:
Gary Russell, Artem Bilan
  • 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 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
      Returns:
      the socket address.
    • start

      public void start()
      Specified by:
      start in interface Lifecycle
      Specified by:
      start in interface 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, 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(ServerSocket serverSocket)
    • getLocalAddress

      @Nullable public String getLocalAddress()
      Returns:
      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.
      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()
      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
      Returns:
      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
      Returns:
      The number of active messages if available.
    • publishServerExceptionEvent

      protected void publishServerExceptionEvent(Exception ex)
    • publishServerListeningEvent

      protected void publishServerListeningEvent(int port)