Spring Integration

org.springframework.integration.ip.tcp.connection
Class AbstractConnectionFactory

java.lang.Object
  extended by org.springframework.integration.context.IntegrationObjectSupport
      extended by 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.ApplicationEventPublisherAware, org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle, NamedComponent, ConnectionFactory
Direct Known Subclasses:
AbstractClientConnectionFactory, AbstractServerConnectionFactory

public abstract class AbstractConnectionFactory
extends IntegrationObjectSupport
implements ConnectionFactory, org.springframework.context.SmartLifecycle, org.springframework.context.ApplicationEventPublisherAware

Base class for all connection factories.

Since:
2.0
Author:
Gary Russell

Field Summary
protected static int DEFAULT_REPLY_TIMEOUT
           
protected  java.lang.Object lifecycleMonitor
           
 
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
logger
 
Constructor Summary
AbstractConnectionFactory(int port)
           
AbstractConnectionFactory(java.lang.String host, int port)
           
 
Method Summary
protected  void addConnection(TcpConnectionSupport connection)
           
protected  void checkActive()
           
abstract  void close()
          Closes the server.
 boolean closeConnection(java.lang.String connectionId)
          Close a connection with the specified connection id.
protected  void doAccept(java.nio.channels.Selector selector, java.nio.channels.ServerSocketChannel server, long now)
           
protected  org.springframework.context.ApplicationEventPublisher getApplicationEventPublisher()
           
 org.springframework.core.serializer.Deserializer<?> getDeserializer()
           
 java.lang.String getHost()
           
 TcpListener getListener()
           
 TcpMessageMapper getMapper()
           
 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.
 int getPhase()
           
 int getPort()
           
 TcpSender getSender()
           
 org.springframework.core.serializer.Serializer<?> getSerializer()
           
 int getSoLinger()
           
 int getSoReceiveBufferSize()
           
 int getSoSendBufferSize()
           
 int getSoTimeout()
           
 int getSoTrafficClass()
           
protected  java.util.concurrent.Executor getTaskExecutor()
          Creates a taskExecutor (if one was not provided).
protected  TcpSocketSupport getTcpSocketSupport()
           
protected  void harvestClosedConnections()
          Cleans up this.connections by removing any closed connections.
protected  boolean isActive()
           
 boolean isAutoStartup()
          We are controlled by the startup options of the bound endpoint.
 boolean isLookupHost()
           
 boolean isRunning()
           
 boolean isSingleUse()
           
 boolean isSoKeepAlive()
           
 boolean isSoTcpNoDelay()
           
protected  void processNioSelections(int selectionCount, java.nio.channels.Selector selector, java.nio.channels.ServerSocketChannel server, java.util.Map<java.nio.channels.SocketChannel,TcpNioConnection> connections)
          Times out any expired connections then, if selectionCount > 0, processes the selected keys.
 void registerListener(TcpListener listener)
          Registers a TcpListener to receive messages after the payload has been converted from the input data.
 void registerSender(TcpSender sender)
          Registers a TcpSender; for server sockets, used to provide connection information so a sender can be used to reply to incoming messages.
protected  void setActive(boolean active)
           
 void setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationEventPublisher)
           
 void setDeserializer(org.springframework.core.serializer.Deserializer<?> deserializer)
           
 void setInterceptorFactoryChain(TcpConnectionInterceptorFactoryChain interceptorFactoryChain)
           
 void setLookupHost(boolean lookupHost)
          If true, DNS reverse lookup is done on the remote ip address.
 void setMapper(TcpMessageMapper mapper)
           
 void setNioHarvestInterval(int nioHarvestInterval)
          How often we clean up closed NIO connections if soTimeout is 0.
 void setSerializer(org.springframework.core.serializer.Serializer<?> serializer)
           
 void setSingleUse(boolean singleUse)
          If true, sockets created by this factory will be used once.
protected  void setSocketAttributes(java.net.Socket socket)
          Sets socket attributes on the socket.
 void setSoKeepAlive(boolean soKeepAlive)
           
 void setSoLinger(int soLinger)
           
 void setSoReceiveBufferSize(int soReceiveBufferSize)
           
 void setSoSendBufferSize(int soSendBufferSize)
           
 void setSoTcpNoDelay(boolean soTcpNoDelay)
           
 void setSoTimeout(int soTimeout)
           
 void setSoTrafficClass(int soTrafficClass)
           
 void setTaskExecutor(java.util.concurrent.Executor taskExecutor)
           
 void setTcpSocketSupport(TcpSocketSupport tcpSocketSupport)
           
 void start()
           
 void stop()
          Stops the server.
 void stop(java.lang.Runnable callback)
           
protected  TcpConnectionSupport wrapConnection(TcpConnectionSupport connection)
           
 
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, getBeanFactory, getComponentName, getComponentType, getConversionService, getTaskScheduler, onInit, setBeanFactory, setBeanName, setComponentName, setConversionService, setTaskScheduler, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.springframework.integration.ip.tcp.connection.ConnectionFactory
getConnection
 

Field Detail

DEFAULT_REPLY_TIMEOUT

protected static final int DEFAULT_REPLY_TIMEOUT
See Also:
Constant Field Values

lifecycleMonitor

protected final java.lang.Object lifecycleMonitor
Constructor Detail

AbstractConnectionFactory

public AbstractConnectionFactory(int port)

AbstractConnectionFactory

public AbstractConnectionFactory(java.lang.String host,
                                 int port)
Method Detail

setApplicationEventPublisher

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

getApplicationEventPublisher

protected 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

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

getHost

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

getPort

public int getPort()
Returns:
the port

getListener

public TcpListener getListener()
Returns:
the listener

getSender

public TcpSender getSender()
Returns:
the sender

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 listener)
Registers a TcpListener to receive messages after the payload has been converted from the input data.

Parameters:
listener - the TcpListener.

registerSender

public void registerSender(TcpSender sender)
Registers a TcpSender; for server sockets, used to provide connection information so a sender can be used to reply to incoming messages.

Parameters:
sender - The sender

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 -

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.

close

public abstract void close()
Closes the server.


start

public void start()
Specified by:
start in interface org.springframework.context.Lifecycle

getTaskExecutor

protected java.util.concurrent.Executor getTaskExecutor()
Creates a taskExecutor (if one was not provided).


stop

public void stop()
Stops the server.

Specified by:
stop in interface org.springframework.context.Lifecycle

wrapConnection

protected TcpConnectionSupport wrapConnection(TcpConnectionSupport connection)
                                       throws java.lang.Exception
Throws:
java.lang.Exception

processNioSelections

protected void processNioSelections(int selectionCount,
                                    java.nio.channels.Selector selector,
                                    java.nio.channels.ServerSocketChannel server,
                                    java.util.Map<java.nio.channels.SocketChannel,TcpNioConnection> connections)
                             throws java.io.IOException
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
connections - Map of connections
Throws:
java.io.IOException

doAccept

protected void doAccept(java.nio.channels.Selector selector,
                        java.nio.channels.ServerSocketChannel server,
                        long now)
                 throws java.io.IOException
Parameters:
selector -
now -
Throws:
java.io.IOException

getPhase

public int getPhase()
Specified by:
getPhase in interface org.springframework.context.Phased

isAutoStartup

public boolean isAutoStartup()
We are controlled by the startup options of the bound endpoint.

Specified by:
isAutoStartup in interface org.springframework.context.SmartLifecycle

stop

public void stop(java.lang.Runnable callback)
Specified by:
stop in interface org.springframework.context.SmartLifecycle

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

isActive

protected boolean isActive()
Returns:
the active

setActive

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

checkActive

protected void checkActive()
                    throws java.io.IOException
Throws:
java.io.IOException

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.

Spring Integration