org.activemq.io
Interface WireFormat

All Known Implementing Classes:
AbstractDefaultWireFormat, AbstractWireFormat, DefaultWireFormat, JabberWireFormat, StatelessDefaultWireFormat, StompWireFormat, TextWireFormat

public interface WireFormat

Represents a strategy of encoding packets on the wire or on disk using some kind of serialization or wire format.

We use a default efficient format for Java to Java communication but other formats to other systems can be used, such as using simple text strings when talking to JavaScript or coming up with other formats for talking to C / C# languages or proprietary messaging systems we wish to interface with at the wire level etc.

Version:
$Revision: 1.1.1.1 $

Field Summary
static int DEFAULT_MAXIMUM_MESSAGE_SIZE
          The maximum message size supported by the transport If the message is bigger than this size, then the message will be 'chunked' into separate pieces and re-assembled on the consumer
 
Method Summary
 boolean canProcessWireFormatVersion(int version)
          Can this wireformat process packets of this version
 WireFormat copy()
          Creates a new copy of this wire format so it can be used in another thread/context
 boolean doesSupportMessageCompression()
          Some wire formats will not be able to understand compressed messages
 boolean doesSupportMessageFragmentation()
          some wire formats will implement their own fragementation
 Packet fromBytes(byte[] bytes)
          Reads the packet from the given byte[]
 Packet fromBytes(byte[] bytes, int offset, int length)
          Reads the packet from the given byte[]
 int getCurrentWireFormatVersion()
           
 void initiateClientSideProtocol()
          Some wire formats require a handshake at start-up
 void initiateServerSideProtocol()
          Some wire formats require a handshake at start-up
 boolean isCachingEnabled()
           
 Packet readPacket(DataInput in)
          Reads a packet from the given input stream
 Packet readPacket(int firstByte, DataInput in)
          A helper method for working with sockets where the first byte is read first, then the rest of the message is read.
 Packet readPacket(String channelID, DatagramPacket dpacket)
          Read a packet from a Datagram packet from the given channelID.
 void registerTransportStreams(DataOutputStream dataOut, DataInputStream dataIn)
          some transports may register their streams (e.g.
 void setCachingEnabled(boolean enableCaching)
           
 byte[] toBytes(Packet packet)
          A helper method which converts a packet into a byte array
 Packet writePacket(Packet packet, DataOutput out)
          Writes the packet to the given output stream
 DatagramPacket writePacket(String channelID, Packet packet)
          Writes the given package to a new datagram
 

Field Detail

DEFAULT_MAXIMUM_MESSAGE_SIZE

static final int DEFAULT_MAXIMUM_MESSAGE_SIZE
The maximum message size supported by the transport If the message is bigger than this size, then the message will be 'chunked' into separate pieces and re-assembled on the consumer

See Also:
Constant Field Values
Method Detail

readPacket

Packet readPacket(DataInput in)
                  throws IOException
Reads a packet from the given input stream

Parameters:
in -
Returns:
Throws:
IOException

readPacket

Packet readPacket(int firstByte,
                  DataInput in)
                  throws IOException
A helper method for working with sockets where the first byte is read first, then the rest of the message is read.

Its common when dealing with sockets to have different timeout semantics until the first non-zero byte is read of a message, after which time a zero timeout is used.

Parameters:
firstByte - the first byte of the packet
in - the rest of the packet
Returns:
Throws:
IOException

readPacket

Packet readPacket(String channelID,
                  DatagramPacket dpacket)
                  throws IOException
Read a packet from a Datagram packet from the given channelID. If the packet is from the same channel ID as it was sent then we have a loop-back so discard the packet

Parameters:
channelID - is the unique channel ID
dpacket -
Returns:
the packet read from the datagram or null if it should be discarded
Throws:
IOException

writePacket

Packet writePacket(Packet packet,
                   DataOutput out)
                   throws IOException,
                          JMSException
Writes the packet to the given output stream

Parameters:
packet -
out -
Returns:
a response packet - or null
Throws:
IOException
JMSException

writePacket

DatagramPacket writePacket(String channelID,
                           Packet packet)
                           throws IOException,
                                  JMSException
Writes the given package to a new datagram

Parameters:
channelID - is the unique channel ID
packet - is the packet to write
Returns:
Throws:
IOException
JMSException

fromBytes

Packet fromBytes(byte[] bytes,
                 int offset,
                 int length)
                 throws IOException
Reads the packet from the given byte[]

Parameters:
bytes -
offset -
length -
Returns:
Throws:
IOException

fromBytes

Packet fromBytes(byte[] bytes)
                 throws IOException
Reads the packet from the given byte[]

Parameters:
bytes -
Returns:
Throws:
IOException

toBytes

byte[] toBytes(Packet packet)
               throws IOException,
                      JMSException
A helper method which converts a packet into a byte array

Parameters:
packet -
Returns:
a byte array representing the packet using some wire protocol
Throws:
IOException
JMSException

copy

WireFormat copy()
Creates a new copy of this wire format so it can be used in another thread/context

Returns:

canProcessWireFormatVersion

boolean canProcessWireFormatVersion(int version)
Can this wireformat process packets of this version

Parameters:
version - the version number to test
Returns:
true if can accept the version

getCurrentWireFormatVersion

int getCurrentWireFormatVersion()
Returns:
the current version of this wire format

registerTransportStreams

void registerTransportStreams(DataOutputStream dataOut,
                              DataInputStream dataIn)
some transports may register their streams (e.g. Tcp)

Parameters:
dataOut -
dataIn -

initiateClientSideProtocol

void initiateClientSideProtocol()
                                throws IOException
Some wire formats require a handshake at start-up

Throws:
IOException

initiateServerSideProtocol

void initiateServerSideProtocol()
                                throws IOException
Some wire formats require a handshake at start-up

Throws:
IOException

isCachingEnabled

boolean isCachingEnabled()
Returns:
Returns the enableCaching.

setCachingEnabled

void setCachingEnabled(boolean enableCaching)
Parameters:
enableCaching - The enableCaching to set.

doesSupportMessageFragmentation

boolean doesSupportMessageFragmentation()
some wire formats will implement their own fragementation

Returns:
true unless a wire format supports it's own fragmentation

doesSupportMessageCompression

boolean doesSupportMessageCompression()
Some wire formats will not be able to understand compressed messages

Returns:
true unless a wire format cannot understand compression


Copyright © 2004-2010 Protique, Ltd.. All Rights Reserved.