Class AbstractMessage
- java.lang.Object
-
- org.apache.hugegraph.computer.core.network.message.AbstractMessage
-
- All Implemented Interfaces:
Message
- Direct Known Subclasses:
AckMessage,DataMessage,FailMessage,FinishMessage,PingMessage,PongMessage,StartMessage
public abstract class AbstractMessage extends java.lang.Object implements Message
Abstract class for messages which optionally contain sequenceNumber, partition, body.HugeGraph:// 0 2 3 4 +---------------------------------------------------+ 0 | magic 2byte | version 1byte | message-type 1byte | +---------------------------------------------------+ 4 | sequence-number 4byte | +---------------------------------------------------+ 8 | partition 4byte | +---------------------------------------------------+ 12 | body-length 4byte | +---------------------------------------------------+ 16 | body-content(length: body-length) | +---------------------------------------------------+
-
-
Field Summary
Fields Modifier and Type Field Description static intHEADER_LENGTHstatic intLENGTH_BODY_LENGTHstatic shortMAGIC_NUMBERstatic intMAX_MESSAGE_LENGTHstatic intOFFSET_BODY_LENGTHstatic bytePROTOCOL_VERSIONstatic intSTART_SEQstatic intUNKNOWN_SEQ
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractMessage()protectedAbstractMessage(int sequenceNumber)protectedAbstractMessage(int sequenceNumber, int partition)protectedAbstractMessage(int sequenceNumber, int partition, NetworkBuffer body)protectedAbstractMessage(int sequenceNumber, NetworkBuffer body)protectedAbstractMessage(NetworkBuffer body)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static voidassertExtraHeader(io.netty.buffer.ByteBuf buf)NetworkBufferbody()An optional body for the message.NetworkBufferencode(io.netty.buffer.ByteBuf buf)Serializes this object by writing into the given ByteBuf.protected NetworkBufferencodeBody(io.netty.buffer.ByteBuf buf)Only serializes the body of this message by writing into the given ByteBuf or return the body buffer.protected voidencodeHeader(io.netty.buffer.ByteBuf buf)Only serializes the header of this message by writing into the given ByteBuf.booleanhasBody()Whether to include the body of the message in the same frame as the message.intpartition()The partition idvoidrelease()Release the messageintsequenceNumber()The message sequence numberjava.lang.StringtoString()
-
-
-
Field Detail
-
HEADER_LENGTH
public static final int HEADER_LENGTH
- See Also:
- Constant Field Values
-
OFFSET_BODY_LENGTH
public static final int OFFSET_BODY_LENGTH
- See Also:
- Constant Field Values
-
LENGTH_BODY_LENGTH
public static final int LENGTH_BODY_LENGTH
- See Also:
- Constant Field Values
-
MAX_MESSAGE_LENGTH
public static final int MAX_MESSAGE_LENGTH
- See Also:
- Constant Field Values
-
MAGIC_NUMBER
public static final short MAGIC_NUMBER
- See Also:
- Constant Field Values
-
PROTOCOL_VERSION
public static final byte PROTOCOL_VERSION
- See Also:
- Constant Field Values
-
UNKNOWN_SEQ
public static final int UNKNOWN_SEQ
- See Also:
- Constant Field Values
-
START_SEQ
public static final int START_SEQ
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AbstractMessage
protected AbstractMessage()
-
AbstractMessage
protected AbstractMessage(int sequenceNumber)
-
AbstractMessage
protected AbstractMessage(int sequenceNumber, int partition)
-
AbstractMessage
protected AbstractMessage(int sequenceNumber, NetworkBuffer body)
-
AbstractMessage
protected AbstractMessage(NetworkBuffer body)
-
AbstractMessage
protected AbstractMessage(int sequenceNumber, int partition, NetworkBuffer body)
-
-
Method Detail
-
encode
public NetworkBuffer encode(io.netty.buffer.ByteBuf buf)
Description copied from interface:MessageSerializes this object by writing into the given ByteBuf.- Specified by:
encodein interfaceMessage- Parameters:
buf-ByteBufthe header buffer, if use zero-copy. Otherwise it will contain header and body.- Returns:
NetworkBufferbody buffer, if use zero-copy
-
encodeHeader
protected void encodeHeader(io.netty.buffer.ByteBuf buf)
Only serializes the header of this message by writing into the given ByteBuf.
-
encodeBody
protected NetworkBuffer encodeBody(io.netty.buffer.ByteBuf buf)
Only serializes the body of this message by writing into the given ByteBuf or return the body buffer.
-
sequenceNumber
public int sequenceNumber()
Description copied from interface:MessageThe message sequence number- Specified by:
sequenceNumberin interfaceMessage
-
partition
public int partition()
Description copied from interface:MessageThe partition id
-
hasBody
public boolean hasBody()
Description copied from interface:MessageWhether to include the body of the message in the same frame as the message.
-
body
public NetworkBuffer body()
Description copied from interface:MessageAn optional body for the message.
-
release
public void release()
Description copied from interface:MessageRelease the message
-
assertExtraHeader
protected static void assertExtraHeader(io.netty.buffer.ByteBuf buf)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-