Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.activemq.message
Class ActiveMQStreamMessage  view ActiveMQStreamMessage download ActiveMQStreamMessage.java

java.lang.Object
  extended byorg.activemq.message.AbstractPacket
      extended byorg.activemq.message.ActiveMQMessage
          extended byorg.activemq.message.ActiveMQStreamMessage
All Implemented Interfaces:
BodyPacket, java.lang.Comparable, org.activemq.io.util.MemoryManageable, javax.jms.Message, Packet, javax.jms.StreamMessage

public class ActiveMQStreamMessage
extends ActiveMQMessage
implements javax.jms.StreamMessage

A StreamMessage object is used to send a stream of primitive types in the Java programming language. It is filled and read sequentially. It inherits from the Message interface and adds a stream message body. Its methods are based largely on those found in java.io.DataInputStream and java.io.DataOutputStream.

The primitive types can be read or written explicitly using methods for each type. They may also be read or written generically as objects. For instance, a call to StreamMessage.writeInt(6) is equivalent to StreamMessage.writeObject(new Integer(6)). Both forms are provided, because the explicit form is convenient for static programming, and the object form is needed when types are not known at compile time.

When the message is first created, and when clearBody is called, the body of the message is in write-only mode. After the first call to reset has been made, the message body is in read-only mode. After a message has been sent, the client that sent it can retain and modify it without affecting the message that has been sent. The same message object can be sent multiple times. When a message has been received, the provider has called reset so that the message body is in read-only mode for the client.

If clearBody is called on a message in read-only mode, the message body is cleared and the message body is in write-only mode.

If a client attempts to read a message in write-only mode, a MessageNotReadableException is thrown.

If a client attempts to write a message in read-only mode, a MessageNotWriteableException is thrown.

StreamMessage objects support the following conversion table. The marked cases must be supported. The unmarked cases must throw a JMSException. The String-to-primitive conversions may throw a runtime exception if the primitive's valueOf() method does not accept it as a valid String representation of the primitive.

A value written as the row type can be read as the column type.

 |        | boolean byte short char int long float double String byte[]
 |----------------------------------------------------------------------
 |boolean |    X                                            X
 |byte    |          X     X         X   X                  X
 |short   |                X         X   X                  X
 |char    |                     X                           X
 |int     |                          X   X                  X
 |long    |                              X                  X
 |float   |                                    X     X      X
 |double  |                                          X      X
 |String  |    X     X     X         X   X     X     X      X
 |byte[]  |                                                        X
 |----------------------------------------------------------------------
 

Attempting to read a null value as a primitive type must be treated as calling the primitive's corresponding valueOf(String) conversion method with a null value. Since char does not support a String conversion, attempting to read a null value as a char must throw a NullPointerException.


Field Summary
private  java.io.ByteArrayOutputStream bytesOut
           
private  int bytesToRead
           
private  java.io.DataInputStream dataIn
           
private  java.io.DataOutputStream dataOut
           
 
Fields inherited from class org.activemq.message.ActiveMQMessage
BOOLEAN, BROKER_NAME_INDEX, BYTE, BYTES, CACHED_DESTINATION_INDEX, CACHED_VALUES_INDEX, CHAR, CID_INDEX, CLUSTER_NAME_INDEX, CORRELATION_INDEX, DEFAULT_DELIVERY_MODE, DEFAULT_PRIORITY, DEFAULT_TIME_TO_LIVE, DISPATCHED_FROM_DLQ_INDEX, DOUBLE, EOF, EXPIRATION_INDEX, EXTERNAL_MESSAGE_ID_INDEX, FLOAT, INT, LONG, LONG_SEQUENCE_INDEX, MESSAGE_PART_INDEX, NULL, PAYLOAD_INDEX, PROPERTIES_INDEX, readOnlyMessage, REDELIVERED_INDEX, REPLY_TO_INDEX, SHORT, STRING, TIMESTAMP_INDEX, TRANSACTION_ID_INDEX, TYPE_INDEX, XA_TRANS_INDEX
 
Fields inherited from class org.activemq.message.AbstractPacket
bitArray, BROKERS_VISITED_INDEX, cachedHashCode, RECEIPT_REQUIRED_INDEX
 
Fields inherited from interface javax.jms.Message
DEFAULT_DELIVERY_MODE, DEFAULT_PRIORITY, DEFAULT_TIME_TO_LIVE
 
Fields inherited from interface org.activemq.message.Packet
ACTIVEMQ_BROKER_INFO, ACTIVEMQ_BYTES_MESSAGE, ACTIVEMQ_CONNECTION_INFO, ACTIVEMQ_MAP_MESSAGE, ACTIVEMQ_MESSAGE, ACTIVEMQ_MSG_ACK, ACTIVEMQ_OBJECT_MESSAGE, ACTIVEMQ_STREAM_MESSAGE, ACTIVEMQ_TEXT_MESSAGE, BROKER_ADMIN_COMMAND, CACHED_VALUE_COMMAND, CAPACITY_INFO, CAPACITY_INFO_REQUEST, CLEANUP_CONNECTION_INFO, CONSUMER_INFO, DURABLE_UNSUBSCRIBE, INT_RESPONSE_RECEIPT_INFO, KEEP_ALIVE, NOT_SET, PRODUCER_INFO, RECEIPT_INFO, RESPONSE_RECEIPT_INFO, SESSION_INFO, TRANSACTION_INFO, WIRE_FORMAT_INFO, XA_TRANSACTION_INFO
 
Constructor Summary
ActiveMQStreamMessage()
           
 
Method Summary
 void clearBody()
          Clears out the message body.
 ActiveMQMessage deepCopy()
           
 org.activemq.io.util.ByteArray getBodyAsBytes()
           
 int getPacketType()
          Return the type of Packet
private  void initializeReading()
           
private  void initializeWriting()
           
 boolean readBoolean()
          Reads a boolean from the stream message.
 byte readByte()
          Reads a byte value from the stream message.
 int readBytes(byte[] value)
          Reads a byte array field from the stream message into the specified byte[] object (the read buffer).
 char readChar()
          Reads a Unicode character value from the stream message.
 double readDouble()
          Reads a double from the stream message.
 float readFloat()
          Reads a float from the stream message.
 int readInt()
          Reads a 32-bit integer from the stream message.
 long readLong()
          Reads a 64-bit integer from the stream message.
 java.lang.Object readObject()
          Reads an object from the stream message.
 short readShort()
          Reads a 16-bit integer from the stream message.
 java.lang.String readString()
          Reads a String from the stream message.
 void reset()
          Puts the message body in read-only mode and repositions the stream of bytes to the beginning.
 void setBodyAsBytes(byte[] bodyAsBytes, int offset, int length)
           
 ActiveMQMessage shallowCopy()
           
 java.lang.String toString()
          Convert this Object to a human-readable String.
 void writeBoolean(boolean value)
          Writes a boolean to the stream message.
 void writeByte(byte value)
          Writes a byte to the stream message.
 void writeBytes(byte[] value)
          Writes a byte array field to the stream message.
 void writeBytes(byte[] value, int offset, int length)
          Writes a portion of a byte array as a byte array field to the stream message.
 void writeChar(char value)
          Writes a char to the stream message.
 void writeDouble(double value)
          Writes a double to the stream message.
 void writeFloat(float value)
          Writes a float to the stream message.
 void writeInt(int value)
          Writes an int to the stream message.
 void writeLong(long value)
          Writes a long to the stream message.
 void writeObject(java.lang.Object value)
          Writes an object to the stream message.
 void writeShort(short value)
          Writes a short to the stream message.
 void writeString(java.lang.String value)
          Writes a String to the stream message.
 
Methods inherited from class org.activemq.message.ActiveMQMessage
acknowledge, buildBodyFromBytes, clearProperties, compareTo, compareTo, convertBodyToBytes, equals, getBodyAsBytes, getBooleanProperty, getByteProperty, getConsumerIdentifer, getConsumerNos, getConsumerNosAsString, getDeliveryCount, getDoubleProperty, getEntryBrokerName, getEntryClusterName, getFloatProperty, getIntProperty, getJMSActiveMQDestination, getJMSClientID, getJMSCorrelationID, getJMSCorrelationIDAsBytes, getJMSDeliveryMode, getJMSDestination, getJMSExpiration, getJMSMessageID, getJMSMessageIdentity, getJMSPriority, getJMSRedelivered, getJMSReplyTo, getJMSTimestamp, getJMSType, getLongProperty, getMemoryId, getMessageAcknowledge, getMesssageHandle, getNumberOfParts, getObjectProperty, getParentMessageID, getPartNumber, getPriority, getProducerKey, getProperties, getPropertyNames, getReservedProperty, getSequenceNumber, getShortProperty, getStringProperty, getTransactionId, getTransactionIDString, getVanillaProperty, hashCode, incrementDeliveryCount, incrementRedeliveryCount, initializeOther, isAdvisory, isBodyConvertedToBytes, isConsumerTarget, isDispatchedFromDLQ, isEntryBroker, isEntryCluster, isExpired, isExpired, isExternalMessageId, isJMSMessage, isLastMessagePart, isMessageConsumed, isMessagePart, isPartOfTransaction, isPersistent, isTemporary, isTransientConsumed, isXaTransacted, prepareMessageBody, propertyExists, readBody, readMapProperties, resetMessagePart, setBodyAsBytes, setBooleanProperty, setByteProperty, setConsumerIdentifer, setConsumerNos, setConsumerNosAsString, setDeliveryCount, setDispatchedFromDLQ, setDoubleProperty, setEntryBrokerName, setEntryClusterName, setExternalMessageId, setFloatProperty, setIntProperty, setJMSClientID, setJMSCorrelationID, setJMSCorrelationIDAsBytes, setJMSDeliveryMode, setJMSDestination, setJMSExpiration, setJMSMessageID, setJMSMessageIdentity, setJMSPriority, setJMSRedelivered, setJMSReplyTo, setJMSTimestamp, setJMSType, setLongProperty, setMessageAcknowledge, setMessageConsumed, setMessagePart, setMesssageHandle, setNumberOfParts, setObjectProperty, setParentMessageID, setPartNumber, setProducerKey, setProperties, setReadOnly, setSequenceNumber, setShortProperty, setStringProperty, setTransactionId, setTransactionIDString, setTransientConsumed, toString, vanillaToBoolean, vanillaToByte, vanillaToDouble, vanillaToFloat, vanillaToInt, vanillaToLong, vanillaToShort, vanillaToString, writeBody, writeMapProperties
 
Methods inherited from class org.activemq.message.AbstractPacket
addBrokerVisited, clearBrokersVisited, decrementMemoryReferenceCount, equals, getBitArray, getBrokersVisited, getBrokersVisitedAsString, getId, getMemoryUsage, getMemoryUsageReferenceCount, getPacketTypeAsString, hasVisited, incrementMemoryReferenceCount, initializeBrokersVisited, initializeOther, isReceipt, isReceiptRequired, setBitArray, setBrokersVisitedAsString, setId, setMemoryUsage, setReceiptRequired
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface javax.jms.Message
acknowledge, clearProperties, getBooleanProperty, getByteProperty, getDoubleProperty, getFloatProperty, getIntProperty, getJMSCorrelationID, getJMSCorrelationIDAsBytes, getJMSDeliveryMode, getJMSDestination, getJMSExpiration, getJMSMessageID, getJMSPriority, getJMSRedelivered, getJMSReplyTo, getJMSTimestamp, getJMSType, getLongProperty, getObjectProperty, getPropertyNames, getShortProperty, getStringProperty, propertyExists, setBooleanProperty, setByteProperty, setDoubleProperty, setFloatProperty, setIntProperty, setJMSCorrelationID, setJMSCorrelationIDAsBytes, setJMSDeliveryMode, setJMSDestination, setJMSExpiration, setJMSMessageID, setJMSPriority, setJMSRedelivered, setJMSReplyTo, setJMSTimestamp, setJMSType, setLongProperty, setObjectProperty, setShortProperty, setStringProperty
 
Methods inherited from interface org.activemq.io.util.MemoryManageable
decrementMemoryReferenceCount, getMemoryUsage, getMemoryUsageReferenceCount, incrementMemoryReferenceCount
 

Field Detail

dataOut

private java.io.DataOutputStream dataOut

bytesOut

private java.io.ByteArrayOutputStream bytesOut

dataIn

private java.io.DataInputStream dataIn

bytesToRead

private int bytesToRead
Constructor Detail

ActiveMQStreamMessage

public ActiveMQStreamMessage()
Method Detail

getPacketType

public int getPacketType()
Return the type of Packet

Specified by:
getPacketType in interface Packet
Overrides:
getPacketType in class ActiveMQMessage

shallowCopy

public ActiveMQMessage shallowCopy()
                            throws javax.jms.JMSException
Overrides:
shallowCopy in class ActiveMQMessage

deepCopy

public ActiveMQMessage deepCopy()
                         throws javax.jms.JMSException
Overrides:
deepCopy in class ActiveMQMessage

clearBody

public void clearBody()
               throws javax.jms.JMSException
Clears out the message body. Clearing a message's body does not clear its header values or property entries.

If this message body was read-only, calling this method leaves the message body in the same state as an empty body in a newly created message.

Specified by:
clearBody in interface javax.jms.Message
Overrides:
clearBody in class ActiveMQMessage

readBoolean

public boolean readBoolean()
                    throws javax.jms.JMSException
Reads a boolean from the stream message.

Specified by:
readBoolean in interface javax.jms.StreamMessage

readByte

public byte readByte()
              throws javax.jms.JMSException
Reads a byte value from the stream message.

Specified by:
readByte in interface javax.jms.StreamMessage

readShort

public short readShort()
                throws javax.jms.JMSException
Reads a 16-bit integer from the stream message.

Specified by:
readShort in interface javax.jms.StreamMessage

readChar

public char readChar()
              throws javax.jms.JMSException
Reads a Unicode character value from the stream message.

Specified by:
readChar in interface javax.jms.StreamMessage

readInt

public int readInt()
            throws javax.jms.JMSException
Reads a 32-bit integer from the stream message.

Specified by:
readInt in interface javax.jms.StreamMessage

readLong

public long readLong()
              throws javax.jms.JMSException
Reads a 64-bit integer from the stream message.

Specified by:
readLong in interface javax.jms.StreamMessage

readFloat

public float readFloat()
                throws javax.jms.JMSException
Reads a float from the stream message.

Specified by:
readFloat in interface javax.jms.StreamMessage

readDouble

public double readDouble()
                  throws javax.jms.JMSException
Reads a double from the stream message.

Specified by:
readDouble in interface javax.jms.StreamMessage

readString

public java.lang.String readString()
                            throws javax.jms.JMSException
Reads a String from the stream message.

Specified by:
readString in interface javax.jms.StreamMessage

readBytes

public int readBytes(byte[] value)
              throws javax.jms.JMSException
Reads a byte array field from the stream message into the specified byte[] object (the read buffer).

To read the field value, readBytes should be successively called until it returns a value less than the length of the read buffer. The value of the bytes in the buffer following the last byte read is undefined.

If readBytes returns a value equal to the length of the buffer, a subsequent readBytes call must be made. If there are no more bytes to be read, this call returns -1.

If the byte array field value is null, readBytes returns -1.

If the byte array field value is empty, readBytes returns 0.

Once the first readBytes call on a byte[] field value has been made, the full value of the field must be read before it is valid to read the next field. An attempt to read the next field before that has been done will throw a MessageFormatException.

To read the byte field value into a new byte[] object, use the readObject method.

Specified by:
readBytes in interface javax.jms.StreamMessage

readObject

public java.lang.Object readObject()
                            throws javax.jms.JMSException
Reads an object from the stream message.

This method can be used to return, in objectified format, an object in the Java programming language ("Java object") that has been written to the stream with the equivalent writeObject method call, or its equivalent primitive writetype method.

Note that byte values are returned as byte[], not Byte[].

An attempt to call readObject to read a byte field value into a new byte[] object before the full value of the byte field has been read will throw a MessageFormatException.

Specified by:
readObject in interface javax.jms.StreamMessage

writeBoolean

public void writeBoolean(boolean value)
                  throws javax.jms.JMSException
Writes a boolean to the stream message. The value true is written as the value (byte)1; the value false is written as the value (byte)0.

Specified by:
writeBoolean in interface javax.jms.StreamMessage

writeByte

public void writeByte(byte value)
               throws javax.jms.JMSException
Writes a byte to the stream message.

Specified by:
writeByte in interface javax.jms.StreamMessage

writeShort

public void writeShort(short value)
                throws javax.jms.JMSException
Writes a short to the stream message.

Specified by:
writeShort in interface javax.jms.StreamMessage

writeChar

public void writeChar(char value)
               throws javax.jms.JMSException
Writes a char to the stream message.

Specified by:
writeChar in interface javax.jms.StreamMessage

writeInt

public void writeInt(int value)
              throws javax.jms.JMSException
Writes an int to the stream message.

Specified by:
writeInt in interface javax.jms.StreamMessage

writeLong

public void writeLong(long value)
               throws javax.jms.JMSException
Writes a long to the stream message.

Specified by:
writeLong in interface javax.jms.StreamMessage

writeFloat

public void writeFloat(float value)
                throws javax.jms.JMSException
Writes a float to the stream message.

Specified by:
writeFloat in interface javax.jms.StreamMessage

writeDouble

public void writeDouble(double value)
                 throws javax.jms.JMSException
Writes a double to the stream message.

Specified by:
writeDouble in interface javax.jms.StreamMessage

writeString

public void writeString(java.lang.String value)
                 throws javax.jms.JMSException
Writes a String to the stream message.

Specified by:
writeString in interface javax.jms.StreamMessage

writeBytes

public void writeBytes(byte[] value)
                throws javax.jms.JMSException
Writes a byte array field to the stream message.

The byte array value is written to the message as a byte array field. Consecutively written byte array fields are treated as two distinct fields when the fields are read.

Specified by:
writeBytes in interface javax.jms.StreamMessage

writeBytes

public void writeBytes(byte[] value,
                       int offset,
                       int length)
                throws javax.jms.JMSException
Writes a portion of a byte array as a byte array field to the stream message.

The a portion of the byte array value is written to the message as a byte array field. Consecutively written byte array fields are treated as two distinct fields when the fields are read.

Specified by:
writeBytes in interface javax.jms.StreamMessage

writeObject

public void writeObject(java.lang.Object value)
                 throws javax.jms.JMSException
Writes an object to the stream message.

This method works only for the objectified primitive object types (Integer, Double, Long ...), String objects, and byte arrays.

Specified by:
writeObject in interface javax.jms.StreamMessage

reset

public void reset()
           throws javax.jms.JMSException
Puts the message body in read-only mode and repositions the stream of bytes to the beginning.

Specified by:
reset in interface javax.jms.StreamMessage

setBodyAsBytes

public void setBodyAsBytes(byte[] bodyAsBytes,
                           int offset,
                           int length)
Overrides:
setBodyAsBytes in class ActiveMQMessage

getBodyAsBytes

public org.activemq.io.util.ByteArray getBodyAsBytes()
                                              throws java.io.IOException
Overrides:
getBodyAsBytes in class ActiveMQMessage

initializeWriting

private void initializeWriting()
                        throws javax.jms.MessageNotWriteableException

initializeReading

private void initializeReading()
                        throws javax.jms.MessageNotReadableException

toString

public java.lang.String toString()
Description copied from class: java.lang.Object
Convert this Object to a human-readable String. There are no limits placed on how long this String should be or what it should contain. We suggest you make it as intuitive as possible to be able to place it into System.out.println() 55 and such.

It is typical, but not required, to ensure that this method never completes abruptly with a java.lang.RuntimeException.

This method will be called when performing string concatenation with this object. If the result is null, string concatenation will instead use "null".

The default implementation returns getClass().getName() + "@" + Integer.toHexString(hashCode()).

Overrides:
toString in class ActiveMQMessage