org.activemq.io
Class AbstractWireFormat

java.lang.Object
  extended by org.activemq.io.AbstractWireFormat
All Implemented Interfaces:
WireFormat
Direct Known Subclasses:
AbstractDefaultWireFormat, JabberWireFormat, TextWireFormat

public abstract class AbstractWireFormat
extends Object
implements 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
protected  boolean cachingEnabled
           
protected  DataInputStream transportDataIn
           
protected  DataOutputStream transportDataOut
           
 
Fields inherited from interface org.activemq.io.WireFormat
DEFAULT_MAXIMUM_MESSAGE_SIZE
 
Constructor Summary
AbstractWireFormat()
           
 
Method Summary
 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[]
 DataInputStream getTransportDataIn()
           
 DataOutputStream getTransportDataOut()
           
 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 dataIn)
          Reads a packet from the given input stream
 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)
           
 void setTransportDataIn(DataInputStream transportDataIn)
           
 void setTransportDataOut(DataOutputStream transportDataOut)
           
 byte[] toBytes(Packet packet)
          A helper method which converts a packet into a byte array
 DatagramPacket writePacket(String channelID, Packet packet)
          Writes the given package to a new datagram
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.activemq.io.WireFormat
canProcessWireFormatVersion, copy, getCurrentWireFormatVersion, readPacket, writePacket
 

Field Detail

transportDataOut

protected DataOutputStream transportDataOut

transportDataIn

protected DataInputStream transportDataIn

cachingEnabled

protected boolean cachingEnabled
Constructor Detail

AbstractWireFormat

public AbstractWireFormat()
Method Detail

readPacket

public 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

Specified by:
readPacket in interface WireFormat
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

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

Specified by:
writePacket in interface WireFormat
Parameters:
channelID - is the unique channel ID
packet - is the packet to write
Returns:
@throws IOException
Throws:
JMSException
IOException

fromBytes

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

Specified by:
fromBytes in interface WireFormat
Parameters:
bytes -
offset -
length -
Returns:
@throws IOException
Throws:
IOException

fromBytes

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

Specified by:
fromBytes in interface WireFormat
Parameters:
bytes -
Returns:
@throws IOException
Throws:
IOException

toBytes

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

Specified by:
toBytes in interface WireFormat
Parameters:
packet -
Returns:
a byte array representing the packet using some wire protocol
Throws:
IOException
JMSException

registerTransportStreams

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

Specified by:
registerTransportStreams in interface WireFormat
Parameters:
dataOut -
dataIn -

initiateClientSideProtocol

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

Specified by:
initiateClientSideProtocol in interface WireFormat
Throws:
IOException

initiateServerSideProtocol

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

Specified by:
initiateServerSideProtocol in interface WireFormat
Throws:
IOException

isCachingEnabled

public boolean isCachingEnabled()
Specified by:
isCachingEnabled in interface WireFormat
Returns:
Returns the enableCaching.

setCachingEnabled

public void setCachingEnabled(boolean enableCaching)
Specified by:
setCachingEnabled in interface WireFormat
Parameters:
enableCaching - The enableCaching to set.

doesSupportMessageFragmentation

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

Specified by:
doesSupportMessageFragmentation in interface WireFormat
Returns:
true unless a wire format supports it's own fragmentation

doesSupportMessageCompression

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

Specified by:
doesSupportMessageCompression in interface WireFormat
Returns:
true unless a wire format cannot understand compression

getTransportDataOut

public DataOutputStream getTransportDataOut()
Returns:
Returns the transportDataOut.

setTransportDataOut

public void setTransportDataOut(DataOutputStream transportDataOut)
Parameters:
transportDataOut - The transportDataOut to set.

getTransportDataIn

public DataInputStream getTransportDataIn()
Returns:
Returns the transportDataIn.

setTransportDataIn

public void setTransportDataIn(DataInputStream transportDataIn)
Parameters:
transportDataIn - The transportDataIn to set.

readPacket

public Packet readPacket(DataInput dataIn)
                  throws IOException
Description copied from interface: WireFormat
Reads a packet from the given input stream

Specified by:
readPacket in interface WireFormat
Parameters:
dataIn -
Returns:
Throws:
IOException


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