public class Message extends Object implements 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 |
static byte |
DONT_BUNDLE |
protected Headers |
headers
All headers are placed here
|
protected int |
length
The number of bytes in the buffer (usually buf.length is buf not equal to null).
|
protected static Log |
log |
static byte |
NO_FC |
static byte |
NO_RELAY |
static byte |
NO_RELIABILITY |
static byte |
NO_TOTAL_ORDER |
protected int |
offset
The index into the payload (usually 0)
|
static byte |
OOB |
static byte |
OOB_DELIVERED |
static byte |
SCOPED |
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,
Object obj)
Public constructor
|
Message(boolean create_headers) |
Modifier and Type | Method and Description |
---|---|
void |
clearFlag(byte flag) |
void |
clearTransientFlag(byte flag) |
protected Object |
clone() |
Message |
copy() |
Message |
copy(boolean copy_buffer)
Create a copy of the message.
|
Message |
copy(boolean copy_buffer,
boolean copy_headers)
Create a copy of the message.
|
Message |
copy(boolean copy_buffer,
short starting_id)
Doesn't copy any headers except for those with ID >= copy_headers_above
|
static String |
flagsToString(byte flags) |
byte[] |
getBuffer()
Returns a copy of the buffer if offset and length are used, otherwise a reference.
|
Address |
getDest() |
byte |
getFlags() |
Header |
getHeader(short id) |
Map<Short,Header> |
getHeaders()
Returns a reference to the headers hashmap, which is immutable.
|
int |
getLength()
Returns the number of bytes in the buffer
|
int |
getNumHeaders() |
Object |
getObject()
Uses custom 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).
|
short |
getScope() |
Address |
getSrc() |
byte |
getTransientFlags() |
boolean |
isFlagSet(byte flag) |
protected static boolean |
isFlagSet(byte flags,
byte flag) |
boolean |
isTransientFlagSet(byte flag) |
Message |
makeReply() |
String |
printHeaders() |
String |
printObjectHeaders() |
void |
putHeader(short id,
Header hdr)
Puts a header given an ID into the hashmap.
|
Header |
putHeaderIfAbsent(short id,
Header hdr)
Puts a header given a key into the map, only if the key doesn't exist yet
|
void |
readFrom(DataInputStream in)
Read the state of the current object (including superclasses) from instream
Note that the input stream must not be closed
|
Header |
removeHeader(short id)
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(Object obj)
Takes an object and uses Java serialization to generate the byte[] buffer which is set in the message.
|
void |
setScope(short scope) |
void |
setSrc(Address new_src) |
void |
setTransientFlag(byte flag)
Same as
setFlag(byte) but transient flags are never marshalled |
boolean |
setTransientFlagIfAbsent(byte flag)
Atomically checks if a given flag is set and - if not - sets it.
|
long |
size()
Returns the exact size of the marshalled message.
|
String |
toString() |
String |
toStringAsObject()
Tries to read an object from the message's buffer and prints it
|
static String |
transientFlagsToString(byte flags) |
void |
writeTo(DataOutputStream out)
Streams all members (dest and src addresses, buffer and headers) to the output stream.
|
void |
writeToNoAddrs(Address src,
DataOutputStream out)
Writes the message to the output stream, but excludes the dest and src addresses unless the src address given
as argument is different from the message's src address
|
protected Address dest_addr
protected Address src_addr
protected int offset
protected int length
protected Headers headers
protected static final Log log
public static final byte OOB
public static final byte DONT_BUNDLE
public static final byte NO_FC
public static final byte SCOPED
public static final byte NO_RELIABILITY
public static final byte NO_TOTAL_ORDER
public static final byte NO_RELAY
public static final byte OOB_DELIVERED
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, Object 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 marshalled into the byte buffer. Obj to be serializable (e.g. implementing
Serializable, Externalizable or Streamable, or be a basic type (e.g. Integer, Short etc)).!
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().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 Map<Short,Header> getHeaders()
public String printHeaders()
public int getNumHeaders()
public final void setObject(Object obj)
public final Object getObject()
public void setFlag(byte flag)
public void clearFlag(byte flag)
public boolean isFlagSet(byte flag)
public void setTransientFlag(byte flag)
setFlag(byte)
but transient flags are never marshalledflag
- public boolean setTransientFlagIfAbsent(byte flag)
flag
- public void clearTransientFlag(byte flag)
public boolean isTransientFlagSet(byte flag)
protected static boolean isFlagSet(byte flags, byte flag)
public byte getFlags()
public byte getTransientFlags()
public void setScope(short scope)
public short getScope()
public void putHeader(short id, Header hdr)
public Header putHeaderIfAbsent(short id, Header hdr)
id
- hdr
- public Header removeHeader(short id)
key
- public Header getHeader(short id)
public Message copy()
public Message copy(boolean copy_buffer)
copy_buffer
- public Message copy(boolean copy_buffer, boolean copy_headers)
copy_buffer
- copy_headers
- Copy the headerspublic Message copy(boolean copy_buffer, short starting_id)
copy_buffer
- starting_id
- protected Object clone() throws CloneNotSupportedException
clone
in class Object
CloneNotSupportedException
public Message makeReply()
public String toStringAsObject()
public String printObjectHeaders()
public void writeTo(DataOutputStream out) throws IOException
writeTo
in interface Streamable
out
- IOException
public void writeToNoAddrs(Address src, DataOutputStream out) throws IOException
src
- out
- IOException
public void readFrom(DataInputStream in) throws IOException, IllegalAccessException, InstantiationException
Streamable
readFrom
in interface Streamable
IOException
IllegalAccessException
InstantiationException
public long size()
public static String flagsToString(byte flags)
public static String transientFlagsToString(byte flags)
Copyright © 2013 JBoss, a division of Red Hat. All Rights Reserved.