Spring Integration

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
Direct Known Subclasses:
TcpNioSSLConnection

public class TcpNioConnection
extends AbstractTcpConnection

A TcpConnection that uses and underlying SocketChannel.

Since:
2.0
Author:
Gary Russell

Field Summary
 
Fields inherited from class org.springframework.integration.ip.tcp.connection.AbstractTcpConnection
logger
 
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.
protected  org.springframework.integration.ip.tcp.connection.TcpNioConnection.ChannelOutputStream getChannelOutputStream()
           
 long getLastRead()
           
 long getLastSend()
           
 java.lang.Object getPayload()
          Uses the deserializer to obtain the message payload from the connection's input stream.
 int getPort()
           
 boolean isOpen()
           
protected  boolean isUsingDirectBuffers()
           
 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.
protected  void sendToPipe(java.nio.ByteBuffer rawBuffer)
           
 void setLastRead(long lastRead)
           
 void setPipeTimeout(long pipeTimeout)
           
 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, getDeserializer, getHostAddress, getHostName, getListener, getMapper, getSender, getSerializer, incrementAndGetConnectionSequence, isNoReadErrorOnClose, isServer, isSingleUse, registerListener, registerSender, setDeserializer, setMapper, setNoReadErrorOnClose, 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

setPipeTimeout

public void setPipeTimeout(long pipeTimeout)

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.


sendToPipe

protected void sendToPipe(java.nio.ByteBuffer rawBuffer)
                   throws java.io.IOException
Throws:
java.io.IOException

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 -

isUsingDirectBuffers

protected boolean isUsingDirectBuffers()

getChannelOutputStream

protected org.springframework.integration.ip.tcp.connection.TcpNioConnection.ChannelOutputStream getChannelOutputStream()

getLastRead

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

setLastRead

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

getLastSend

public long getLastSend()
Returns:
the time of the last send

Spring Integration