Class TcpNetServerConnectionFactory

java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
All Implemented Interfaces:
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 TcpNetServerConnectionFactory extends AbstractServerConnectionFactory
Implements a server connection factory that produces TcpNetConnections using a ServerSocket. Must have a TcpListener registered.
Since:
2.0
  • Constructor Details

    • TcpNetServerConnectionFactory

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

    • getComponentType

      public 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 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.
    • setTcpSocketFactorySupport

      public void setTcpSocketFactorySupport(TcpSocketFactorySupport tcpSocketFactorySupport)
    • setTcpNetConnectionSupport

      public void setTcpNetConnectionSupport(TcpNetConnectionSupport connectionSupport)
      Set the TcpNetConnectionSupport to use to create connection objects.
      Parameters:
      connectionSupport - the connection support.
      Since:
      5.0
    • 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.
    • createServerSocket

      protected ServerSocket createServerSocket(int port, int backlog, @Nullable InetAddress whichNic) throws IOException
      Create a new ServerSocket. This default implementation uses the default ServerSocketFactory. Override to use some other mechanism
      Parameters:
      port - The port.
      backlog - The server socket backlog.
      whichNic - An InetAddress if binding to a specific network interface. Set to null when configured to bind to all interfaces.
      Returns:
      The Server Socket.
      Throws:
      IOException - Any IOException.
    • 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
    • getServerSocket

      protected ServerSocket getServerSocket()
      Returns:
      the serverSocket
    • getTcpSocketFactorySupport

      protected TcpSocketFactorySupport getTcpSocketFactorySupport()