org.jgroups
public class Message extends Object implements 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.
Field Summary | |
---|---|
protected Address | dest_addr |
protected Map | headers Map |
protected int | length The number of bytes in the buffer (usually buf.length is buf not equal to null). |
protected static Log | log |
protected int | offset The index into the payload (usually 0) |
protected Address | src_addr |
Constructor Summary | |
---|---|
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, Serializable obj) Public constructor | |
Message() | |
Message(boolean create_headers) |
Method Summary | |
---|---|
protected 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() |
Header | getHeader(String key) |
Map | getHeaders() |
int | getLength() Returns the number of bytes in the buffer |
Object | getObject() |
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() |
Message | makeReply() |
String | printObjectHeaders() |
void | putHeader(String key, Header hdr) Puts a header given a key into the hashmap. |
void | readExternal(ObjectInput in) |
void | readFrom(DataInputStream in) |
Header | removeHeader(String key) |
void | removeHeaders() |
void | reset()
Nulls all fields of this message so that the message can be reused. |
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 | setObject(Serializable obj) |
void | setSrc(Address new_src) |
long | size()
Returns size of buffer, plus some constant overhead for src and dest, plus number of headers time
some estimated size/header. |
String | toString() |
String | toStringAsObject() Tries to read an object from the message's buffer and prints it |
void | writeExternal(ObjectOutput out) |
void | writeTo(DataOutputStream out)
Streams all members (dest and src addresses, buffer and headers) to the output stream. |
Parameters: dest Address of receiver. If it is null or a string, then
it is sent to the group (either to current group or to the group as given
in the string). If it is a Vector, then it contains a number of addresses
to which it must be sent. Otherwise, it contains a single destination.
Addresses are generally untyped (all are of type Object. A channel
instance must know what types of addresses it expects and downcast
accordingly.
Parameters: dest Address of receiver. If it is null or a string, then
it is sent to the group (either to current group or to the group as given
in the string). If it is a Vector, then it contains a number of addresses
to which it must be sent. Otherwise, it contains a single destination.
Addresses are generally untyped (all are of type Object. A channel
instance must know what types of addresses it expects and downcast
accordingly.
Parameters: dest Address of receiver. If it is null or a string, then
it is sent to the group (either to current group or to the group as given
in the string). If it is a Vector, then it contains a number of addresses
to which it must be sent. Otherwise, it contains a single destination.
Addresses are generally untyped (all are of type Object. A channel
instance must know what types of addresses it expects and downcast
accordingly.
Parameters: copy_buffer
Returns: Message with specified data
Returns: byte array with a copy of the buffer.
Parameters: b The reference to a given buffer. If null, we'll reset the buffer to null offset The initial position length The number of bytes
Size estimations don't have to be very accurate since this is mainly used by FRAG to determine whether to fragment a message or not. Fragmentation will then serialize the message, therefore getting the correct value.
Parameters: out
Throws: IOException