public abstract class Message extends Object
| Modifier | Constructor and Description |
|---|---|
protected |
Message(byte type,
ByteBuffer buf) |
protected |
Message(byte type,
int clusterId,
String senderId,
String recipientId,
long term) |
| Modifier and Type | Method and Description |
|---|---|
protected int |
calculateSize()
Calculate an upper bound on the number of bytes required by
writeTo(). |
protected static int |
calculateSize(ByteBuffer buf) |
protected static int |
calculateSize(String string) |
protected static int |
calculateSize(Timestamp timestamp) |
static Message |
decode(ByteBuffer buf)
Decode a message from the given input.
|
ByteBuffer |
encode()
Serialize this instance.
|
protected static boolean |
getBoolean(ByteBuffer buf)
Deserialize a boolean value previously serialized by
putBoolean() from the buffer. |
protected static ByteBuffer |
getByteBuffer(ByteBuffer buf)
Deserialize a
ByteBuffer previously serialized by putByteBuffer() from the buffer. |
int |
getClusterId()
Get the cluster ID of the sender.
|
protected static Reads |
getReads(ByteBuffer buf)
Deserialize a
Reads previously serialized by putReads() from the buffer. |
String |
getRecipientId()
Get the identity of the recipient.
|
String |
getSenderId()
Get the identity of the sender.
|
protected static String |
getString(ByteBuffer buf)
Deserialize a
String previously serialized by putString() from the buffer. |
long |
getTerm()
Get the term of the sender of this message.
|
protected static Timestamp |
getTimestamp(ByteBuffer buf)
Deserialize a
Timestamp value previously serialized by putTimestamp() from the buffer. |
protected static Writes |
getWrites(ByteBuffer buf)
Deserialize a
Writes previously serialized by putWrites() from the buffer. |
boolean |
isLeaderMessage()
Determine whether this message is only sent by leaders.
|
protected static void |
putBoolean(ByteBuffer dest,
boolean value)
Serialize a boolean value into the buffer.
|
protected static void |
putByteBuffer(ByteBuffer dest,
ByteBuffer buf)
Serialize a
ByteBuffer into the buffer. |
protected static void |
putReads(ByteBuffer dest,
Reads reads)
Serialize a
Reads into the buffer. |
protected static void |
putString(ByteBuffer dest,
String string)
Serialize a
String into the buffer. |
protected static void |
putTimestamp(ByteBuffer dest,
Timestamp timestamp)
Serialize a
Timestamp value into the buffer. |
protected static void |
putWrites(ByteBuffer dest,
Writes writes)
Serialize a
Writes into the buffer. |
abstract String |
toString() |
abstract void |
visit(MessageSwitch handler)
Apply the visitor pattern based on this instance's type.
|
void |
writeTo(ByteBuffer buf)
Serialize this instance into the given buffer.
|
protected Message(byte type,
ByteBuffer buf)
public int getClusterId()
public String getSenderId()
public String getRecipientId()
public long getTerm()
public boolean isLeaderMessage()
public abstract void visit(MessageSwitch handler)
handler - target for visitpublic static Message decode(ByteBuffer buf)
Note that data is not necessarily copied out of buf, so the returned instance may become invalid
if the data in buf gets overwritten.
buf - source for encoded messageBufferUnderflowException - if there is not enough dataIllegalArgumentException - if encoded message is bogusIllegalArgumentException - if there is trailing garbagepublic ByteBuffer encode()
public void writeTo(ByteBuffer buf)
buf - destination for encoded dataBufferOverflowException - if data overflows bufprotected int calculateSize()
writeTo().protected static void putByteBuffer(ByteBuffer dest, ByteBuffer buf)
ByteBuffer into the buffer.dest - destination for encoded databuf - data to encodeReadOnlyBufferException - if dest is read onlyBufferOverflowException - if dest overflowsIllegalArgumentException - if buf has more than 2^31 bytes remainingIllegalArgumentException - if either parameter is nullprotected static ByteBuffer getByteBuffer(ByteBuffer buf)
ByteBuffer previously serialized by putByteBuffer() from the buffer.buf - source for encoded dataBufferUnderflowException - if buf underflowsIllegalArgumentException - if input is bogusIllegalArgumentException - if buf is nullprotected static int calculateSize(ByteBuffer buf)
protected static void putString(ByteBuffer dest, String string)
String into the buffer.dest - destination for encoded datastring - string to encodeReadOnlyBufferException - if dest is read onlyBufferOverflowException - if dest overflowsIllegalArgumentException - if either parameter is nullprotected static String getString(ByteBuffer buf)
String previously serialized by putString() from the buffer.buf - source for encoded dataBufferUnderflowException - if buf underflowsIllegalArgumentException - if input is bogusprotected static int calculateSize(String string)
protected static void putBoolean(ByteBuffer dest, boolean value)
dest - destination for encoded datavalue - value to encodeReadOnlyBufferException - if dest is read onlyBufferOverflowException - if dest overflowsIllegalArgumentException - if dest is nullprotected static boolean getBoolean(ByteBuffer buf)
putBoolean() from the buffer.buf - source for encoded dataBufferUnderflowException - if buf underflowsIllegalArgumentException - if input is bogusprotected static void putTimestamp(ByteBuffer dest, Timestamp timestamp)
Timestamp value into the buffer.dest - destination for encoded datatimestamp - value to encodeReadOnlyBufferException - if dest is read onlyBufferOverflowException - if dest overflowsIllegalArgumentException - if dest or timestamp is nullprotected static Timestamp getTimestamp(ByteBuffer buf)
Timestamp value previously serialized by putTimestamp() from the buffer.buf - source for encoded dataBufferUnderflowException - if buf underflowsIllegalArgumentException - if input is bogusprotected static int calculateSize(Timestamp timestamp)
protected static void putReads(ByteBuffer dest, Reads reads)
Reads into the buffer.dest - destination for encoded datareads - value to encodeReadOnlyBufferException - if dest is read onlyBufferOverflowException - if dest overflowsIllegalArgumentException - if either parameter is nullprotected static Reads getReads(ByteBuffer buf)
Reads previously serialized by putReads() from the buffer.buf - source for encoded dataBufferUnderflowException - if buf underflowsprotected static void putWrites(ByteBuffer dest, Writes writes)
Writes into the buffer.dest - destination for encoded datawrites - value to encodeReadOnlyBufferException - if dest is read onlyBufferOverflowException - if dest overflowsIllegalArgumentException - if either parameter is nullprotected static Writes getWrites(ByteBuffer buf)
Writes previously serialized by putWrites() from the buffer.buf - source for encoded dataBufferUnderflowException - if buf underflowsCopyright © 2016. All rights reserved.