Class 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 be MessageIn and MessageOut fused in one class.
    • Method Detail

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

        @Nullable
        public TimeUUID traceSession()
      • 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.
      • out

        public static <T> Message<T> out​(Verb verb,
                                         T payload,
                                         long expiresAtNanos)
      • 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
      • withPayload

        public <V> Message<V> withPayload​(V newPayload)
      • withParam

        public Message<T> withParam​(ParamType type,
                                    java.lang.Object value)
      • withParams

        public Message<T> withParams​(java.util.Map<ParamType,​java.lang.Object> values)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • serializedSize

        public int serializedSize​(int version)
        Serialized size of the entire message, for the provided messaging version. Caches the calculated value.