Spring Integration

org.springframework.integration.ip.tcp
Class AbstractSocketWriter

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

public abstract class AbstractSocketWriter
extends Object
implements SocketWriter, MessageFormats

Abstract SocketWriter that handles data in 3 standard, and one custom format. The default format is MessageFormats.FORMAT_LENGTH_HEADER in which the message consists of a 4 byte integer (in network byte order) containing the length of data that follows. MessageFormats.FORMAT_STX_ETX indicates a message where the data begins with STX (0x02) and ends with ETX (0x03); the STX and ETX are not part of the data. MessageFormats.FORMAT_CRLF indicates a message followed by carriage return and line feed '\r\n'. FORMAT_LENGTH_HEADER can be used for Socket and SocketChannel implementations are provided for the standard formats. Users requiring other formats should subclass the appropriate implementation, and provide an implementation for writeCustomFormat(Object) which is invoked by write(Object) when the format is MessageFormats.FORMAT_CUSTOM.

Since:
2.0
Author:
Gary Russell

Field Summary
protected  org.apache.commons.logging.Log logger
           
protected  int 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
AbstractSocketWriter()
           
 
Method Summary
protected abstract  void doClose()
          Called when an IO error
 void setMessageFormat(int messageFormat)
           
 void write(Object object)
          Write the entire buffer to the underlying socket.
protected abstract  void writeCrLfFormat(byte[] bytes)
          Write the data, followed by carriage return, line feed ('\r\n').
protected abstract  void writeCustomFormat(Object object)
          Write the data using some custom protocol.
protected abstract  void writeLengthFormat(byte[] bytes)
          Write the length of the data in a 4 byte integer (in network byte order) before the data itself.
protected abstract  void writeSerializedFormat(Object object)
          Write the data, followed by carriage return, line feed ('\r\n').
protected abstract  void writeStxEtxFormat(byte[] bytes)
          Write an STX (0x02) followed by the data, followed by ETX (0x03).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

messageFormat

protected int messageFormat

logger

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

AbstractSocketWriter

public AbstractSocketWriter()
Method Detail

write

public void write(Object object)
           throws IOException
Description copied from interface: SocketWriter
Write the entire buffer to the underlying socket. Appropriate wire protocols will be implemented so the receiving side can decode and reassemble the message, if packetized by the network.

Specified by:
write in interface SocketWriter
Parameters:
object - The object to write.
Throws:
IOException

doClose

protected abstract void doClose()
Called when an IO error


writeLengthFormat

protected abstract void writeLengthFormat(byte[] bytes)
                                   throws IOException
Write the length of the data in a 4 byte integer (in network byte order) before the data itself.

Parameters:
bytes - The bytes to write.
Throws:
IOException

writeStxEtxFormat

protected abstract void writeStxEtxFormat(byte[] bytes)
                                   throws IOException
Write an STX (0x02) followed by the data, followed by ETX (0x03).

Parameters:
bytes - The bytes to write.
Throws:
IOException

writeCrLfFormat

protected abstract void writeCrLfFormat(byte[] bytes)
                                 throws IOException
Write the data, followed by carriage return, line feed ('\r\n').

Throws:
IOException

writeSerializedFormat

protected abstract void writeSerializedFormat(Object object)
                                       throws IOException
Write the data, followed by carriage return, line feed ('\r\n').

Throws:
IOException

writeCustomFormat

protected abstract void writeCustomFormat(Object object)
                                   throws IOException
Write the data using some custom protocol.

Throws:
IOException

setMessageFormat

public void setMessageFormat(int messageFormat)
Specified by:
setMessageFormat in interface SocketWriter
Parameters:
messageFormat - the messageFormat to set

Spring Integration

Copyright © 2010. All Rights Reserved.