Class AbstractConnectionFactory

java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory
All Implemented Interfaces:
Aware, BeanFactoryAware, BeanNameAware, InitializingBean, ApplicationContextAware, ApplicationEventPublisherAware, Lifecycle, ComponentSourceAware, ExpressionCapable, ConnectionFactory, NamedComponent, ManageableLifecycle
Direct Known Subclasses:
AbstractClientConnectionFactory, AbstractServerConnectionFactory

public abstract class AbstractConnectionFactory extends IntegrationObjectSupport implements ConnectionFactory, ApplicationEventPublisherAware
Base class for all connection factories.
Since:
2.0
Author:
Gary Russell, Artem Bilan, Christian Tzolov, Ngoc Nhan
  • Field Details Link icon

    • DEFAULT_REPLY_TIMEOUT Link icon

      protected static final int DEFAULT_REPLY_TIMEOUT
      See Also:
    • lifecycleMonitor Link icon

      protected final Lock lifecycleMonitor
    • connections Link icon

      protected final Map<String,TcpConnectionSupport> connections
    • connectionsMonitor Link icon

      protected final Lock connectionsMonitor
  • Constructor Details Link icon

    • AbstractConnectionFactory Link icon

      public AbstractConnectionFactory(int port)
    • AbstractConnectionFactory Link icon

      public AbstractConnectionFactory(String host, int port)
  • Method Details Link icon

    • setApplicationEventPublisher Link icon

      public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)
      Specified by:
      setApplicationEventPublisher in interface ApplicationEventPublisherAware
    • getApplicationEventPublisher Link icon

      @Nullable public ApplicationEventPublisher getApplicationEventPublisher()
    • setSocketAttributes Link icon

      protected void setSocketAttributes(Socket socket) throws SocketException
      Sets socket attributes on the socket.
      Parameters:
      socket - The socket.
      Throws:
      SocketException - Any SocketException.
    • getSoTimeout Link icon

      public int getSoTimeout()
      Returns:
      the soTimeout
    • setSoTimeout Link icon

      public void setSoTimeout(int soTimeout)
      Parameters:
      soTimeout - the soTimeout to set, in milliseconds
    • getSoReceiveBufferSize Link icon

      public int getSoReceiveBufferSize()
      Returns:
      the soReceiveBufferSize
    • setSoReceiveBufferSize Link icon

      public void setSoReceiveBufferSize(int soReceiveBufferSize)
      Parameters:
      soReceiveBufferSize - the soReceiveBufferSize to set
    • getSoSendBufferSize Link icon

      public int getSoSendBufferSize()
      Returns:
      the soSendBufferSize
    • setSoSendBufferSize Link icon

      public void setSoSendBufferSize(int soSendBufferSize)
      Parameters:
      soSendBufferSize - the soSendBufferSize to set
    • isSoTcpNoDelay Link icon

      public boolean isSoTcpNoDelay()
      Returns:
      the soTcpNoDelay
    • setSoTcpNoDelay Link icon

      public void setSoTcpNoDelay(boolean soTcpNoDelay)
      Parameters:
      soTcpNoDelay - the soTcpNoDelay to set
    • getSoLinger Link icon

      public int getSoLinger()
      Returns:
      the soLinger
    • setSoLinger Link icon

      public void setSoLinger(int soLinger)
      Parameters:
      soLinger - the soLinger to set
    • isSoKeepAlive Link icon

      public boolean isSoKeepAlive()
      Returns:
      the soKeepAlive
    • setSoKeepAlive Link icon

      public void setSoKeepAlive(boolean soKeepAlive)
      Parameters:
      soKeepAlive - the soKeepAlive to set
    • getSoTrafficClass Link icon

      public int getSoTrafficClass()
      Returns:
      the soTrafficClass
    • setSoTrafficClass Link icon

      public void setSoTrafficClass(int soTrafficClass)
      Parameters:
      soTrafficClass - the soTrafficClass to set
    • setHost Link icon

      public void setHost(String host)
      Set the host; requires the factory to be stopped.
      Parameters:
      host - the host.
      Since:
      5.0
    • getHost Link icon

      public String getHost()
      Returns:
      the host
    • setPort Link icon

      public void setPort(int port)
      Set the port; requires the factory to be stopped.
      Parameters:
      port - the port.
      Since:
      5.0
    • getPort Link icon

      public int getPort()
      Returns:
      the port
    • getListener Link icon

      @Nullable public TcpListener getListener()
      Returns:
      the listener
    • getSender Link icon

      @Nullable public TcpSender getSender()
      Returns:
      the first sender, if present.
    • getSenders Link icon

      public List<TcpSender> getSenders()
      Return the list of senders.
      Returns:
      the senders.
      Since:
      5.4
    • getSerializer Link icon

      public Serializer<?> getSerializer()
      Returns:
      the serializer
    • getDeserializer Link icon

      public Deserializer<?> getDeserializer()
      Returns:
      the deserializer
    • getMapper Link icon

      public TcpMessageMapper getMapper()
      Returns:
      the mapper
    • registerListener Link icon

      public void registerListener(TcpListener listenerToRegister)
      Registers a TcpListener to receive messages after the payload has been converted from the input data.
      Parameters:
      listenerToRegister - the TcpListener.
    • registerSender Link icon

      public void registerSender(TcpSender senderToRegister)
      Registers a TcpSender; for server sockets, used to provide connection information so a sender can be used to reply to incoming messages.
      Parameters:
      senderToRegister - The sender
    • unregisterSender Link icon

      public boolean unregisterSender(TcpSender sender)
      Unregister a TcpSender.
      Parameters:
      sender - the sender.
      Returns:
      true if the sender was registered.
    • setTaskExecutor Link icon

      public void setTaskExecutor(Executor taskExecutor)
      Parameters:
      taskExecutor - the taskExecutor to set
    • setDeserializer Link icon

      public void setDeserializer(Deserializer<?> deserializer)
      Parameters:
      deserializer - the deserializer to set
    • setSerializer Link icon

      public void setSerializer(Serializer<?> serializer)
      Parameters:
      serializer - the serializer to set
    • setMapper Link icon

      public void setMapper(TcpMessageMapper mapper)
      Parameters:
      mapper - the mapper to set; defaults to a TcpMessageMapper
    • isSingleUse Link icon

      public boolean isSingleUse()
      Returns:
      the singleUse
    • setSingleUse Link icon

      public void setSingleUse(boolean singleUse)
      If true, sockets created by this factory will be used once.
      Parameters:
      singleUse - The singleUse to set.
    • setLeaveOpen Link icon

      public void setLeaveOpen(boolean leaveOpen)
      If true, sockets created by this factory will be reused. Inverse of setSingleUse(boolean).
      Parameters:
      leaveOpen - The keepOpen to set.
      Since:
      5.0
    • setInterceptorFactoryChain Link icon

      public void setInterceptorFactoryChain(TcpConnectionInterceptorFactoryChain interceptorFactoryChain)
    • setLookupHost Link icon

      public void setLookupHost(boolean lookupHost)
      If true, DNS reverse lookup is done on the remote ip address. Default false: not all environments (e.g. Docker containers) perform reliable DNS resolution.
      Parameters:
      lookupHost - the lookupHost to set
    • isLookupHost Link icon

      public boolean isLookupHost()
      Returns:
      the lookupHost
    • setNioHarvestInterval Link icon

      public void setNioHarvestInterval(int nioHarvestInterval)
      How often we clean up closed NIO connections if soTimeout is 0. Ignored when soTimeout > 0 because the clean up process is run as part of the timeout handling. Default 2000 milliseconds.
      Parameters:
      nioHarvestInterval - The interval in milliseconds.
    • setSslHandshakeTimeout Link icon

      public void setSslHandshakeTimeout(int sslHandshakeTimeout)
      Set the handshake timeout used when waiting for SSL handshake data; only applies to SSL connections, when using NIO.
      Parameters:
      sslHandshakeTimeout - the timeout.
      Since:
      4.3.6
    • getSslHandshakeTimeout Link icon

      @Nullable protected Integer getSslHandshakeTimeout()
      Returns:
      the handshake timeout.
      Since:
      4.3.6
      See Also:
    • getDelayedReads Link icon

      protected BlockingQueue<org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory.PendingIO> getDelayedReads()
    • getReadDelay Link icon

      protected long getReadDelay()
    • setReadDelay Link icon

      public void setReadDelay(long readDelay)
      The delay (in milliseconds) before retrying a read after the previous attempt failed due to insufficient threads. Default 100.
      Parameters:
      readDelay - the readDelay to set.
    • getLifecycleMonitor Link icon

      protected Object getLifecycleMonitor()
    • onInit Link icon

      protected void onInit()
      Description copied from class: IntegrationObjectSupport
      Subclasses may implement this for initialization logic.
      Overrides:
      onInit in class IntegrationObjectSupport
    • start Link icon

      public void start()
      Specified by:
      start in interface Lifecycle
      Specified by:
      start in interface ManageableLifecycle
    • getTaskExecutor Link icon

      protected Executor getTaskExecutor()
      Creates a taskExecutor (if one was not provided).
      Returns:
      The executor.
    • stop Link icon

      public void stop()
      Stops the server.
      Specified by:
      stop in interface Lifecycle
      Specified by:
      stop in interface ManageableLifecycle
    • wrapConnection Link icon

      protected TcpConnectionSupport wrapConnection(TcpConnectionSupport connectionArg)
    • processNioSelections Link icon

      protected void processNioSelections(int selectionCount, Selector selector, @Nullable ServerSocketChannel server, Map<SocketChannel,TcpNioConnection> connectionMap)
      Times out any expired connections then, if selectionCount > 0, processes the selected keys. Removes closed connections from the connections field, and from the connections parameter.
      Parameters:
      selectionCount - Number of IO Events, if 0 we were probably woken up by a close.
      selector - The selector.
      server - The server socket channel.
      connectionMap - Map of connections.
    • delayRead Link icon

      protected void delayRead(Selector selector, long now, SelectionKey key)
    • doAccept Link icon

      protected void doAccept(Selector selector, ServerSocketChannel server, long now)
      Parameters:
      selector - The selector.
      server - The server socket channel.
      now - The current time.
    • addConnection Link icon

      protected void addConnection(TcpConnectionSupport connection)
    • harvestClosedConnections Link icon

      protected void harvestClosedConnections()
      Cleans up this.connections by removing any closed connections.
    • isRunning Link icon

      public boolean isRunning()
      Specified by:
      isRunning in interface Lifecycle
      Specified by:
      isRunning in interface ManageableLifecycle
    • isActive Link icon

      protected boolean isActive()
      Returns:
      the active
    • setActive Link icon

      protected void setActive(boolean active)
      Parameters:
      active - the active to set
    • checkActive Link icon

      protected void checkActive()
    • getTcpSocketSupport Link icon

      protected TcpSocketSupport getTcpSocketSupport()
    • setTcpSocketSupport Link icon

      public void setTcpSocketSupport(TcpSocketSupport tcpSocketSupport)
    • getOpenConnectionIds Link icon

      public List<String> getOpenConnectionIds()
      Returns a list of (currently) open TcpConnection connection ids; allows, for example, broadcast operations to all open connections.
      Returns:
      the list of connection ids.
    • closeConnection Link icon

      public boolean closeConnection(String connectionId)
      Close a connection with the specified connection id.
      Parameters:
      connectionId - the connection id.
      Returns:
      true if the connection was closed.
    • toString Link icon

      public String toString()
      Overrides:
      toString in class IntegrationObjectSupport