org.mule.providers.tcp.protocols
Class LengthProtocol

java.lang.Object
  extended by org.mule.providers.tcp.protocols.ByteProtocol
      extended by org.mule.providers.tcp.protocols.DefaultProtocol
          extended by org.mule.providers.tcp.protocols.LengthProtocol
All Implemented Interfaces:
TcpProtocol
Direct Known Subclasses:
MuleMessageLengthProtocol

public class LengthProtocol
extends DefaultProtocol

The LengthProtocol is an application level tcp protocol that can be used to transfer large amounts of data without risking some data to be loss. The protocol is defined by sending / reading an integer (the packet length) and then the data to be transferred.

Note that use of this protocol must be symmetric - both the sending and receiving connectors must use the same protocol.


Field Summary
 
Fields inherited from class org.mule.providers.tcp.protocols.ByteProtocol
EOF, NO_STREAM, STREAM_OK
 
Constructor Summary
LengthProtocol()
           
 
Method Summary
protected  boolean isRepeat(int len, int available)
          Read all four bytes for initial integer (limit is set in read)
 Object read(InputStream is)
          Reads the input stream and returns a whole message.
protected  void writeByteArray(OutputStream os, byte[] data)
           
 
Methods inherited from class org.mule.providers.tcp.protocols.DefaultProtocol
read
 
Methods inherited from class org.mule.providers.tcp.protocols.ByteProtocol
copy, copy, nullEmptyArray, safeRead, safeRead, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LengthProtocol

public LengthProtocol()
Method Detail

read

public Object read(InputStream is)
            throws IOException
Description copied from interface: TcpProtocol
Reads the input stream and returns a whole message.

Specified by:
read in interface TcpProtocol
Overrides:
read in class DefaultProtocol
Parameters:
is - the input stream
Returns:
an array of byte containing a full message
Throws:
IOException - if an exception occurs

writeByteArray

protected void writeByteArray(OutputStream os,
                              byte[] data)
                       throws IOException
Overrides:
writeByteArray in class ByteProtocol
Throws:
IOException

isRepeat

protected boolean isRepeat(int len,
                           int available)
Read all four bytes for initial integer (limit is set in read)

Overrides:
isRepeat in class DefaultProtocol
Parameters:
len - Amount transferred last call (-1 on EOF or socket error)
available - Amount available
Returns:
true if the transfer should continue


Copyright © 2003-2008 MuleSource, Inc.. All Rights Reserved.