public class Message extends java.lang.Object implements java.io.Externalizable, Streamable
The byte buffer can point to a reference, and we can subset it using index and length. However, when the message is serialized, we only write the bytes between index and length.
Modifier and Type | Field and Description |
---|---|
protected Address |
dest_addr |
protected Headers |
headers
All headers are placed here
|
static byte |
HIGH_PRIO |
protected int |
length
The number of bytes in the buffer (usually buf.length is buf not equal to null).
|
protected static org.apache.commons.logging.Log |
log |
static byte |
LOW_PRIO |
protected int |
offset
The index into the payload (usually 0)
|
static byte |
OOB |
protected Address |
src_addr |
Constructor and Description |
---|
Message() |
Message(Address dest)
Public constructor
|
Message(Address dest,
Address src,
byte[] buf)
Public constructor
|
Message(Address dest,
Address src,
byte[] buf,
int offset,
int length)
Constructs a message.
|
Message(Address dest,
Address src,
java.io.Serializable obj)
Public constructor
|
Message(boolean create_headers) |
Modifier and Type | Method and Description |
---|---|
void |
clearFlag(byte flag) |
protected java.lang.Object |
clone() |
Message |
copy() |
Message |
copy(boolean copy_buffer)
Create a copy of the message.
|
byte[] |
getBuffer()
Returns a copy of the buffer if offset and length are used, otherwise a reference.
|
Address |
getDest() |
byte |
getFlags() |
Header |
getHeader(java.lang.String key) |
java.util.Map<java.lang.String,Header> |
getHeaders()
Returns a reference to the headers hashmap, which is immutable.
|
int |
getLength()
Returns the number of bytes in the buffer
|
int |
getNumHeaders() |
java.lang.Object |
getObject()
Uses Java serialization to create an object from the buffer of the message.
|
int |
getOffset()
Returns the offset into the buffer at which the data starts
|
byte[] |
getRawBuffer()
Returns a reference to the payload (byte buffer).
|
Address |
getSrc() |
boolean |
isFlagSet(byte flag) |
Message |
makeReply() |
java.lang.String |
printHeaders() |
java.lang.String |
printObjectHeaders() |
void |
putHeader(java.lang.String key,
Header hdr)
Puts a header given a key into the hashmap.
|
Header |
putHeaderIfAbsent(java.lang.String key,
Header hdr)
Puts a header given a key into the map, only if the key doesn't exist yet
|
void |
readExternal(java.io.ObjectInput in) |
void |
readFrom(java.io.DataInputStream in)
Read the state of the current object (including superclasses) from instream
Note that the input stream must not be closed
|
Header |
removeHeader(java.lang.String key)
Deprecated.
Use getHeader() instead. The issue with removing a header is described in
http://jira.jboss.com/jira/browse/JGRP-393
|
void |
setBuffer(Buffer buf)
Note that the byte[] buffer passed as argument must not be modified.
|
void |
setBuffer(byte[] b) |
void |
setBuffer(byte[] b,
int offset,
int length)
Set the internal buffer to point to a subset of a given buffer
|
void |
setDest(Address new_dest) |
void |
setFlag(byte flag) |
void |
setObject(java.io.Serializable obj)
Takes an object and uses Java serialization to generate the byte[] buffer which is set in the message.
|
void |
setSrc(Address new_src) |
long |
size()
Returns the exact size of the marshalled message.
|
java.lang.String |
toString() |
java.lang.String |
toStringAsObject()
Tries to read an object from the message's buffer and prints it
|
void |
writeExternal(java.io.ObjectOutput out) |
void |
writeTo(java.io.DataOutputStream out)
Streams all members (dest and src addresses, buffer and headers) to the output stream.
|
protected Address dest_addr
protected Address src_addr
protected transient int offset
protected transient int length
protected Headers headers
protected static final org.apache.commons.logging.Log log
public static final byte OOB
public static final byte LOW_PRIO
public static final byte HIGH_PRIO
public Message(Address dest)
dest
- Address of receiver. If it is null then the message sent to the group.
Otherwise, it contains a single destination and is sent to that member.public Message(Address dest, Address src, byte[] buf)
dest
- Address of receiver. If it is null then the message sent to the group.
Otherwise, it contains a single destination and is sent to that member.src
- Address of senderbuf
- Message to be sent. Note that this buffer must not be modified (e.g. buf[0]=0 is
not allowed), since we don't copy the contents on clopy() or clone().public Message(Address dest, Address src, byte[] buf, int offset, int length)
dest
- Address of receiver. If it is null then the message sent to the group.
Otherwise, it contains a single destination and is sent to that member.src
- Address of senderbuf
- A reference to a byte bufferoffset
- The index into the byte bufferlength
- The number of bytes to be used from buf. Both index and length are checked for
array index violations and an ArrayIndexOutOfBoundsException will be thrown if invalidpublic Message(Address dest, Address src, java.io.Serializable obj)
dest
- Address of receiver. If it is null then the message sent to the group.
Otherwise, it contains a single destination and is sent to that member.src
- Address of senderobj
- The object will be serialized into the byte buffer. Object
has to be serializable ! The resulting buffer must not be modified
(e.g. buf[0]=0 is not allowed), since we don't copy the contents on clopy() or clone().
Note that this is a convenience method and JGroups will use default Java serialization to
serialize obj
into a byte buffer.public Message()
public Message(boolean create_headers)
public Address getDest()
public void setDest(Address new_dest)
public Address getSrc()
public void setSrc(Address new_src)
public byte[] getRawBuffer()
public final byte[] getBuffer()
public final void setBuffer(byte[] b)
public final void setBuffer(byte[] b, int offset, int length)
b
- The reference to a given buffer. If null, we'll reset the buffer to nulloffset
- The initial positionlength
- The number of bytespublic final void setBuffer(Buffer buf)
public int getOffset()
public int getLength()
public java.util.Map<java.lang.String,Header> getHeaders()
public java.lang.String printHeaders()
public int getNumHeaders()
public final void setObject(java.io.Serializable obj)
public final java.lang.Object getObject()
public void setFlag(byte flag)
public void clearFlag(byte flag)
public boolean isFlagSet(byte flag)
public byte getFlags()
public void putHeader(java.lang.String key, Header hdr)
public Header putHeaderIfAbsent(java.lang.String key, Header hdr)
key
- hdr
- public Header removeHeader(java.lang.String key)
key
- public Header getHeader(java.lang.String key)
public Message copy()
public Message copy(boolean copy_buffer)
copy_buffer
- protected java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
public Message makeReply()
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toStringAsObject()
public long size()
public java.lang.String printObjectHeaders()
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
writeExternal
in interface java.io.Externalizable
java.io.IOException
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
readExternal
in interface java.io.Externalizable
java.io.IOException
java.lang.ClassNotFoundException
public void writeTo(java.io.DataOutputStream out) throws java.io.IOException
writeTo
in interface Streamable
out
- java.io.IOException
public void readFrom(java.io.DataInputStream in) throws java.io.IOException, java.lang.IllegalAccessException, java.lang.InstantiationException
Streamable
readFrom
in interface Streamable
java.io.IOException
java.lang.IllegalAccessException
java.lang.InstantiationException
Copyright ? 1998-2008 Bela Ban. All Rights Reserved.