public interface MatsInitiateInterceptor
MatsInterceptable.addInitiationInterceptor(MatsInitiateInterceptor)
.
Meant for intercepting initiations with ability to modify the initiation, and to implement extra logging and metrics
gathering.
When more than one interceptor is installed, the ordering becomes interesting. If the following class is added twice,
first with 1 as the argument, and then secondly with 2 as the argument ..:
private static class MyMatsInitiateInterceptor implements MatsInitiateInterceptor { private final int _number; MyMatsInitiateInterceptor(int number) { _number = number; } @Override public void initiateStarted(InitiateStartedContext initiateStartedContext) { log.info("Started #" + _number); } @Override public void initiateIntercept(InitiateInterceptContext initiateInterceptContext, InitiateLambda initiateLambda, MatsInitiate matsInitiate) { log.info("Intercept pre #" + _number); // Wrap the MatsInitiate to catch "send(dto)", before invoking the lambda MatsInitiateWrapper wrappedMatsInitiate = new MatsInitiateWrapper(matsInitiate) { @Override public MessageReference send(Object messageDto) { log.info(".. send pre #" + _number); MessageReference send = super.send(messageDto); log.info(".. send post #" + _number); return send; } }; // Invoke the lambda, with the wrapped MatsInitiate initiateLambda.initiate(wrappedMatsInitiate); log.info("Intercept post #" + _number); } @Override public void initiateCompleted(InitiateCompletedContext initiateCompletedContext) { log.info("Completed #" + _number); } }.. then the following sequence of log lines and operations ensues:
initiateStarted(..)
are invoked
in sequence:Started #1
Started #2
initiateIntercept(..)
methods, and then the resulting lambda is invoked:Intercept pre #1
Intercept pre #2
send(..)
, which goes through the stack of MatsInitiateWrappers which the
initiateIntercept(..)
invocations generated (thus hitting the last wrapping by #2 first):.. send pre #2
.. send pre #1
.. send post #1
.. send post #2
initiateIntercept(..)
stackIntercept post #2
Intercept post #1
initiateComplete(..)
is invoked, in explicit reversed order:Completed #2
Completed #1
MatsInitiator
gotten with MatsFactory.getDefaultInitiator()
or
MatsFactory.getOrCreateInitiator(String)
- and notice the special semantics of getDefaultInitiator(),
whereby if such an seemingly "from the outside" initiation is invoked when code-flow-wise within a Stage, you will
actually be "elevated" to be initiated "within Mats" using the Stage initiator - and hence this interceptor will not
be invoked (it is no longer "from outside of Mats").
The concept of "outside" vs. "inside" perhaps seems subtle, but there is a distinct difference: No processing will
ever happen in a Mats fabric if no initiations happens "from the outside": It is always a "from the outside"
initiation that will set Mats flows in action. Such a process flow might then set several new Mats flows in action
(i.e. initiations "from the inside"), but those are dependent on the initial Mats flow that was set in motion "from
the outside", and would never have been initiated was it not for such initiation.
To catch initiations "from the inside", you will employ a MatsStageInterceptor
.Modifier and Type | Interface and Description |
---|---|
static interface |
MatsInitiateInterceptor.InitiateCompletedContext |
static interface |
MatsInitiateInterceptor.InitiateInterceptContext |
static interface |
MatsInitiateInterceptor.InitiateInterceptOutgoingMessagesContext |
static interface |
MatsInitiateInterceptor.InitiateInterceptUserLambdaContext |
static interface |
MatsInitiateInterceptor.InitiateStartedContext |
static interface |
MatsInitiateInterceptor.MatsInitiateInterceptOutgoingMessages
While still within the initiation context, this interception enables modifying outgoing messages from the user
lambda, setting trace properties, adding "sideloads", deleting a message, or initiating additional messages.
|
static interface |
MatsInitiateInterceptor.MatsInitiateInterceptUserLambda
Enables the intercepting of the invocation of the user lambda in an Initiation, with ability to wrap the
MatsInitiator.MatsInitiate (and thus modify any request, send or publishes) - or even take over the entire initiation. |
Modifier and Type | Method and Description |
---|---|
default void |
initiateCompleted(MatsInitiateInterceptor.InitiateCompletedContext context) |
default void |
initiateStarted(MatsInitiateInterceptor.InitiateStartedContext context)
Invoked right before user lambda is invoked.
|
default void initiateStarted(MatsInitiateInterceptor.InitiateStartedContext context)
default void initiateCompleted(MatsInitiateInterceptor.InitiateCompletedContext context)