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

java.lang.Object
  extended by org.springframework.integration.ip.tcp.connection.AbstractTcpConnection
      extended by org.springframework.integration.ip.tcp.connection.TcpNioConnection
All Implemented Interfaces:
java.lang.Runnable, TcpConnection

public class TcpNioConnection
extends AbstractTcpConnection

A TcpConnection that uses and underlying SocketChannel.

Since:
2.0

Field Summary
 
Fields inherited from class org.springframework.integration.ip.tcp.connection.AbstractTcpConnection
connectionId, deserializer, listener, logger, mapper, sender, serializer, server, singleUse
 
Constructor Summary
TcpNioConnection(java.nio.channels.SocketChannel socketChannel, boolean server, boolean lookupHost)
          Constructs a TcpNetConnection for the SocketChannel.
 
Method Summary
protected  java.nio.ByteBuffer allocate(int length)
          Allocates a ByteBuffer of the requested length using normal or direct buffers, depending on the usingDirectBuffers field.
 void close()
          Closes this connection.
 long getLastRead()
           
 java.lang.Object getPayload()
          Uses the deserializer to obtain the message payload from the connection's input stream.
 int getPort()
           
 boolean isOpen()
           
 void readPacket()
          Invoked by the factory when there is data to be read.
 void run()
          If there is no listener, and this connection is not for single use, this method exits.
 void send(Message<?> message)
          Converts and sends the message.
 void setLastRead(long lastRead)
           
 void setTaskExecutor(java.util.concurrent.Executor taskExecutor)
           
 void setUsingDirectBuffers(boolean usingDirectBuffers)
          If true, connection will attempt to use direct buffers where possible.
 
Methods inherited from class org.springframework.integration.ip.tcp.connection.AbstractTcpConnection
afterSend, closeConnection, getConnectionId, getConnectionSeq, getDeserializer, getHostAddress, getHostName, getListener, getMapper, getSerializer, isServer, isSingleUse, registerListener, registerSender, setDeserializer, setMapper, setSerializer, setSingleUse
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TcpNioConnection

public TcpNioConnection(java.nio.channels.SocketChannel socketChannel,
                        boolean server,
                        boolean lookupHost)
                 throws java.lang.Exception
Constructs a TcpNetConnection for the SocketChannel.

Parameters:
socketChannel - the socketChannel
server - if true this connection was created as a result of an incoming request.
Throws:
java.lang.Exception
Method Detail

close

public void close()
Description copied from class: AbstractTcpConnection
Closes this connection.

Specified by:
close in interface TcpConnection
Overrides:
close in class AbstractTcpConnection

isOpen

public boolean isOpen()
Returns:
true if the connection is open.

send

public void send(Message<?> message)
          throws java.lang.Exception
Description copied from interface: TcpConnection
Converts and sends the message.

Parameters:
message - The message
Throws:
java.lang.Exception

getPayload

public java.lang.Object getPayload()
                            throws java.lang.Exception
Description copied from interface: TcpConnection
Uses the deserializer to obtain the message payload from the connection's input stream.

Returns:
The payload
Throws:
java.lang.Exception

getPort

public int getPort()
Returns:
the port

allocate

protected java.nio.ByteBuffer allocate(int length)
Allocates a ByteBuffer of the requested length using normal or direct buffers, depending on the usingDirectBuffers field.


run

public void run()
If there is no listener, and this connection is not for single use, this method exits. When there is a listener, this method assembles data into messages by invoking convertAndSend whenever there is data in the input Stream. Method exits when a message is complete and there is no more data; thus freeing the thread to work on other sockets.


readPacket

public void readPacket()
Invoked by the factory when there is data to be read.


setTaskExecutor

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

setUsingDirectBuffers

public void setUsingDirectBuffers(boolean usingDirectBuffers)
If true, connection will attempt to use direct buffers where possible.

Parameters:
usingDirectBuffers -

getLastRead

public long getLastRead()
Returns:
Time of last read.

setLastRead

public void setLastRead(long lastRead)
Parameters:
lastRead - The time of the last read.