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 Object
Immutable main unit of internode communication - what used to be MessageIn and MessageOut fused in one class.
  • Field Details

  • Method Details

    • 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(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 from from()
    • traceSession

      @Nullable public TimeUUID traceSession()
    • traceType

      @Nullable public Tracing.TraceType traceType()
    • out

      public static <T> Message<T> out(Verb verb, T payload)
      Make a request Message 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 of out() that allow providing them at point of message constructions, rather than allocating new messages with those added flags and params. See outWithFlag(), outWithFlags(), and outWithParam() family.
    • synthetic

      public static <T> Message<T> synthetic(InetAddressAndPort from, Verb verb, T payload)
    • out

      public static <T> Message<T> out(Verb verb, T payload, long expiresAtNanos)
    • 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, List<MessageFlag> flags)
    • internalResponse

      public static <T> Message<T> internalResponse(Verb verb, T payload)
    • remoteResponse

      public static <T> Message<T> remoteResponse(InetAddressAndPort from, Verb verb, T payload)
      Used by the MultiRangeReadCommand 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)
    • withParam

      public Message<T> withParam(ParamType type, Object value)
    • withParams

      public Message<T> withParams(Map<ParamType,Object> values)
    • toString

      public String toString()
      Overrides:
      toString in class 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.