public class MatsTraceFieldImpl<Z> extends java.lang.Object implements MatsTrace<Z>, java.lang.Cloneable
MatsTrace
which uses fields to hold all state necessary for a Mats flow, including
"holders" for the serialization of DTOs and STOs, with type 'Z'. It is meant to be "field-serialized", thus the field
names are short. The most relevant types of Z are String and byte[], using e.g. JSON or Smile for serializing the
DTOs and STOs payloads, but it might be relevant to use a container/holder type too. You should create an extension
of this class to set the type. In 'mats-serial-json', a MatsTraceStringImpl
variant exists.Modifier and Type | Class and Description |
---|---|
static class |
MatsTraceFieldImpl.CallImpl<Z>
Represents an entry in the
MatsTrace . |
MatsTrace.Call<Z>, MatsTrace.KeepMatsTrace, MatsTrace.StackState<Z>
Modifier | Constructor and Description |
---|---|
protected |
MatsTraceFieldImpl() |
protected |
MatsTraceFieldImpl(java.lang.String traceId,
java.lang.String flowId,
MatsTrace.KeepMatsTrace keepMatsTrace,
boolean nonPersistent,
boolean interactive,
long ttlMillis,
boolean noAudit) |
Modifier and Type | Method and Description |
---|---|
MatsTrace<Z> |
addGotoCall(java.lang.String from,
java.lang.String to,
Z data,
Z initialState) |
MatsTraceFieldImpl<Z> |
addNextCall(java.lang.String from,
java.lang.String to,
Z data,
Z state)
Adds a
NEXT Call, which is a "skip call" to the next stage in a multistage service, as
opposed to the normal request out to a service expecting a reply. |
MatsTraceFieldImpl<Z> |
addReplyCall(java.lang.String from,
Z data)
Adds a
REPLY Call, which happens when a requested service is finished with its
processing and have some Reply to return. |
MatsTraceFieldImpl<Z> |
addRequestCall(java.lang.String from,
java.lang.String to,
MatsTrace.Call.MessagingModel toMessagingModel,
java.lang.String replyTo,
MatsTrace.Call.MessagingModel replyToMessagingModel,
Z data,
Z replyState,
Z initialState)
Adds a
REQUEST Call, which is an invocation of a service where one expects a Reply
from this service to go to a specified endpoint, typically the next stage in a multi-stage endpoint: Envision a
normal invocation of some method that returns a value. |
MatsTraceFieldImpl<Z> |
addSendCall(java.lang.String from,
java.lang.String to,
MatsTrace.Call.MessagingModel toMessagingModel,
Z data,
Z initialState)
Adds a
SEND Call, meaning a "request" which do not expect a Reply: Envision an
invocation of a void-method. |
protected MatsTraceFieldImpl<Z> |
cloneForNewCall()
Takes into account the KeepMatsTrace value.
|
java.util.List<MatsTrace.Call<Z>> |
getCallFlow() |
int |
getCallNumber() |
MatsTraceFieldImpl.CallImpl<Z> |
getCurrentCall() |
long |
getCurrentSpanId() |
java.util.Optional<MatsTrace.StackState<Z>> |
getCurrentState()
Returns the
MatsTrace.StackState for the MatsTrace.getCurrentCall() , if present. |
java.lang.String |
getDebugInfo() |
java.lang.String |
getFlowId() |
long |
getInitializedTimestamp() |
java.lang.String |
getInitializingAppName() |
java.lang.String |
getInitializingAppVersion() |
java.lang.String |
getInitializingHost() |
java.lang.String |
getInitiatorId() |
MatsTrace.KeepMatsTrace |
getKeepTrace() |
java.lang.String |
getParentMatsMessageId()
If this is a
child flow of an existing flow, this should return the
MatsMessageId of the message whose processing spawned this new flow. |
long |
getSameHeightEndpointEnteredTimestamp() |
long |
getSameHeightOutgoingTimestamp() |
java.util.List<MatsTrace.StackState<Z>> |
getStateFlow() |
java.util.List<io.mats3.serial.impl.MatsTraceFieldImpl.StackStateImpl<Z>> |
getStateStack_internal() |
java.util.List<MatsTrace.StackState<Z>> |
getStateStack() |
long |
getTimeToLive() |
int |
getTotalCallNumber()
"Stack overflow protection" mechanism.
|
java.lang.String |
getTraceId() |
Z |
getTraceProperty(java.lang.String propertyName)
Retrieves a property value set by
MatsTrace.setTraceProperty(String, Object) , refer to
ProcessContext.getTraceProperty(String, Class) . |
java.util.Set<java.lang.String> |
getTracePropertyKeys() |
boolean |
isInteractive() |
boolean |
isNoAudit() |
boolean |
isNonPersistent() |
void |
overrideInitializationTimestamp(long timestamp)
NOTICE! This is NOT meant for public usage!
|
void |
setOutgoingTimestamp(long timestamp)
Shall be invoked after adding the outgoing call, immediately before serializing the outgoing MatsTrace.
|
void |
setStageEnteredTimestamp(long timestamp)
Invoke this as early as possible on the reception of a message.
|
void |
setTraceProperty(java.lang.String propertyName,
Z propertyValue)
Sets a trace property, refer to
ProcessContext.setTraceProperty(String, Object) . |
java.lang.String |
toString()
MatsTraceStringImpl.toString().
|
MatsTrace<Z> |
withChildFlow(java.lang.String parentMatsMessageId,
int totalCallNumber)
If this newly created MatsTrace is a child-flow (initiated within a Stage) of an existing flow, then this method
should be invoked to set the parent MatsMessageId, and the "total call number" which is a "Call Overflow
protection" mechanism.
|
MatsTrace<Z> |
withDebugInfo(java.lang.String initializingAppName,
java.lang.String initializingAppVersion,
java.lang.String initializingHost,
java.lang.String initiatorId,
java.lang.String debugInfo)
Can only be set once..
|
protected MatsTraceFieldImpl()
protected MatsTraceFieldImpl(java.lang.String traceId, java.lang.String flowId, MatsTrace.KeepMatsTrace keepMatsTrace, boolean nonPersistent, boolean interactive, long ttlMillis, boolean noAudit)
public MatsTrace<Z> withDebugInfo(java.lang.String initializingAppName, java.lang.String initializingAppVersion, java.lang.String initializingHost, java.lang.String initiatorId, java.lang.String debugInfo)
MatsTrace
withDebugInfo
in interface MatsTrace<Z>
initiatorId
- the id set using matsInitiate.from(initiatorId)
- it is not the name of the initiator.this
, for chaining. Note that this is opposed to the add[Request|Send|Next|Reply]Call(..)
methods, which return a new, independent instance.public MatsTrace<Z> withChildFlow(java.lang.String parentMatsMessageId, int totalCallNumber)
MatsTrace
MatsTrace.getTotalCallNumber()
. If this message is initiated within an
existing call flow, set to the current call's MatsTrace.getTotalCallNumber()
+ 1. This number will increase for
every subsequent call this flow is going through, just as with MatsTrace.getCallNumber()
- the difference being
that it should continue increasing if a new message is initiated within a flow. Thereby it is possible to
stop an out-of-control initiate-send/request recursion, by checking that the MatsTrace.getTotalCallNumber()
doesn't ever go above a fixed number, e.g. 100.withChildFlow
in interface MatsTrace<Z>
parentMatsMessageId
- the MatsMessageId of the message whose processing spawned this new flow.totalCallNumber
- the MatsTrace.getTotalCallNumber()
to initialize this MatsTrace with.this
, for chaining. Note that this is opposed to the add[Request|Send|Next|Reply]Call(..)
methods, which return a new, independent instance.public void overrideInitializationTimestamp(long timestamp)
public java.lang.String getTraceId()
getTraceId
in interface MatsTrace<Z>
MatsTrace
was initiated with - this is set once, at initiation time, and
follows the processing till it terminates. (All log lines will have the traceId set on the MDC.)public java.lang.String getFlowId()
getFlowId
in interface MatsTrace<Z>
MatsTrace.Call.getMatsMessageId()
, separated by a "_".public long getInitializedTimestamp()
getInitializedTimestamp
in interface MatsTrace<Z>
public MatsTrace.KeepMatsTrace getKeepTrace()
getKeepTrace
in interface MatsTrace<Z>
MatsTrace.KeepMatsTrace.COMPACT
.public boolean isNonPersistent()
isNonPersistent
in interface MatsTrace<Z>
false
(i.e. persistent,
reliable).public boolean isInteractive()
isInteractive
in interface MatsTrace<Z>
false
.public long getTimeToLive()
getTimeToLive
in interface MatsTrace<Z>
public boolean isNoAudit()
isNoAudit
in interface MatsTrace<Z>
public java.lang.String getInitializingAppName()
getInitializingAppName
in interface MatsTrace<Z>
public java.lang.String getInitializingAppVersion()
getInitializingAppVersion
in interface MatsTrace<Z>
public java.lang.String getInitializingHost()
getInitializingHost
in interface MatsTrace<Z>
public java.lang.String getInitiatorId()
getInitiatorId
in interface MatsTrace<Z>
MatsInitiator.MatsInitiate.from(String)
.public java.lang.String getDebugInfo()
getDebugInfo
in interface MatsTrace<Z>
public int getCallNumber()
getCallNumber
in interface MatsTrace<Z>
MatsTrace.add[Request|Next|Reply..](..)
has been invoked on this MatsTrace. This means that right after
a new MatsTrace has been created, before a call has been added, 0 is returned. With KeepMatsTrace at
FULL
or COMPACT
, the returned number will be the
same as MatsTrace.getCallFlow()
.size(), but with MINIMAL
, that number of
always 1, but this number will still return the number of calls that has been added through the flow.MatsTrace.getTotalCallNumber()
public int getTotalCallNumber()
MatsTrace
getTotalCallNumber
in interface MatsTrace<Z>
MatsTrace.getCallNumber()
unless this flow was
initiated within a stage, in which case the totalCallNumber starts at the current call number at that
stage (as set with MatsTrace.withChildFlow(String, int)
). This ensures that if we end up with e.g. a mats
flow initiating a new mats flow to itself, thus creating a loop, this number will continuously increase,
and we can thus break out at some obviously-too-large value.public java.lang.String getParentMatsMessageId()
MatsTrace
child flow
of an existing flow, this should return the
MatsMessageId of the message whose processing spawned this new flow.getParentMatsMessageId
in interface MatsTrace<Z>
public void setTraceProperty(java.lang.String propertyName, Z propertyValue)
MatsTrace
ProcessContext.setTraceProperty(String, Object)
. Notice that on the
MatsTrace-side, the value must be of type Z
.setTraceProperty
in interface MatsTrace<Z>
propertyName
- the name of the property.propertyValue
- the value of the property.MatsTrace.getTracePropertyKeys()
,
MatsTrace.getTraceProperty(String)
public Z getTraceProperty(java.lang.String propertyName)
MatsTrace
MatsTrace.setTraceProperty(String, Object)
, refer to
ProcessContext.getTraceProperty(String, Class)
. Notice that on the MatsTrace-side, the value is of
type Z
.getTraceProperty
in interface MatsTrace<Z>
propertyName
- the name of the property to retrieve.MatsTrace.setTraceProperty(String, Object)
,
MatsTrace.getTracePropertyKeys()
public java.util.Set<java.lang.String> getTracePropertyKeys()
getTracePropertyKeys
in interface MatsTrace<Z>
trace properties
.MatsTrace.getTraceProperty(String)
,
MatsTrace.setTraceProperty(String, Object)
public MatsTraceFieldImpl<Z> addRequestCall(java.lang.String from, java.lang.String to, MatsTrace.Call.MessagingModel toMessagingModel, java.lang.String replyTo, MatsTrace.Call.MessagingModel replyToMessagingModel, Z data, Z replyState, Z initialState)
MatsTrace
REQUEST
Call, which is an invocation of a service where one expects a Reply
from this service to go to a specified endpoint, typically the next stage in a multi-stage endpoint: Envision a
normal invocation of some method that returns a value.addRequestCall
in interface MatsTrace<Z>
from
- which stageId this request is for. This is solely meant for monitoring and debugging - the protocol
does not need the from specifier, as this is not where any replies go to.to
- which endpoint that should get the request.toMessagingModel
- the MatsTrace.Call.MessagingModel
of 'to'.replyTo
- which endpoint that should get the reply from the requested endpoint.replyToMessagingModel
- the MatsTrace.Call.MessagingModel
of 'replyTo'.data
- the request data, most often a JSON representing the Request Data Transfer Object that the requested
service expects to get.replyState
- the state data for the stageId that gets the reply to this request, that is, the state for the stageId
that is at the first element of the replyStack. Most often a JSON representing the State Transfer
Object for the multi-stage endpoint.initialState
- an optional feature, whereby the state can be set for the initial stage of the requested endpoint.
Same stuff as replyState.public MatsTraceFieldImpl<Z> addSendCall(java.lang.String from, java.lang.String to, MatsTrace.Call.MessagingModel toMessagingModel, Z data, Z initialState)
MatsTrace
SEND
Call, meaning a "request" which do not expect a Reply: Envision an
invocation of a void-method. Or an invocation of some method that returns the value, but where you invoke it as a
void-method (i.e. not storing the result, e.g. the method map.remove("test")
returns the removed
value, but is often invoked without storing this.).addSendCall
in interface MatsTrace<Z>
from
- which stageId this request is for. This is solely meant for monitoring and debugging - the protocol
does not need the from specifier, as this is not where any replies go to.to
- which endpoint that should get the message.toMessagingModel
- the MatsTrace.Call.MessagingModel
of 'to'.data
- the request data, most often a JSON representing the Request Data Transfer Object that the receiving
service expects to get.initialState
- an optional feature, whereby the state can be set for the initial stage of the requested endpoint.public MatsTraceFieldImpl<Z> addNextCall(java.lang.String from, java.lang.String to, Z data, Z state)
MatsTrace
NEXT
Call, which is a "skip call" to the next stage in a multistage service, as
opposed to the normal request out to a service expecting a reply. The functionality is functionally identical to
#addSendCall(String, String, MessagingModel, Object, Object)
addSendCall(...)}, but has its own
CallType
enum value NEXT
.
Note: Cannot specify MatsTrace.Call.MessagingModel
here, as one cannot fathom where that would make sense: It must be
QUEUE
.addNextCall
in interface MatsTrace<Z>
from
- which stageId this request is for. This is solely meant for monitoring and debugging - the protocol
does not need the from specifier, as this is not where any replies go to.to
- which endpoint that should get the message - the next stage in a multi-stage service.data
- the request data, most often a JSON representing the Request Data Transfer Object that the next stage
expects to get.state
- the state data for the next stage.public MatsTraceFieldImpl<Z> addReplyCall(java.lang.String from, Z data)
MatsTrace
REPLY
Call, which happens when a requested service is finished with its
processing and have some Reply to return. This method pops the stack (takes the last element) from the (previous)
current call, sets this as the "to" parameter, and uses the rest of the list as the stack for the next Call.addReplyCall
in interface MatsTrace<Z>
from
- which stageId this request is for. This is solely meant for monitoring and debugging - the protocol
does not need the from specifier, as this is not where any replies go to.data
- the request data, most often a JSON representing the Request Data Transfer Object that the requesting
service expects to get.public MatsTrace<Z> addGotoCall(java.lang.String from, java.lang.String to, Z data, Z initialState)
addGotoCall
in interface MatsTrace<Z>
data
- the request data, most often a JSON representing the Request Data Transfer Object that the passed-to
endpoint expects to get.initialState
- an optional feature, whereby the state can be set for the initial stage of the requested endpoint.public void setOutgoingTimestamp(long timestamp)
MatsTrace
MatsTrace.Call.getCalledTimestamp()
to be more closely aligned to the exact sending
time. (For example, the message may have been constructed, then a massive SQL query was performed, and then a new
message is constructed, and then the messages are actually turned into JMS messages and committed on the wire.
This means that the first message will have a much earlier timestamp than the second.) Using this method, all
outgoing messages can have the Called Timestamp set right before it is serialized and JMS-constructed and
committed.MatsTrace.getCurrentCall()
is a REQUEST, SEND, GOTO or PUBLISH (anything else than REPLY), it also sets
the same-height-called-timestamp, recorded on the stackframe below it, or on the MatsTrace itself if there is no
stackframe below (initial SEND). This is to be able to calculate the "time between stages" for the e.g. time
between stage1 and stage2 of a multi-stage endpoint, noting that this might entail multiple levels of Request and
Replies (thus it must reside on the stack).setOutgoingTimestamp
in interface MatsTrace<Z>
public long getSameHeightOutgoingTimestamp()
getSameHeightOutgoingTimestamp
in interface MatsTrace<Z>
MatsTrace.setOutgoingTimestamp(long)
for the preceding call on the same stack height.
Used to calculate the "time between stages" for the different stages on an endpoint. It does not make
sense to get this for the initial stage of an Endpoint if the incoming is a REQUEST, and the return value
will then be -1
.public void setStageEnteredTimestamp(long timestamp)
MatsTrace
setStageEnteredTimestamp
in interface MatsTrace<Z>
public long getSameHeightEndpointEnteredTimestamp()
getSameHeightEndpointEnteredTimestamp
in interface MatsTrace<Z>
MatsTrace.setStageEnteredTimestamp(long)
for the stages of the same endpoint. Used to
calculate the "total endpoint time", through all stages, when the endpoint Replies, or stops (no outgoing
message).public long getCurrentSpanId()
getCurrentSpanId
in interface MatsTrace<Z>
FlowId
. Otherwise, it is the topmost element of an internal stack, in the same way as
MatsTrace.getCurrentCall()
.MatsTrace.Call.getReplyStack()
.public MatsTraceFieldImpl.CallImpl<Z> getCurrentCall()
public java.util.List<MatsTrace.Call<Z>> getCallFlow()
getCallFlow
in interface MatsTrace<Z>
current call
-
unless KeepTrace
is MINIMAL, in which case only the current call is present in
the list.public java.util.Optional<MatsTrace.StackState<Z>> getCurrentState()
MatsTrace
MatsTrace.StackState
for the MatsTrace.getCurrentCall()
, if present.
Searches in the 'State Flow'
from the back (most recent) for the first element that is at
the current stack height, as defined by MatsTrace.getCurrentCall()
.MatsTrace.Call.getReplyStackHeight()
. If a more
shallow stackDepth than the specified is encountered, or the list is exhausted without the Stack Height being
found, the search is terminated with null. This happens for the initial stage for an endpoint, unless the
'initialState' was set on the SEND or REQUEST.
The point of the 'State Flow' is the same as for the Call list: Monitoring and debugging, by keeping a history of
all calls in the processing, along with the states that was present at each call point.
If "condensing" is on (COMPACT
or MINIMAL
), the
stack-state-list is - by the condensing algorithm - turned in to a pure stack (as available via
MatsTrace.getStateStack()
), with the StackState for the earliest stack element at position 0, while the latest
(current) at end of list. The above-specified search algorithm still works, as it now will either find the
element with the correct stack depth at the end of the list, or it is not there.
NOTE: The StateStack (mostly) includes a frame for the current call, as opposed to the
MatsTrace.Call.getReplyStack()
(reply stack), which only includes frames below us. Note that as a matter of
avoiding space use, on a REQUEST call, the StackState is not added for the actual REQUEST message's state stack,
unless the "initial incoming state" is supplied (which is uncommon - a service invocation typically starts with
an empty state). However, on REPLY messages, it will always be present, and hence the state stack is typically
one level higher (includes current frame) than the reply stack (only includes frames below).
NOTE: As further info on how the state stack relates to the reply stack height: When a REPLY comes to a
terminator, there are 0 more frames below. However, the terminator needs its state, which is at state stack
height 0.getCurrentState
in interface MatsTrace<Z>
MatsTrace.StackState
for the MatsTrace.getCurrentCall()
if it exists, null
otherwise, as is
typical when entering initial stage of an endpoint.public java.util.List<MatsTrace.StackState<Z>> getStateFlow()
getStateFlow
in interface MatsTrace<Z>
MatsTrace.KeepMatsTrace
is
COMPACT or MINIMAL, then it will be a pure stack (as returned with MatsTrace.getStateStack()
, with the
last element being the most recent stack frame. NOTICE: The index position in this list has little to do
with which stack level the state refers to. This must be gotten from MatsTrace.StackState.getHeight()
.for more information on how the "State Flow" works.
public java.util.List<MatsTrace.StackState<Z>> getStateStack()
getStateStack
in interface MatsTrace<Z>
for more information on how the "State Flow" works.
public java.util.List<io.mats3.serial.impl.MatsTraceFieldImpl.StackStateImpl<Z>> getStateStack_internal()
protected MatsTraceFieldImpl<Z> cloneForNewCall()
public java.lang.String toString()
toString
in class java.lang.Object