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:
java.lang.Runnable, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, 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, java.lang.Runnable, org.springframework.context.SmartLifecycle

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(TcpConnection connection)
           
protected  void checkActive()
           
abstract  void close()
          Closes the server.
protected  void doAccept(java.nio.channels.Selector selector, java.nio.channels.ServerSocketChannel server, long now)
           
 org.springframework.core.serializer.Deserializer<?> getDeserializer()
           
 java.lang.String getHost()
           
 TcpListener getListener()
           
 TcpMessageMapper getMapper()
           
 int getPhase()
           
 int getPoolSize()
           
 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  void harvestClosedConnections()
           
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 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 setPoolSize(int poolSize)
           
 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 start()
          Starts the listening process.
 void stop()
          Stops the server.
 void stop(java.lang.Runnable callback)
           
protected  TcpConnection wrapConnection(TcpConnection 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
 
Methods inherited from interface java.lang.Runnable
run
 

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

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

getPoolSize

public int getPoolSize()
Returns:
the poolSize

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 -

setPoolSize

public void setPoolSize(int poolSize)

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

close

public abstract void close()
Closes the server.


start

public void start()
Starts the listening process.

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 TcpConnection wrapConnection(TcpConnection 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.

Parameters:
selectionCount -
selector -
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(TcpConnection connection)

harvestClosedConnections

protected void harvestClosedConnections()

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

Spring Integration