Spring Integration

org.springframework.integration.ip.tcp
Class NioSocketWriter

java.lang.Object
  extended by org.springframework.integration.ip.tcp.AbstractSocketWriter
      extended by org.springframework.integration.ip.tcp.NioSocketWriter
All Implemented Interfaces:
MessageFormats, SocketWriter

public class NioSocketWriter
extends AbstractSocketWriter

A SocketWriter that writes to a SocketChannel. The data is wrapped in a wire protocol based on the messageFormat property.

Since:
2.0
Author:
Gary Russell

Field Summary
protected  int bufferCount
           
protected  BlockingQueue<ByteBuffer> buffers
          If we are using direct buffers, we don't want to churn them using normal heap management.
protected  SocketChannel channel
           
protected  ByteBuffer crLfPart
          A buffer containing the CRLF for when the messageFormat is MessageFormats.FORMAT_CRLF.
protected  ByteBuffer etxPart
          A buffer containing the ETX for when the messageFormat is MessageFormats.FORMAT_STX_ETX.
protected  ByteBuffer lengthPart
          A buffer containing the length part when the messageFormat is MessageFormats.FORMAT_LENGTH_HEADER.
protected  int maxBuffers
           
protected  ByteBuffer stxPart
          A buffer containing the STX for when the messageFormat is MessageFormats.FORMAT_STX_ETX.
protected  boolean usingDirectBuffers
          If true, direct buffers are used.
 
Fields inherited from class org.springframework.integration.ip.tcp.AbstractSocketWriter
logger, messageFormat
 
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
NioSocketWriter(SocketChannel channel, int maxBuffers, int sendBufferSize)
           
 
Method Summary
protected  void doClose()
          Called when an IO error
protected  ByteBuffer getBuffer()
           
protected  void returnBuffer(ByteBuffer buffer)
           
 void setUsingDirectBuffers(boolean usingDirectBuffers)
           
protected  void writeCrLfFormat(byte[] bytes)
          Write the data, followed by carriage return, line feed ('\r\n').
protected  void writeCustomFormat(Object object)
          Write the data using some custom protocol.
protected  void writeLengthFormat(byte[] bytes)
          Write the length of the data in a 4 byte integer (in network byte order) before the data itself.
protected  void writeSerializedFormat(Object object)
          Write the data, followed by carriage return, line feed ('\r\n').
protected  void writeStxEtxFormat(byte[] bytes)
          Write an STX (0x02) followed by the data, followed by ETX (0x03).
 
Methods inherited from class org.springframework.integration.ip.tcp.AbstractSocketWriter
setMessageFormat, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

channel

protected SocketChannel channel

usingDirectBuffers

protected boolean usingDirectBuffers
If true, direct buffers are used.

See Also:
for more information

lengthPart

protected ByteBuffer lengthPart
A buffer containing the length part when the messageFormat is MessageFormats.FORMAT_LENGTH_HEADER.


stxPart

protected ByteBuffer stxPart
A buffer containing the STX for when the messageFormat is MessageFormats.FORMAT_STX_ETX.


etxPart

protected ByteBuffer etxPart
A buffer containing the ETX for when the messageFormat is MessageFormats.FORMAT_STX_ETX.


crLfPart

protected ByteBuffer crLfPart
A buffer containing the CRLF for when the messageFormat is MessageFormats.FORMAT_CRLF.


buffers

protected BlockingQueue<ByteBuffer> buffers
If we are using direct buffers, we don't want to churn them using normal heap management. But, because we can have multiple threads writing and we might write in chunks, we need a dedicated buffer for each thread; up to a limit. We handle this with a blocking queue.


maxBuffers

protected int maxBuffers

bufferCount

protected int bufferCount
Constructor Detail

NioSocketWriter

public NioSocketWriter(SocketChannel channel,
                       int maxBuffers,
                       int sendBufferSize)
Method Detail

setUsingDirectBuffers

public void setUsingDirectBuffers(boolean usingDirectBuffers)
Parameters:
usingDirectBuffers - whether direct buffers are to be used

getBuffer

protected ByteBuffer getBuffer()
                        throws InterruptedException
Throws:
InterruptedException

returnBuffer

protected void returnBuffer(ByteBuffer buffer)

writeCrLfFormat

protected void writeCrLfFormat(byte[] bytes)
                        throws IOException
Description copied from class: AbstractSocketWriter
Write the data, followed by carriage return, line feed ('\r\n').

Specified by:
writeCrLfFormat in class AbstractSocketWriter
Throws:
IOException

writeSerializedFormat

protected void writeSerializedFormat(Object object)
                              throws IOException
Description copied from class: AbstractSocketWriter
Write the data, followed by carriage return, line feed ('\r\n').

Specified by:
writeSerializedFormat in class AbstractSocketWriter
Throws:
IOException

writeCustomFormat

protected void writeCustomFormat(Object object)
                          throws IOException
Description copied from class: AbstractSocketWriter
Write the data using some custom protocol.

Specified by:
writeCustomFormat in class AbstractSocketWriter
Throws:
IOException

writeLengthFormat

protected void writeLengthFormat(byte[] bytes)
                          throws IOException
Description copied from class: AbstractSocketWriter
Write the length of the data in a 4 byte integer (in network byte order) before the data itself.

Specified by:
writeLengthFormat in class AbstractSocketWriter
Parameters:
bytes - The bytes to write.
Throws:
IOException

writeStxEtxFormat

protected void writeStxEtxFormat(byte[] bytes)
                          throws IOException
Description copied from class: AbstractSocketWriter
Write an STX (0x02) followed by the data, followed by ETX (0x03).

Specified by:
writeStxEtxFormat in class AbstractSocketWriter
Parameters:
bytes - The bytes to write.
Throws:
IOException

doClose

protected void doClose()
Description copied from class: AbstractSocketWriter
Called when an IO error

Specified by:
doClose in class AbstractSocketWriter

Spring Integration

Copyright © 2010. All Rights Reserved.