public abstract class Message extends Object
Modifier | Constructor and Description |
---|---|
protected |
Message(byte type,
ByteBuffer buf,
int version) |
protected |
Message(byte type,
int clusterId,
String senderId,
String recipientId,
long term) |
Modifier and Type | Method and Description |
---|---|
protected static int |
calculateSize(ByteBuffer buf) |
protected int |
calculateSize(int version)
Calculate an upper bound on the number of bytes required by
writeTo() . |
protected static int |
calculateSize(String string) |
protected static int |
calculateSize(Timestamp timestamp,
int version) |
static Message |
decode(ByteBuffer buf,
int version)
Decode a message from the given input.
|
static int |
decodeProtocolVersion(ByteBuffer buf)
Read the protocol version number header from the message encoded in the given input.
|
ByteBuffer |
encode(int version)
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.
|
static int |
getCurrentProtocolVersion()
Get the current (i.e., maximum known) protocol version number.
|
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,
int version)
Deserialize a
Timestamp value previously serialized by putTimestamp() 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 |
putString(ByteBuffer dest,
String string)
Serialize a
String into the buffer. |
protected static void |
putTimestamp(ByteBuffer dest,
Timestamp timestamp,
int version)
Serialize a
Timestamp value 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,
int version)
Serialize this instance into the given buffer.
|
protected Message(byte type, ByteBuffer buf, int version)
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 int getCurrentProtocolVersion()
public static int decodeProtocolVersion(ByteBuffer buf)
buf
- source for encoded messagepublic static Message decode(ByteBuffer buf, int version)
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 messageversion
- message versionBufferUnderflowException
- if there is not enough dataIllegalArgumentException
- if version
is bogusIllegalArgumentException
- if encoded message is bogusIllegalArgumentException
- if there is trailing garbagepublic ByteBuffer encode(int version)
version
- protocol encoding version numberIllegalArgumentException
- if version
is boguspublic void writeTo(ByteBuffer buf, int version)
buf
- destination for encoded dataversion
- protocol encoding version numberBufferOverflowException
- if data overflows buf
IllegalArgumentException
- if version
is bogusprotected int calculateSize(int version)
writeTo()
.version
- protocol encoding versionprotected 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, int version)
Timestamp
value into the buffer.dest
- destination for encoded datatimestamp
- value to encodeversion
- protocol encoding versionReadOnlyBufferException
- if dest
is read onlyBufferOverflowException
- if dest
overflowsIllegalArgumentException
- if dest
or timestamp
is nullprotected static Timestamp getTimestamp(ByteBuffer buf, int version)
Timestamp
value previously serialized by putTimestamp()
from the buffer.buf
- source for encoded dataversion
- protocol encoding versionBufferUnderflowException
- if buf
underflowsIllegalArgumentException
- if input is bogusprotected static int calculateSize(Timestamp timestamp, int version)
Copyright © 2022. All rights reserved.