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:
Runnable, TcpConnection

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
connectionId, inputConverter, listener, logger, mapper, outputConverter, sender, server, singleUse
 
Constructor Summary
TcpNioConnection(SocketChannel socketChannel, boolean server)
          Constructs a TcpNetConnection for the SocketChannel.
 
Method Summary
protected  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.
 String getConnectionId()
           
 String getHostAddress()
           
 String getHostName()
           
 long getLastRead()
           
 Object getPayload()
          Uses the input converter 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(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
getInputConverter, getListener, getMapper, getOutputConverter, isServer, isSingleUse, registerListener, registerSender, setInputConverter, setMapper, setOutputConverter, setSingleUse
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TcpNioConnection

public TcpNioConnection(SocketChannel socketChannel,
                        boolean server)
                 throws 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:
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 Exception
Description copied from interface: TcpConnection
Converts and sends the message.

Parameters:
message - The message
Throws:
Exception

getHostAddress

public String getHostAddress()
Returns:
the host address

getHostName

public String getHostName()
Returns:
the host name

getPayload

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

Returns:
The payload
Throws:
Exception

getPort

public int getPort()
Returns:
the port

allocate

protected 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(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 -

getConnectionId

public String getConnectionId()
Returns:
a string uniquely representing a connection.

getLastRead

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

setLastRead

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

Spring Integration

Copyright © 2010. All Rights Reserved.