Class AbstractConnectionFactory

java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory
All Implemented Interfaces:
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, ConnectionFactory, org.springframework.integration.support.context.NamedComponent, org.springframework.integration.support.management.ManageableLifecycle
Direct Known Subclasses:
AbstractClientConnectionFactory, AbstractServerConnectionFactory

public abstract class AbstractConnectionFactory
extends org.springframework.integration.context.IntegrationObjectSupport
implements ConnectionFactory, org.springframework.context.ApplicationEventPublisherAware
Base class for all connection factories.
Since:
2.0
  • Field Details

  • Constructor Details

  • Method Details

    • setApplicationEventPublisher

      public void setApplicationEventPublisher​(org.springframework.context.ApplicationEventPublisher applicationEventPublisher)
      Specified by:
      setApplicationEventPublisher in interface org.springframework.context.ApplicationEventPublisherAware
    • getApplicationEventPublisher

      @Nullable public org.springframework.context.ApplicationEventPublisher getApplicationEventPublisher()
    • setSocketAttributes

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

      public int getSoTimeout()
      Returns:
      the soTimeout
    • setSoTimeout

      public void setSoTimeout​(int soTimeout)
      Parameters:
      soTimeout - the soTimeout to set
    • getSoReceiveBufferSize

      public int getSoReceiveBufferSize()
      Returns:
      the soReceiveBufferSize
    • setSoReceiveBufferSize

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

      public int getSoSendBufferSize()
      Returns:
      the soSendBufferSize
    • setSoSendBufferSize

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

      public boolean isSoTcpNoDelay()
      Returns:
      the soTcpNoDelay
    • setSoTcpNoDelay

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

      public int getSoLinger()
      Returns:
      the soLinger
    • setSoLinger

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

      public boolean isSoKeepAlive()
      Returns:
      the soKeepAlive
    • setSoKeepAlive

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

      public int getSoTrafficClass()
      Returns:
      the soTrafficClass
    • setSoTrafficClass

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

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

      public java.lang.String getHost()
      Returns:
      the host
    • setPort

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

      public int getPort()
      Returns:
      the port
    • getListener

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

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

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

      public org.springframework.core.serializer.Serializer<?> getSerializer()
      Returns:
      the serializer
    • getDeserializer

      public org.springframework.core.serializer.Deserializer<?> getDeserializer()
      Returns:
      the deserializer
    • getMapper

      public TcpMessageMapper getMapper()
      Returns:
      the mapper
    • registerListener

      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

      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

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

      public void setTaskExecutor​(java.util.concurrent.Executor taskExecutor)
      Parameters:
      taskExecutor - the taskExecutor to set
    • setDeserializer

      public void setDeserializer​(org.springframework.core.serializer.Deserializer<?> deserializer)
      Parameters:
      deserializer - the deserializer to set
    • setSerializer

      public void setSerializer​(org.springframework.core.serializer.Serializer<?> serializer)
      Parameters:
      serializer - the serializer to set
    • setMapper

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

      public boolean isSingleUse()
      Returns:
      the singleUse
    • setSingleUse

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

      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

      public void setInterceptorFactoryChain​(TcpConnectionInterceptorFactoryChain interceptorFactoryChain)
    • setLookupHost

      public void setLookupHost​(boolean lookupHost)
      If true, DNS reverse lookup is done on the remote ip address. Default true.
      Parameters:
      lookupHost - the lookupHost to set
    • isLookupHost

      public boolean isLookupHost()
      Returns:
      the lookupHost
    • setNioHarvestInterval

      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

      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

      @Nullable protected java.lang.Integer getSslHandshakeTimeout()
      Returns:
      the handshake timeout.
      Since:
      4.3.6
      See Also:
      setSslHandshakeTimeout(int)
    • getDelayedReads

      protected java.util.concurrent.BlockingQueue<org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory.PendingIO> getDelayedReads()
    • getReadDelay

      protected long getReadDelay()
    • setReadDelay

      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

      protected java.lang.Object getLifecycleMonitor()
    • onInit

      protected void onInit()
      Overrides:
      onInit in class org.springframework.integration.context.IntegrationObjectSupport
    • start

      public void start()
      Specified by:
      start in interface org.springframework.context.Lifecycle
      Specified by:
      start in interface org.springframework.integration.support.management.ManageableLifecycle
    • getTaskExecutor

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

      public void stop()
      Stops the server.
      Specified by:
      stop in interface org.springframework.context.Lifecycle
      Specified by:
      stop in interface org.springframework.integration.support.management.ManageableLifecycle
    • wrapConnection

      protected TcpConnectionSupport wrapConnection​(TcpConnectionSupport connectionArg)
    • processNioSelections

      protected void processNioSelections​(int selectionCount, java.nio.channels.Selector selector, @Nullable java.nio.channels.ServerSocketChannel server, java.util.Map<java.nio.channels.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

      protected void delayRead​(java.nio.channels.Selector selector, long now, java.nio.channels.SelectionKey key)
    • doAccept

      protected void doAccept​(java.nio.channels.Selector selector, java.nio.channels.ServerSocketChannel server, long now)
      Parameters:
      selector - The selector.
      server - The server socket channel.
      now - The current time.
    • addConnection

      protected void addConnection​(TcpConnectionSupport connection)
    • harvestClosedConnections

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

      public boolean isRunning()
      Specified by:
      isRunning in interface org.springframework.context.Lifecycle
      Specified by:
      isRunning in interface org.springframework.integration.support.management.ManageableLifecycle
    • isActive

      protected boolean isActive()
      Returns:
      the active
    • setActive

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

      protected void checkActive()
    • getTcpSocketSupport

      protected TcpSocketSupport getTcpSocketSupport()
    • setTcpSocketSupport

      public void setTcpSocketSupport​(TcpSocketSupport tcpSocketSupport)
    • getOpenConnectionIds

      public java.util.List<java.lang.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

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

      public java.lang.String toString()
      Overrides:
      toString in class org.springframework.integration.context.IntegrationObjectSupport