Sun Java(tm) System Message Queue
v4.1

com.sun.messaging.jmq.io
Class ReadOnlyPacket

java.lang.Object
  extended by com.sun.messaging.jmq.io.ReadOnlyPacket
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
ReadWritePacket

public class ReadOnlyPacket
extends Object
implements Cloneable

This class is a mostly immutable encapsulation of a JMQ packet. It is only "mostly" immutable because it can be modified by calling the readPacket() method which modifies the state of the object to reflect the packet just read. WARNING! This class emphasizes performance over safety. In particular the readPacket() method is NOT synchronized. You must only call readPacket() in a single threaded environment (or do the synchronization yourself). Once the object is initialized via a readPacket() you can safely use the accessors and the writePacket() methods in a multi-threaded envornment.


Field Summary
protected  int bitFlags
           
protected  long consumerID
           
protected  String correlationID
           
static short defaultVersion
           
protected  String destination
           
protected  String destinationClass
           
protected  int encryption
           
protected  long expiration
           
protected static int HEADER_SIZE
           
protected  byte[] headerBuffer
           
protected  int magic
           
static int MAGIC
           
protected  String messageID
           
protected  String messageType
           
protected  int packetSize
           
protected  int packetType
           
protected  int priority
           
protected  long producerID
           
protected  Hashtable properties
           
protected  int propertyOffset
           
protected  int propertySize
           
protected  String replyTo
           
protected  String replyToClass
           
protected  byte[] ropBuffer
           
protected  int ropLength
           
protected  boolean stringsParsed
           
protected  SysMessageID sysMessageID
           
protected  long transactionID
           
protected  int version
           
static short VERSION1
           
static short VERSION2
           
static short VERSION3
           
 
Constructor Summary
ReadOnlyPacket()
           
 
Method Summary
 Object clone()
          Make a deep copy of this packet.
 Object cloneShallow()
          Make a shallow copy of this packet.
 void dump(PrintStream os)
          Dump the contents of the packet in human readable form to the specified OutputStream.
 boolean getConsumerFlow()
           
 long getConsumerID()
           
 String getCorrelationID()
           
 String getDestination()
           
 String getDestinationClass()
           
 int getEncryption()
           
 long getExpiration()
           
 boolean getFlag(int flag)
           
 boolean getFlowPaused()
           
 boolean getIndempotent()
           
 int getInterestID()
           
 byte[] getIP()
           
 String getIPString()
           
 boolean getIsLast()
           
 boolean getIsQueue()
           
 boolean getIsTransacted()
           
 int getMagic()
           
 int getMessageBodySize()
          Return the size of the message body in bytes
 InputStream getMessageBodyStream()
          Return an InputStream that contains the contents of the message body.
 String getMessageID()
          Get the MessageID for the packet.
 String getMessageType()
           
 int getPacketSize()
           
 int getPacketType()
           
 boolean getPersistent()
           
 int getPort()
           
 int getPriority()
           
 long getProducerID()
           
 Hashtable getProperties()
          Return the property hashtable for this packet.
 int getPropertyOffset()
           
 int getPropertySize()
           
 boolean getRedelivered()
           
 String getReplyTo()
           
 String getReplyToClass()
           
 boolean getSelectorsProcessed()
           
 boolean getSendAcknowledge()
           
 int getSequence()
           
 SysMessageID getSysMessageID()
          Get the system message ID.
 long getTimestamp()
           
 long getTransactionID()
           
 int getVersion()
           
 boolean isEqual(SysMessageID id)
          Check if this packet matches the specified system message id.
 void readPacket(InputStream is)
          Read packet from an InputStream.
protected  void reset()
          Reset packet to initial values
 void retryReadPacket(InputStream is)
          Attempt to complete the reading of a packet.
static void setDefaultVersion(short version)
          this method MUST be called before a packet is created
 String toString()
          Return a unique string that identifies the packet
 String toVerboseString()
          Return a string containing the contents of the packet in a human readable form.
 void writePacket(OutputStream os)
          Write the packet to an OutputStream
 void writePacket(OutputStream os, int new_version)
          Write the packet to an OutputStream
 void writePacket(OutputStream os, int new_version, long new_consumerID, boolean new_pauseFlow, boolean new_redelivered, boolean new_lastPkt)
          Write the packet to an OutputStream with some modified fields.
 void writePacket(OutputStream os, long new_consumerID, boolean new_pauseFlow, boolean new_redelivered, boolean new_lastPkt)
          Write the packet to an OutputStream with some modified fields.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAGIC

public static final int MAGIC
See Also:
Constant Field Values

VERSION1

public static final short VERSION1
See Also:
Constant Field Values

VERSION2

public static final short VERSION2
See Also:
Constant Field Values

VERSION3

public static final short VERSION3
See Also:
Constant Field Values

defaultVersion

public static short defaultVersion

HEADER_SIZE

protected static final int HEADER_SIZE
See Also:
Constant Field Values

headerBuffer

protected byte[] headerBuffer

ropBuffer

protected byte[] ropBuffer

ropLength

protected int ropLength

version

protected int version

magic

protected int magic

packetType

protected int packetType

packetSize

protected int packetSize

expiration

protected long expiration

propertyOffset

protected int propertyOffset

propertySize

protected int propertySize

encryption

protected int encryption

transactionID

protected long transactionID

priority

protected int priority

bitFlags

protected int bitFlags

consumerID

protected long consumerID

sysMessageID

protected SysMessageID sysMessageID

destination

protected String destination

destinationClass

protected String destinationClass

messageID

protected String messageID

correlationID

protected String correlationID

replyTo

protected String replyTo

replyToClass

protected String replyToClass

messageType

protected String messageType

producerID

protected long producerID

stringsParsed

protected boolean stringsParsed

properties

protected Hashtable properties
Constructor Detail

ReadOnlyPacket

public ReadOnlyPacket()
Method Detail

setDefaultVersion

public static void setDefaultVersion(short version)
this method MUST be called before a packet is created


readPacket

public void readPacket(InputStream is)
                throws IOException,
                       EOFException,
                       StreamCorruptedException,
                       IllegalArgumentException
Read packet from an InputStream. This method reads one packet from the InputStream and sets the state of this object to reflect the packet read. This method is not synchronized and should only be called by non-concurrent code. If we read a packet with a bad magic number (ie it looks like bogus data), we give up and throw a StreamCorruptedException. If we read a packet that does not match our packet version we attempt to swallow the packet and then throw an IllegalArgumentException. If this method throws an OutOfMemoryError, the caller can try to free memory and call retryReadPacket().

Parameters:
is - the InputStream to read the packet from
Throws:
IOException
EOFException
StreamCorruptedException
IllegalArgumentException

retryReadPacket

public void retryReadPacket(InputStream is)
                     throws IOException,
                            EOFException,
                            StreamCorruptedException,
                            IllegalArgumentException
Attempt to complete the reading of a packet. This is of limited usefulness. It depends on the fixed portion of a packet having been read successfully already. In practice this method should only be used if readPacket() throws an OutOfMemoryError() and the caller has freed some memory and wants to try completing the read of the packet.

Throws:
IOException
EOFException
StreamCorruptedException
IllegalArgumentException

getFlag

public boolean getFlag(int flag)

writePacket

public void writePacket(OutputStream os)
                 throws IOException
Write the packet to an OutputStream

Parameters:
os - The OutputStream to write the packet to
Throws:
IOException

writePacket

public void writePacket(OutputStream os,
                        int new_version)
                 throws IOException
Write the packet to an OutputStream

Parameters:
os - The OutputStream to write the packet to
Throws:
IOException

writePacket

public void writePacket(OutputStream os,
                        long new_consumerID,
                        boolean new_pauseFlow,
                        boolean new_redelivered,
                        boolean new_lastPkt)
                 throws IOException
Write the packet to an OutputStream with some modified fields.

Parameters:
os - The OutputStream to write the packet to
new_consumerID - New value for the consumerID
new_pauseFlow - New value for the pause flow flag (F bit)
new_redelivered - New value for the redelivered flag (R bit)
new_lastPkt - New value for the last message flag (L bit)
Throws:
IOException

writePacket

public void writePacket(OutputStream os,
                        int new_version,
                        long new_consumerID,
                        boolean new_pauseFlow,
                        boolean new_redelivered,
                        boolean new_lastPkt)
                 throws IOException
Write the packet to an OutputStream with some modified fields.

Parameters:
os - The OutputStream to write the packet to
new_version - New version value
new_consumerID - New value for the consumerID
new_pauseFlow - New value for the pause flow flag (F bit)
new_redelivered - New value for the redelivered flag (R bit)
new_lastPkt - New value for the last message flag (L bit)
Throws:
IOException

isEqual

public boolean isEqual(SysMessageID id)
Check if this packet matches the specified system message id.

Returns:
"true" if the packet matches the specified id, else "false"

getVersion

public int getVersion()

getMagic

public int getMagic()

getPacketType

public int getPacketType()

getPacketSize

public int getPacketSize()

getTimestamp

public long getTimestamp()

getExpiration

public long getExpiration()

getPort

public int getPort()

getIPString

public String getIPString()

getIP

public byte[] getIP()

getSequence

public int getSequence()

getPropertyOffset

public int getPropertyOffset()

getPropertySize

public int getPropertySize()

getEncryption

public int getEncryption()

getPriority

public int getPriority()

getTransactionID

public long getTransactionID()

getProducerID

public long getProducerID()

getConsumerID

public long getConsumerID()

getInterestID

public int getInterestID()

getPersistent

public boolean getPersistent()

getRedelivered

public boolean getRedelivered()

getIsQueue

public boolean getIsQueue()

getSelectorsProcessed

public boolean getSelectorsProcessed()

getSendAcknowledge

public boolean getSendAcknowledge()

getIsLast

public boolean getIsLast()

getFlowPaused

public boolean getFlowPaused()

getIsTransacted

public boolean getIsTransacted()

getConsumerFlow

public boolean getConsumerFlow()

getIndempotent

public boolean getIndempotent()

getDestination

public String getDestination()

getDestinationClass

public String getDestinationClass()

getMessageID

public String getMessageID()
Get the MessageID for the packet. If the client has set a MessageID then that is what is returned. Otherwise the system message ID is returned (see getSysMessageID())

Returns:
The packet's MessageID

getCorrelationID

public String getCorrelationID()

getReplyTo

public String getReplyTo()

getReplyToClass

public String getReplyToClass()

getMessageType

public String getMessageType()

getSysMessageID

public SysMessageID getSysMessageID()
Get the system message ID. Note that this is not the JMS MessageID set by the client. Rather this is a system-wide unique message ID generated from the timestamp, sequence number, port number and IP address of the packet.

WARNING! This returns a references to the Packet's SysMessageID not a copy.

Returns:
The packet's system MessageID

getMessageBodySize

public int getMessageBodySize()
Return the size of the message body in bytes

Returns:
Size of message body in bytes

getMessageBodyStream

public InputStream getMessageBodyStream()
Return an InputStream that contains the contents of the message body.

Returns:
An InputStream from which the message body can be read from. Or null if no message body.

getProperties

public Hashtable getProperties()
                        throws IOException,
                               ClassNotFoundException
Return the property hashtable for this packet. WARNING! This method emphasizes performance over safety. The HashTable object returned is a reference to the HashTable object in the object -- it is NOT a copy. Modifying the contents of the HashTable will have non-deterministic results so don't do it!

Throws:
IOException
ClassNotFoundException

reset

protected void reset()
Reset packet to initial values


cloneShallow

public Object cloneShallow()
Make a shallow copy of this packet. Warning! This does not copy any of the internal buffers.


clone

public Object clone()
Make a deep copy of this packet. This will be slow.

Overrides:
clone in class Object

toString

public String toString()
Return a unique string that identifies the packet

Overrides:
toString in class Object

toVerboseString

public String toVerboseString()
Return a string containing the contents of the packet in a human readable form.


dump

public void dump(PrintStream os)
Dump the contents of the packet in human readable form to the specified OutputStream.

Parameters:
os - OutputStream to write packet contents to

Sun Java(tm) System Message Queue
v4.1

Copyright 2006 Sun Microsystems, Inc. 4150 Network Circle,
Santa Clara, California, 95054, U.S.A. All Rights Reserved.