Class TcpNioServerConnectionFactory

java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
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

public class TcpNioServerConnectionFactory
extends AbstractServerConnectionFactory
/** Implements a server connection factory that produces TcpNioConnections using a ServerSocketChannel. Must have a TcpListener registered.
Since:
2.0
  • Constructor Details

    • TcpNioServerConnectionFactory

      public TcpNioServerConnectionFactory​(int port)
      Listens for incoming connections on the port.
      Parameters:
      port - The port.
  • Method Details

    • setMultiAccept

      public void setMultiAccept​(boolean multiAccept)
      Set to false to only accept one connection per iteration over the selector keys. This might be necessary to avoid accepts overwhelming reads of existing sockets. By default when the OP_ACCEPT operation is ready, we will keep accepting connections in a loop until no more arrive.
      Parameters:
      multiAccept - false to accept connections one-at-a-time.
      Since:
      5.1.4
    • getComponentType

      public java.lang.String getComponentType()
      Specified by:
      getComponentType in interface org.springframework.integration.support.context.NamedComponent
      Overrides:
      getComponentType in class org.springframework.integration.context.IntegrationObjectSupport
    • getPort

      public int getPort()
      Description copied from interface: TcpServerConnectionFactory
      Return the port this server is listening on. If the factory is configured to listen on a random port (0), this will return the actual port after the factory is started. It may return the previous value if the factory is stopped.
      Specified by:
      getPort in interface TcpServerConnectionFactory
      Overrides:
      getPort in class AbstractConnectionFactory
      Returns:
      the port
    • 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
      Overrides:
      getServerSocketAddress in class AbstractServerConnectionFactory
      Returns:
      the socket address.
    • run

      public void run()
      If no listener registers, exits. Accepts incoming connections and creates TcpConnections for each new connection. Invokes {AbstractServerConnectionFactory.initializeConnection(TcpConnectionSupport, Socket) and executes the connection Runnable.run() using the task executor. I/O errors on the server socket/channel are logged and the factory is stopped.
    • doAccept

      protected void doAccept​(java.nio.channels.Selector selectorForNewSocket, java.nio.channels.ServerSocketChannel server, long now)
      Overrides:
      doAccept in class AbstractConnectionFactory
      Parameters:
      selectorForNewSocket - The selector.
      server - The server socket channel.
      now - The current time.
    • stop

      public void stop()
      Description copied from class: AbstractConnectionFactory
      Stops the server.
      Specified by:
      stop in interface org.springframework.context.Lifecycle
      Specified by:
      stop in interface org.springframework.integration.support.management.ManageableLifecycle
      Overrides:
      stop in class AbstractConnectionFactory
    • setUsingDirectBuffers

      public void setUsingDirectBuffers​(boolean usingDirectBuffers)
    • setTcpNioConnectionSupport

      public void setTcpNioConnectionSupport​(TcpNioConnectionSupport tcpNioSupport)
    • getServerChannel

      protected java.nio.channels.ServerSocketChannel getServerChannel()
      Returns:
      the serverChannel
    • isUsingDirectBuffers

      protected boolean isUsingDirectBuffers()
      Returns:
      the usingDirectBuffers
    • getConnections

      protected java.util.Map<java.nio.channels.SocketChannel,​TcpNioConnection> getConnections()
      Returns:
      the connections