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

java.lang.Object
  extended by org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory
All Implemented Interfaces:
java.lang.Runnable, Lifecycle, Phased, SmartLifecycle, ConnectionFactory
Direct Known Subclasses:
AbstractClientConnectionFactory, AbstractServerConnectionFactory

public abstract class AbstractConnectionFactory
extends java.lang.Object
implements ConnectionFactory, java.lang.Runnable, SmartLifecycle

Base class for all connection factories.

Since:
2.0

Field Summary
protected  boolean active
           
protected static int DEFAULT_REPLY_TIMEOUT
           
protected  Deserializer<?> deserializer
           
protected  java.lang.String host
           
protected  TcpConnectionInterceptorFactoryChain interceptorFactoryChain
           
protected  java.lang.Object lifecycleMonitor
           
protected  TcpListener listener
           
protected  org.apache.commons.logging.Log logger
           
protected  TcpMessageMapper mapper
           
protected  int poolSize
           
protected  int port
           
protected  TcpSender sender
           
protected  Serializer<?> serializer
           
protected  boolean singleUse
           
protected  int soTimeout
           
 
Constructor Summary
AbstractConnectionFactory()
           
 
Method Summary
protected  void addConnection(TcpConnection connection)
           
abstract  void close()
          Closes the server.
protected  void doAccept(java.nio.channels.Selector selector, java.nio.channels.ServerSocketChannel server, long now)
           
 java.lang.String getHost()
           
 int getPhase()
           
 int getPort()
           
 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()
           
 boolean isAutoStartup()
           
 boolean isLookupHost()
           
 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.
 void setDeserializer(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(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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.springframework.integration.ip.tcp.connection.ConnectionFactory
getConnection
 
Methods inherited from interface java.lang.Runnable
run
 
Methods inherited from interface org.springframework.context.Lifecycle
isRunning
 

Field Detail

logger

protected org.apache.commons.logging.Log logger

DEFAULT_REPLY_TIMEOUT

protected static final int DEFAULT_REPLY_TIMEOUT
See Also:
Constant Field Values

host

protected java.lang.String host

port

protected int port

listener

protected TcpListener listener

sender

protected TcpSender sender

soTimeout

protected int soTimeout

deserializer

protected Deserializer<?> deserializer

serializer

protected Serializer<?> serializer

mapper

protected TcpMessageMapper mapper

singleUse

protected boolean singleUse

poolSize

protected int poolSize

active

protected volatile boolean active

interceptorFactoryChain

protected TcpConnectionInterceptorFactoryChain interceptorFactoryChain

lifecycleMonitor

protected final java.lang.Object lifecycleMonitor
Constructor Detail

AbstractConnectionFactory

public AbstractConnectionFactory()
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

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(Deserializer<?> deserializer)
Parameters:
deserializer - the deserializer to set

setSerializer

public void setSerializer(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 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 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 Phased

isAutoStartup

public boolean isAutoStartup()
Specified by:
isAutoStartup in interface SmartLifecycle

stop

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

addConnection

protected void addConnection(TcpConnection connection)

harvestClosedConnections

protected void harvestClosedConnections()