|
|||||||||
Home >> All >> org >> activemq >> [ message overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: ![]() ![]() ![]() |
DETAIL: FIELD | CONSTR | METHOD |
org.activemq.message
Class ActiveMQStreamMessage

java.lang.Objectorg.activemq.message.AbstractPacket
org.activemq.message.ActiveMQMessage
org.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
- extends ActiveMQMessage
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 |
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 java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
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 interfacePacket
- Overrides:
getPacketType
in classActiveMQMessage
shallowCopy
public ActiveMQMessage shallowCopy() throws javax.jms.JMSException
- Overrides:
shallowCopy
in classActiveMQMessage
deepCopy
public ActiveMQMessage deepCopy() throws javax.jms.JMSException
- Overrides:
deepCopy
in classActiveMQMessage
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 interfacejavax.jms.Message
- Overrides:
clearBody
in classActiveMQMessage
readBoolean
public boolean readBoolean() throws javax.jms.JMSException
- Reads a
boolean
from the stream message.- Specified by:
readBoolean
in interfacejavax.jms.StreamMessage
readByte
public byte readByte() throws javax.jms.JMSException
- Reads a
byte
value from the stream message.- Specified by:
readByte
in interfacejavax.jms.StreamMessage
readShort
public short readShort() throws javax.jms.JMSException
- Reads a 16-bit integer from the stream message.
- Specified by:
readShort
in interfacejavax.jms.StreamMessage
readChar
public char readChar() throws javax.jms.JMSException
- Reads a Unicode character value from the stream message.
- Specified by:
readChar
in interfacejavax.jms.StreamMessage
readInt
public int readInt() throws javax.jms.JMSException
- Reads a 32-bit integer from the stream message.
- Specified by:
readInt
in interfacejavax.jms.StreamMessage
readLong
public long readLong() throws javax.jms.JMSException
- Reads a 64-bit integer from the stream message.
- Specified by:
readLong
in interfacejavax.jms.StreamMessage
readFloat
public float readFloat() throws javax.jms.JMSException
- Reads a
float
from the stream message.- Specified by:
readFloat
in interfacejavax.jms.StreamMessage
readDouble
public double readDouble() throws javax.jms.JMSException
- Reads a
double
from the stream message.- Specified by:
readDouble
in interfacejavax.jms.StreamMessage
readString
public java.lang.String readString() throws javax.jms.JMSException
- Reads a
String
from the stream message.- Specified by:
readString
in interfacejavax.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 subsequentreadBytes
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 abyte[]
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 aMessageFormatException
.To read the byte field value into a new
byte[]
object, use thereadObject
method.- Specified by:
readBytes
in interfacejavax.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 primitivewritetype
method.Note that byte values are returned as
byte[]
, notByte[]
.An attempt to call
readObject
to read a byte field value into a newbyte[]
object before the full value of the byte field has been read will throw aMessageFormatException
.- Specified by:
readObject
in interfacejavax.jms.StreamMessage
writeBoolean
public void writeBoolean(boolean value) throws javax.jms.JMSException
- Writes a
boolean
to the stream message. The valuetrue
is written as the value(byte)1
; the valuefalse
is written as the value(byte)0
.- Specified by:
writeBoolean
in interfacejavax.jms.StreamMessage
writeByte
public void writeByte(byte value) throws javax.jms.JMSException
- Writes a
byte
to the stream message.- Specified by:
writeByte
in interfacejavax.jms.StreamMessage
writeShort
public void writeShort(short value) throws javax.jms.JMSException
- Writes a
short
to the stream message.- Specified by:
writeShort
in interfacejavax.jms.StreamMessage
writeChar
public void writeChar(char value) throws javax.jms.JMSException
- Writes a
char
to the stream message.- Specified by:
writeChar
in interfacejavax.jms.StreamMessage
writeInt
public void writeInt(int value) throws javax.jms.JMSException
- Writes an
int
to the stream message.- Specified by:
writeInt
in interfacejavax.jms.StreamMessage
writeLong
public void writeLong(long value) throws javax.jms.JMSException
- Writes a
long
to the stream message.- Specified by:
writeLong
in interfacejavax.jms.StreamMessage
writeFloat
public void writeFloat(float value) throws javax.jms.JMSException
- Writes a
float
to the stream message.- Specified by:
writeFloat
in interfacejavax.jms.StreamMessage
writeDouble
public void writeDouble(double value) throws javax.jms.JMSException
- Writes a
double
to the stream message.- Specified by:
writeDouble
in interfacejavax.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 interfacejavax.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 interfacejavax.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 interfacejavax.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 interfacejavax.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 interfacejavax.jms.StreamMessage
setBodyAsBytes
public void setBodyAsBytes(byte[] bodyAsBytes, int offset, int length)
- Overrides:
setBodyAsBytes
in classActiveMQMessage
getBodyAsBytes
public org.activemq.io.util.ByteArray getBodyAsBytes() throws java.io.IOException
- Overrides:
getBodyAsBytes
in classActiveMQMessage
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 classActiveMQMessage
|
|||||||||
Home >> All >> org >> activemq >> [ message overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: ![]() ![]() ![]() |
DETAIL: FIELD | CONSTR | METHOD |