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

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

public class TcpNioServerConnectionFactory
extends AbstractServerConnectionFactory

/** Implements a server connection factory that produces TcpNioConnections using a ServerSocketChannel. Must have a TcpListener registered.

Since:
2.0

Field Summary
protected  java.util.Map<java.nio.channels.SocketChannel,TcpNioConnection> connections
           
protected  java.nio.channels.ServerSocketChannel serverChannel
           
protected  boolean usingDirectBuffers
           
 
Fields inherited from class org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory
listening, localAddress
 
Fields inherited from class org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory
active, DEFAULT_REPLY_TIMEOUT, deserializer, host, interceptorFactoryChain, lifecycleMonitor, listener, logger, mapper, poolSize, port, sender, serializer, singleUse, soTimeout
 
Constructor Summary
TcpNioServerConnectionFactory(int port)
          Listens for incoming connections on the port.
 
Method Summary
 void close()
          Closes the server.
protected  void doAccept(java.nio.channels.Selector selector, java.nio.channels.ServerSocketChannel server, long now)
           
 boolean isRunning()
           
 void run()
          If no listener registers, exits.
 void setUsingDirectBuffers(boolean usingDirectBuffers)
           
 
Methods inherited from class org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory
getConnection, getLocalAddress, initializeConnection, isListening, setLocalAddress
 
Methods inherited from class org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory
addConnection, getHost, getPhase, getPort, getSoLinger, getSoReceiveBufferSize, getSoSendBufferSize, getSoTimeout, getSoTrafficClass, getTaskExecutor, harvestClosedConnections, isAutoStartup, isLookupHost, isSingleUse, isSoKeepAlive, isSoTcpNoDelay, processNioSelections, registerListener, registerSender, setDeserializer, setInterceptorFactoryChain, setLookupHost, setMapper, setPoolSize, setSerializer, setSingleUse, setSocketAttributes, setSoKeepAlive, setSoLinger, setSoReceiveBufferSize, setSoSendBufferSize, setSoTcpNoDelay, setSoTimeout, setSoTrafficClass, setTaskExecutor, start, stop, stop, wrapConnection
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serverChannel

protected java.nio.channels.ServerSocketChannel serverChannel

usingDirectBuffers

protected boolean usingDirectBuffers

connections

protected java.util.Map<java.nio.channels.SocketChannel,TcpNioConnection> connections
Constructor Detail

TcpNioServerConnectionFactory

public TcpNioServerConnectionFactory(int port)
Listens for incoming connections on the port.

Parameters:
port - The port.
Method Detail

run

public void run()
If no listener registers, exits. Accepts incoming connections and creates TcpConnections for each new connection. Invokes {AbstractServerConnectionFactory.initializeConnection(TcpConnection, Socket) and executes the connection Runnable.run() using the task executor. I/O errors on the server socket/channel are logged and the factory is stopped.


doAccept

protected void doAccept(java.nio.channels.Selector selector,
                        java.nio.channels.ServerSocketChannel server,
                        long now)
                 throws java.io.IOException
Overrides:
doAccept in class AbstractConnectionFactory
Parameters:
selector -
server -
now -
Throws:
java.io.IOException
java.net.SocketException
java.nio.channels.ClosedChannelException

isRunning

public boolean isRunning()

close

public void close()
Description copied from class: AbstractConnectionFactory
Closes the server.

Specified by:
close in class AbstractConnectionFactory

setUsingDirectBuffers

public void setUsingDirectBuffers(boolean usingDirectBuffers)