public class Message extends java.lang.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 | Class and Description |
---|---|
static class |
Message.Flag |
static class |
Message.TransientFlag |
Modifier and Type | Field and Description |
---|---|
protected byte[] |
buf
The payload
|
protected Address |
dest_addr |
static Message.Flag |
DONT_BUNDLE
Deprecated.
|
protected short |
flags |
protected Header[] |
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).
|
static Message.Flag |
NO_FC
Deprecated.
|
static Message.Flag |
NO_RELAY
Deprecated.
|
static Message.Flag |
NO_RELIABILITY
Deprecated.
|
static Message.Flag |
NO_TOTAL_ORDER
Deprecated.
|
protected int |
offset
The index into the payload (usually 0)
|
static Message.Flag |
OOB
Deprecated.
|
static Message.TransientFlag |
OOB_DELIVERED
Deprecated.
|
static Message.Flag |
RSVP
Deprecated.
|
static Message.Flag |
SCOPED
Deprecated.
|
protected Address |
src_addr |
protected byte |
transient_flags |
Constructor and Description |
---|
Message() |
Message(Address dest)
Constructs a Message given a destination Address
|
Message(Address dest,
Address src,
byte[] buf)
Constructs a Message given a destination Address, a source Address and the payload byte buffer
|
Message(Address dest,
Address src,
byte[] buf,
int offset,
int length)
Constructs a message.
|
Message(Address dest,
Address src,
java.lang.Object obj)
Constructs a Message given a destination Address, a source Address and the payload Object
|
Message(Address dest,
byte[] buf) |
Message(Address dest,
byte[] buf,
int offset,
int length) |
Message(Address dest,
java.lang.Object obj) |
Message(boolean create_headers) |
Modifier and Type | Method and Description |
---|---|
Message |
clearFlag(Message.Flag... flags)
Clears a number of flags in a message
|
Message |
clearTransientFlag(Message.TransientFlag... flags) |
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
|
Message |
copy(boolean copy_buffer,
short starting_id,
short... copy_only_ids)
Copies a message.
|
protected static Header[] |
createHeaders(int size) |
Address |
dest() |
Message |
dest(Address new_dest) |
static java.lang.String |
flagsToString(short flags) |
byte[] |
getBuffer()
Returns a copy of the buffer if offset and length are used, otherwise a reference.
|
Address |
getDest() |
short |
getFlags()
Returns the internal representation of flags.
|
Header |
getHeader(short id) |
java.util.Map<java.lang.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() |
java.lang.Object |
getObject() |
java.lang.Object |
getObject(java.lang.ClassLoader loader)
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() |
short |
getTransientFlags() |
boolean |
isFlagSet(Message.Flag flag)
Checks if a given flag is set
|
static boolean |
isFlagSet(short flags,
Message.Flag flag) |
boolean |
isTransientFlagSet(Message.TransientFlag flag) |
static boolean |
isTransientFlagSet(short flags,
Message.TransientFlag flag) |
Message |
makeReply() |
java.lang.String |
printHeaders() |
java.lang.String |
printObjectHeaders() |
Message |
putHeader(short id,
Header hdr)
Puts a header given an ID into the hashmap.
|
Message |
putHeaderIfAbsent(short id,
Header hdr)
Puts a header given a key into the map, only if the key doesn't exist yet
|
void |
readFrom(java.io.DataInput in)
Read the state of the current object (including superclasses) from instream
Note that the input stream must not be closed
|
int |
readFromSkipPayload(ByteArrayDataInputStream in)
Reads the message's contents from an input stream, but skips the buffer and instead returns the
position (offset) at which the buffer starts
|
protected static Header |
readHeader(java.io.DataInput in) |
Message |
setBuffer(Buffer buf)
Note that the byte[] buffer passed as argument must not be modified.
|
Message |
setBuffer(byte[] b)
Note that the byte[] buffer passed as argument must not be modified.
|
Message |
setBuffer(byte[] b,
int offset,
int length)
Sets the internal buffer to point to a subset of a given buffer.
Note that the byte[] buffer passed as argument must not be modified.
|
void |
setDest(Address new_dest) |
Message |
setFlag(Message.Flag... flags)
Sets a number of flags in a message
|
Message |
setFlag(short flag)
Sets the flags from a short.
|
Message |
setObject(java.lang.Object obj)
Takes an object and uses Java serialization to generate the byte[] buffer which is set in the
message.
|
Message |
setScope(short scope) |
void |
setSrc(Address new_src) |
Message |
setTransientFlag(Message.TransientFlag... flags)
Same as
setFlag(Flag...) except that transient flags are not marshalled |
Message |
setTransientFlag(short flag) |
boolean |
setTransientFlagIfAbsent(Message.TransientFlag flag)
Atomically checks if a given flag is set and - if not - sets it.
|
long |
size()
Returns the exact size of the marshalled message.
|
Address |
src() |
Message |
src(Address new_src) |
java.lang.String |
toString() |
static java.lang.String |
transientFlagsToString(short flags) |
protected static void |
writeHeader(Header hdr,
java.io.DataOutput out) |
void |
writeTo(java.io.DataOutput out)
Streams all members (dest and src addresses, buffer and headers) to the output stream.
|
void |
writeToNoAddrs(Address src,
java.io.DataOutput out,
short... excluded_headers)
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 byte[] buf
protected int offset
protected int length
protected volatile Header[] headers
protected volatile short flags
protected volatile byte transient_flags
@Deprecated public static final Message.Flag OOB
@Deprecated public static final Message.Flag DONT_BUNDLE
@Deprecated public static final Message.Flag NO_FC
@Deprecated public static final Message.Flag SCOPED
@Deprecated public static final Message.Flag NO_RELIABILITY
@Deprecated public static final Message.Flag NO_TOTAL_ORDER
@Deprecated public static final Message.Flag NO_RELAY
@Deprecated public static final Message.Flag RSVP
@Deprecated public static final Message.TransientFlag 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, byte[] buf)
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, byte[] buf, int offset, int length)
public Message(Address dest, Address src, java.lang.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 has 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(Address dest, java.lang.Object obj)
public Message()
public Message(boolean create_headers)
public Address getDest()
public Address dest()
public void setDest(Address new_dest)
public Address getSrc()
public Address src()
public void setSrc(Address new_src)
public byte[] getRawBuffer()
public final byte[] getBuffer()
public final Message setBuffer(byte[] b)
public final Message 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 Message setBuffer(Buffer buf)
public int getOffset()
public int getLength()
public java.util.Map<java.lang.Short,Header> getHeaders()
public java.lang.String printHeaders()
public int getNumHeaders()
public final Message setObject(java.lang.Object obj)
public final java.lang.Object getObject()
public final java.lang.Object getObject(java.lang.ClassLoader loader)
public Message setFlag(Message.Flag... flags)
flags
- The flag or flagspublic Message setTransientFlag(Message.TransientFlag... flags)
setFlag(Flag...)
except that transient flags are not marshalledflags
- The flagpublic Message setFlag(short flag)
setFlag(org.jgroups.Message.Flag...)
instead),
as the internal representation of flags might change anytime.flag
- public Message setTransientFlag(short flag)
public short getFlags()
public short getTransientFlags()
public Message clearFlag(Message.Flag... flags)
flags
- The flagspublic Message clearTransientFlag(Message.TransientFlag... flags)
public static boolean isFlagSet(short flags, Message.Flag flag)
public boolean isFlagSet(Message.Flag flag)
flag
- The flagpublic static boolean isTransientFlagSet(short flags, Message.TransientFlag flag)
public boolean isTransientFlagSet(Message.TransientFlag flag)
public boolean setTransientFlagIfAbsent(Message.TransientFlag flag)
flag
- public Message setScope(short scope)
public short getScope()
public Message putHeader(short id, Header hdr)
public Message putHeaderIfAbsent(short id, Header hdr)
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)
putHeader(short,Header)
again.copy_buffer
- copy_headers
- Copy the headerspublic Message copy(boolean copy_buffer, short starting_id)
copy_buffer
- starting_id
- public Message copy(boolean copy_buffer, short starting_id, short... copy_only_ids)
copy_buffer
- starting_id
- copy_only_ids
- public Message makeReply()
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String printObjectHeaders()
public void writeTo(java.io.DataOutput out) throws java.lang.Exception
writeTo
in interface Streamable
out
- java.lang.Exception
public void writeToNoAddrs(Address src, java.io.DataOutput out, short... excluded_headers) throws java.lang.Exception
src
- out
- excluded_headers
- Don't marshal headers that are part of excluded_headersjava.lang.Exception
public void readFrom(java.io.DataInput in) throws java.lang.Exception
Streamable
readFrom
in interface Streamable
java.lang.Exception
public int readFromSkipPayload(ByteArrayDataInputStream in) throws java.lang.Exception
java.lang.Exception
public long size()
public static java.lang.String flagsToString(short flags)
public static java.lang.String transientFlagsToString(short flags)
protected static void writeHeader(Header hdr, java.io.DataOutput out) throws java.lang.Exception
java.lang.Exception
protected static Header readHeader(java.io.DataInput in) throws java.lang.Exception
java.lang.Exception
protected static Header[] createHeaders(int size)
Copyright © 1998-2020 Red Hat. All Rights Reserved.