Interface MatsStageInterceptor.StageCommonContext

All Superinterfaces:
MatsStageInterceptor.StageInterceptContext
All Known Subinterfaces:
MatsStageInterceptor.StageCompletedContext, MatsStageInterceptor.StageInterceptOutgoingMessageContext, MatsStageInterceptor.StageInterceptUserLambdaContext, MatsStageInterceptor.StageReceivedContext
Enclosing interface:
MatsStageInterceptor

public static interface MatsStageInterceptor.StageCommonContext extends MatsStageInterceptor.StageInterceptContext
Common context elements for stage interception, including all the incoming message/envelope data and metadata.

Remember: There are also lots of properties on the ProcessContext!

  • Method Details

    • putInterceptContextAttribute

      void putInterceptContextAttribute(String key, Object value)
      Set an attribute on this particular interception, which is shared between the different stages of interception, and also between all interceptors - use some namespacing to avoid accidental collisions. Use instead of ThreadLocals.
      Parameters:
      key - the key name for this intercept context attribute.
      value - the value which should be held.
    • getInterceptContextAttribute

      <T> T getInterceptContextAttribute(String key)
      Type Parameters:
      T - the type of this attribute, to avoid explicit casting - but you should really know the type, otherwise request Object.
      Parameters:
      key - the key name for this intercept context attribute.
      Returns:
      the intercept context attribute that was stored by putInterceptContextAttribute(String, Object), null if there is no such value.
    • getProcessContext

      Returns:
      the MatsEndpoint.DetachedProcessContext for the executing stage - this is overridden in several sub interfaces to return the actual "live" MatsEndpoint.ProcessContext.
    • getEndpointEnteredTimestamp

      Instant getEndpointEnteredTimestamp()
      Returns the timestamp when the initial stage of the Endpoint which this Stage belongs to, was entered. Use to calculate total endpoint time: If the result of a stage is MatsStageInterceptor.StageCompletedContext.ProcessResult.REPLY or MatsStageInterceptor.StageCompletedContext.ProcessResult.NONE, then the endpoint is finished, and the current time vs. endpoint entered timestamp (this method) is the total time this endpoint used.

      Note that this is susceptible to time skews between nodes: If the initial stage was run on node A, while this stage is run on node B, calculations on the timestamp returned from this method (from node A) vs. this node (B's) System.currentTimeMillis() is highly dependent on the time synchronization between node A and node B.

      Returns:
      the timestamp when the initial stage of the Endpoint which this Stage belongs to, was entered.
      See Also:
    • getPrecedingSameStackHeightOutgoingTimestamp

      Instant getPrecedingSameStackHeightOutgoingTimestamp()
      Returns the timestamp of the preceding outgoing message on the same stack height as this stage. Use to calculate "Time since previous Stage of same Endpoint", which includes queue times and processing times of requested endpoints happening in between the send and the receive, as well as any other latencies. For example, it is the time between when EndpointA.Stage2 performs a REQUEST to AnotherEndpointB, till the REPLY from that endpoint is received on EndpointA.Stage3 (There can potentially be dozens of message passing and processings in between those two stages (of the same endpoint), as AnotherEndpointB might itself have a dozen stages, each performing requests to yet other endpoints).

      Note that this is susceptible to time skews between nodes: If the preceding stage was run on node A, while this stage is run on node B, calculations on the timestamp returned from this method (from node A) vs. this node (B's) System.currentTimeMillis() is highly dependent on the time synchronization between node A and node B.

      Note: There is no preceding stage for a REQUEST to the Initial Stage of an Endpoint.

      Note: On a Terminator whose corresponding initiation did a REQUEST, the "same stack height" ends up being the initiator (it is stack height 0). If an initiation goes directly to a Terminator (e.g. "fire-and-forget" PUBLISH or SEND), again the "same stack height" is the initiator.

      Returns:
      The timestamp of the outgoing message on the same stack height as this stage. If the current Call is a REQUEST, there is no such message, and -1 is returned.
      See Also:
    • getIncomingMessageType

      MatsOutgoingMessage.MessageType getIncomingMessageType()
      Returns:
      the MatsOutgoingMessage.MessageType of the incoming message.
    • getIncomingState

      Optional<Object> getIncomingState()
      Returns:
      the incoming state (STO), if present (which it typically is for all stages except initial - albeit it is also possible to send state to the initial stage).
    • getStateSerializedSize

      int getStateSerializedSize()
      Returns:
      the number of units (bytes or characters) that the state (STO) serialized to. If getIncomingState() is Optional.empty(), then this method returns 0.
    • getIncomingData

      Object getIncomingData()
      Returns:
      the incoming data (DTO).
    • getDataSerializedSize

      int getDataSerializedSize()
      Returns:
      the number of units (bytes or characters) that the data (DTO) serialized to. (Null data might give 0 or 4, or really whatever else the serializer uses to represent null).
    • getIncomingSameStackHeightExtraState

      <T> Optional<T> getIncomingSameStackHeightExtraState(String key, Class<T> type)
      Returns:
      the extra-state, if any, on the incoming REPLY, NEXT or GOTO message - as set by MatsOutgoingMessage.MatsEditableOutgoingMessage.setSameStackHeightExtraState(String, Object).
    • getTotalPreprocessAndDeserializeNanos

      long getTotalPreprocessAndDeserializeNanos()
      Returns:
      the total time taken (in nanoseconds) from the reception of a message system message, via deconstruct; decompression; deserialization of envelope, message and state, to right before the invocation of the MatsStageInterceptor.stageReceived(StageReceivedContext); approx. the sum of the timings below.
    • getMessageSystemDeconstructNanos

      long getMessageSystemDeconstructNanos()
      Returns:
      time taken (in nanoseconds) to pick the pieces out of the message system message.
    • getEnvelopeWireSize

      int getEnvelopeWireSize()
      Returns:
      size (in bytes) of the envelope "on the wire", which often is compressed, which is picked out of the message system message in getMessageSystemDeconstructNanos(). If compression was not applied, returns the same value as getEnvelopeSerializedSize(). Note that the returned size is only the (compressed) Mats envelope, and does not include the size of the messaging system's message/envelope and any meta-data that Mats adds to this. This means that the message size on the wire will be larger.
    • getEnvelopeDecompressionNanos

      long getEnvelopeDecompressionNanos()
      Returns:
      time taken (in nanoseconds) to decompress the "on the wire" representation of the envelope. - will be 0 if no compression was applied, while it will return > 0 if compression was applied.
    • getEnvelopeSerializedSize

      int getEnvelopeSerializedSize()
      Returns:
      size (in bytes) of the serialized envelope - after decompression. Do read the JavaDoc of getEnvelopeWireSize() too, as the same applies here: This size only refers to the Mats envelope, not the messaging system's final message size.
    • getEnvelopeDeserializationNanos

      long getEnvelopeDeserializationNanos()
      Returns:
      time taken (in nanoseconds) to deserialize the envelope.
    • getDataAndStateDeserializationNanos

      long getDataAndStateDeserializationNanos()
      Returns:
      time taken (in nanoseconds) to deserialize the data (DTO) and state (STO) from the envelope, before invoking the user lambda with them.
    • getMessageSystemTotalWireSize

      default int getMessageSystemTotalWireSize()
      Returns:
      the number of bytes sent on the wire (best approximation), as far as Mats knows. Any overhead from the message system is unknown. Includes the envelope (which includes the TraceProperties), as well as the sideloads (bytes and strings). Implementation might add some more size for metadata. Notice that the strings are just "length()'ed", so any "exotic" characters are still just counted as 1 byte.