Spring Integration

org.springframework.integration.ip.tcp
Class NioSocketReader

java.lang.Object
  extended by org.springframework.integration.ip.tcp.AbstractSocketReader
      extended by org.springframework.integration.ip.tcp.NioSocketReader
All Implemented Interfaces:
MessageFormats, SocketReader

public class NioSocketReader
extends AbstractSocketReader

A non-blocking SocketReader that reads from a SocketChannel.

Since:
2.0
Author:
Gary Russell

Field Summary
protected  ByteBuffer buildBuffer
           
protected  boolean building
           
protected  SocketChannel channel
           
protected  ByteBuffer dataPart
           
protected  ByteBuffer lengthPart
           
protected  org.apache.commons.logging.Log logger
           
protected  ByteBuffer rawBuffer
           
protected  boolean usingDirectBuffers
           
 
Fields inherited from class org.springframework.integration.ip.tcp.AbstractSocketReader
assembledData, maxMessageSize, messageFormat
 
Fields inherited from interface org.springframework.integration.ip.tcp.SocketReader
MESSAGE_COMPLETE, MESSAGE_INCOMPLETE, SOCKET_CLOSED
 
Fields inherited from interface org.springframework.integration.ip.tcp.MessageFormats
ETX, FORMAT_CRLF, FORMAT_CUSTOM, FORMAT_IMPLICIT, FORMAT_JAVA_SERIALIZED, FORMAT_LENGTH_HEADER, FORMAT_STX_ETX, STX
 
Constructor Summary
NioSocketReader(SocketChannel channel)
          Constructs an NioSocketReader which reads from 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.
protected  int assembleDataCrLfFormat()
          Assembles data in format MessageFormats.FORMAT_CRLF.
protected  int assembleDataCustomFormat()
          Throws UnsupportedOperationException; custom implementations can subclass this class and provide an implementation.
 int assembleDataLengthFormat()
          Assembles data in format MessageFormats.FORMAT_LENGTH_HEADER.
protected  int assembleDataSerializedFormat()
          Throws UnsupportedOperationException; Java serialization is currently only supported using the NetSocketReader.
protected  int assembleDataStxEtxFormat()
          Assembles data in format MessageFormats.FORMAT_STX_ETX.
protected  void doClose()
          Called after an exception; close the transport.
 InetAddress getAddress()
          Returns the InetAddress of the underlying socket.
 Socket getSocket()
           
 boolean isUsingDirectBuffers()
           
protected  int readChannel(ByteBuffer buffer)
          Reads from the channel into the buffer.
protected  int readChannelNonDeterministic()
          Reads data into the rawBuffer for non-deterministic algorithms.
 void setUsingDirectBuffers(boolean usingDirectBuffers)
           
 
Methods inherited from class org.springframework.integration.ip.tcp.AbstractSocketReader
assembleData, getAssembledData, setMaxMessageSize, setMessageFormat
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final org.apache.commons.logging.Log logger

channel

protected SocketChannel channel

usingDirectBuffers

protected boolean usingDirectBuffers

lengthPart

protected ByteBuffer lengthPart

dataPart

protected ByteBuffer dataPart

rawBuffer

protected ByteBuffer rawBuffer

buildBuffer

protected ByteBuffer buildBuffer

building

protected boolean building
Constructor Detail

NioSocketReader

public NioSocketReader(SocketChannel channel)
Constructs an NioSocketReader which reads from the SocketChannel.

Parameters:
channel - The channel.
Method Detail

assembleDataLengthFormat

public int assembleDataLengthFormat()
                             throws IOException
Description copied from class: AbstractSocketReader
Assembles data in format MessageFormats.FORMAT_LENGTH_HEADER.

Specified by:
assembleDataLengthFormat in class AbstractSocketReader
Returns:
SocketReader.MESSAGE_COMPLETE when message is assembled, otherwise SocketReader.MESSAGE_IMCOMPLETE, or < 0 if socket closed before any data for a message is received.
Throws:
IOException

assembleDataStxEtxFormat

protected int assembleDataStxEtxFormat()
                                throws IOException
Description copied from class: AbstractSocketReader
Assembles data in format MessageFormats.FORMAT_STX_ETX.

Specified by:
assembleDataStxEtxFormat in class AbstractSocketReader
Returns:
SocketReader.MESSAGE_COMPLETE when message is assembled, otherwise SocketReader.MESSAGE_IMCOMPLETE, or < 0 if socket closed before any data for a message is received.
Throws:
IOException

assembleDataCrLfFormat

protected int assembleDataCrLfFormat()
                              throws IOException
Description copied from class: AbstractSocketReader
Assembles data in format MessageFormats.FORMAT_CRLF.

Specified by:
assembleDataCrLfFormat in class AbstractSocketReader
Returns:
SocketReader.MESSAGE_COMPLETE when message is assembled, otherwise SocketReader.MESSAGE_IMCOMPLETE, or < 0 if socket closed before any data for a message is received.
Throws:
IOException

assembleDataSerializedFormat

protected int assembleDataSerializedFormat()
                                    throws IOException
Throws UnsupportedOperationException; Java serialization is currently only supported using the NetSocketReader.

Specified by:
assembleDataSerializedFormat in class AbstractSocketReader
Returns:
SocketReader.MESSAGE_COMPLETE when message is assembled, otherwise SocketReader.MESSAGE_IMCOMPLETE, or < 0 if socket closed before any data for a message is received.
Throws:
IOException
See Also:
AbstractSocketReader.assembleDataCustomFormat()

assembleDataCustomFormat

protected int assembleDataCustomFormat()
                                throws IOException
Throws UnsupportedOperationException; custom implementations can subclass this class and provide an implementation.

Specified by:
assembleDataCustomFormat in class AbstractSocketReader
Returns:
True when a message is completely assembled.
Throws:
IOException
See Also:
AbstractSocketReader.assembleDataCustomFormat()

readChannel

protected int readChannel(ByteBuffer buffer)
                   throws IOException
Reads from the channel into the buffer. Reads as much data as is currently available in the channel.

Parameters:
buffer -
Throws:
IOException

readChannelNonDeterministic

protected int readChannelNonDeterministic()
                                   throws IOException
Reads data into the rawBuffer for non-deterministic algorithms.

Returns:
bytes remaining in raw buffer or < 0 if channel closed
Throws:
IOException

allocate

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


doClose

protected void doClose()
Description copied from class: AbstractSocketReader
Called after an exception; close the transport.

Specified by:
doClose in class AbstractSocketReader

getAddress

public InetAddress getAddress()
Description copied from interface: SocketReader
Returns the InetAddress of the underlying socket.

Returns:
The InetAddress.

isUsingDirectBuffers

public boolean isUsingDirectBuffers()

setUsingDirectBuffers

public void setUsingDirectBuffers(boolean usingDirectBuffers)
Parameters:
usingDirectBuffers - the usingDirectBuffers to set

getSocket

public Socket getSocket()
Returns:
the Socket

Spring Integration

Copyright © 2010. All Rights Reserved.