Package org.apache.cassandra.net
Class Message<T>
- java.lang.Object
-
- org.apache.cassandra.net.Message<T>
-
- Type Parameters:
T
- The type of the message payload.
public class Message<T> extends java.lang.Object
Immutable main unit of internode communication - what used to beMessageIn
andMessageOut
fused in one class.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Message.Builder<T>
static class
Message.Header
Split into a separate object to allow partial message deserialization without wasting work and allocation afterwards, if the entire message is necessary and available.static class
Message.InvalidLegacyProtocolMagic
static class
Message.Serializer
Each message contains a header with several fixed fields, an optional key-value params section, and then the message payload itself.
-
Field Summary
Fields Modifier and Type Field Description Message.Header
header
T
payload
static Message.Serializer
serializer
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T> Message.Builder<T>
builder(Message<T> message)
static <T> Message.Builder<T>
builder(Verb verb, T payload)
long
createdAtNanos()
Creation time of the message.long
creationTimeMillis()
long
elapsedSinceCreated(java.util.concurrent.TimeUnit units)
For how long the message has lived.Message<NoPayload>
emptyResponse()
Builds a response Message with no payload, and all the right fields inferred from request Messagelong
expiresAtNanos()
Message<RequestFailureReason>
failureResponse(RequestFailureReason reason)
Builds a failure response Message with an explicit reason, and fields inferred from request MessageForwardingInfo
forwardTo()
Used for cross-DC write optimisation - pick one node in the DC and have it relay the write to its local peersInetAddressAndPort
from()
Sender of the message.long
id()
id of the request/message.static <T> Message<T>
internalResponse(Verb verb, T payload)
boolean
isCrossNode()
Whether the message has crossed the node boundary, that is whether it originated from another node.boolean
isFailureResponse()
static <T> Message<T>
out(Verb verb, T payload)
Make a requestMessage
with supplied verb and payload.static <T> Message<T>
out(Verb verb, T payload, long expiresAtNanos)
static <T> Message<T>
outWithFlag(Verb verb, T payload, MessageFlag flag)
static <T> Message<T>
outWithFlags(Verb verb, T payload, MessageFlag flag1, MessageFlag flag2)
static <T> Message<T>
outWithFlags(Verb verb, T payload, Dispatcher.RequestTime requestTime, java.util.List<MessageFlag> flags)
static <T> Message<T>
remoteResponse(InetAddressAndPort from, Verb verb, T payload)
Used by theMultiRangeReadCommand
to split multi-range responses from a replica into single-range responses.InetAddressAndPort
respondTo()
The originator of the request - used when forwarding and will differ fromfrom()
<T> Message<T>
responseWith(T payload)
Builds a response Message with provided payload, and all the right fields inferred from request Messageint
serializedSize(int version)
Serialized size of the entire message, for the provided messaging version.static <T> Message<T>
synthetic(InetAddressAndPort from, Verb verb, T payload)
java.lang.String
toString()
TimeUUID
traceSession()
Tracing.TraceType
traceType()
boolean
trackRepairedData()
See CASSANDRA-14145boolean
trackWarnings()
Verb
verb()
Message<T>
withFlag(MessageFlag flag)
Message<T>
withForwardTo(ForwardingInfo peers)
Message<T>
withFrom(InetAddressAndPort from)
Message<T>
withParam(ParamType type, java.lang.Object value)
Message<T>
withParams(java.util.Map<ParamType,java.lang.Object> values)
<V> Message<V>
withPayload(V newPayload)
-
-
-
Field Detail
-
header
public final Message.Header header
-
payload
public final T payload
-
serializer
public static final Message.Serializer serializer
-
-
Method Detail
-
from
public InetAddressAndPort from()
Sender of the message.
-
isCrossNode
public boolean isCrossNode()
Whether the message has crossed the node boundary, that is whether it originated from another node.
-
id
public long id()
id of the request/message. In 4.0+ can be shared between multiple messages of the same logical request, whilst in versions above a new id would be allocated for each message sent.
-
verb
public Verb verb()
-
isFailureResponse
public boolean isFailureResponse()
-
createdAtNanos
public long createdAtNanos()
Creation time of the message. If cross-node timeouts are enabled (DatabaseDescriptor.hasCrossNodeTimeout()
,deserialize()
will use the marshalled value, otherwise will use current time on the deserializing machine.
-
expiresAtNanos
public long expiresAtNanos()
-
elapsedSinceCreated
public long elapsedSinceCreated(java.util.concurrent.TimeUnit units)
For how long the message has lived.
-
creationTimeMillis
public long creationTimeMillis()
-
trackWarnings
public boolean trackWarnings()
-
trackRepairedData
public boolean trackRepairedData()
See CASSANDRA-14145
-
forwardTo
@Nullable public ForwardingInfo forwardTo()
Used for cross-DC write optimisation - pick one node in the DC and have it relay the write to its local peers
-
respondTo
@Nullable public InetAddressAndPort respondTo()
The originator of the request - used when forwarding and will differ fromfrom()
-
traceSession
@Nullable public TimeUUID traceSession()
-
traceType
@Nullable public Tracing.TraceType traceType()
-
out
public static <T> Message<T> out(Verb verb, T payload)
Make a requestMessage
with supplied verb and payload. Will fill in remaining fields automatically. If you know that you will need to set some params or flags - prefer using variants ofout()
that allow providing them at point of message constructions, rather than allocating new messages with those added flags and params. SeeoutWithFlag()
,outWithFlags()
, andoutWithParam()
family.
-
synthetic
public static <T> Message<T> synthetic(InetAddressAndPort from, Verb verb, T payload)
-
outWithFlag
public static <T> Message<T> outWithFlag(Verb verb, T payload, MessageFlag flag)
-
outWithFlags
public static <T> Message<T> outWithFlags(Verb verb, T payload, MessageFlag flag1, MessageFlag flag2)
-
outWithFlags
public static <T> Message<T> outWithFlags(Verb verb, T payload, Dispatcher.RequestTime requestTime, java.util.List<MessageFlag> flags)
-
remoteResponse
public static <T> Message<T> remoteResponse(InetAddressAndPort from, Verb verb, T payload)
Used by theMultiRangeReadCommand
to split multi-range responses from a replica into single-range responses.
-
responseWith
public <T> Message<T> responseWith(T payload)
Builds a response Message with provided payload, and all the right fields inferred from request Message
-
emptyResponse
public Message<NoPayload> emptyResponse()
Builds a response Message with no payload, and all the right fields inferred from request Message
-
failureResponse
public Message<RequestFailureReason> failureResponse(RequestFailureReason reason)
Builds a failure response Message with an explicit reason, and fields inferred from request Message
-
withPayload
public <V> Message<V> withPayload(V newPayload)
-
withForwardTo
public Message<T> withForwardTo(ForwardingInfo peers)
-
withFrom
public Message<T> withFrom(InetAddressAndPort from)
-
withFlag
public Message<T> withFlag(MessageFlag flag)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
builder
public static <T> Message.Builder<T> builder(Message<T> message)
-
builder
public static <T> Message.Builder<T> builder(Verb verb, T payload)
-
serializedSize
public int serializedSize(int version)
Serialized size of the entire message, for the provided messaging version. Caches the calculated value.
-
-