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.ObjectImmutable main unit of internode communication - what used to beMessageInandMessageOutfused in one class.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMessage.Builder<T>static classMessage.HeaderSplit into a separate object to allow partial message deserialization without wasting work and allocation afterwards, if the entire message is necessary and available.static classMessage.InvalidLegacyProtocolMagicstatic classMessage.SerializerEach 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.HeaderheaderTpayloadstatic Message.Serializerserializer
-
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)longcreatedAtNanos()Creation time of the message.longcreationTimeMillis()longelapsedSinceCreated(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 MessagelongexpiresAtNanos()Message<RequestFailureReason>failureResponse(RequestFailureReason reason)Builds a failure response Message with an explicit reason, and fields inferred from request MessageForwardingInfoforwardTo()Used for cross-DC write optimisation - pick one node in the DC and have it relay the write to its local peersInetAddressAndPortfrom()Sender of the message.longid()id of the request/message.static <T> Message<T>internalResponse(Verb verb, T payload)booleanisCrossNode()Whether the message has crossed the node boundary, that is whether it originated from another node.static <T> Message<T>out(Verb verb, T payload)Make a requestMessagewith 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 theMultiRangeReadCommandto split multi-range responses from a replica into single-range responses.InetAddressAndPortrespondTo()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 MessageintserializedSize(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.StringtoString()TimeUUIDtraceSession()Tracing.TraceTypetraceType()booleantrackRepairedData()See CASSANDRA-14145booleantrackWarnings()Verbverb()Message<T>withFlag(MessageFlag flag)Message<T>withForwardTo(ForwardingInfo peers)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()
-
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 requestMessagewith 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 theMultiRangeReadCommandto 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)
-
withFlag
public Message<T> withFlag(MessageFlag flag)
-
toString
public java.lang.String toString()
- Overrides:
toStringin 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.
-
-