Package io.toro.martini.tracker
Interface Tracker
public interface Tracker
Tracker serves as the centralized abstraction for logging and tracing
changes that may occur within an arbitrary invocation. Similar to how a typical
logger is used within the context of a class, one may pass Tracker objects
possibly to a pipeline to track states as the each processor processes
the the data.
Similar to a finite-state machine, the tracker records maintain a set of
states, at which callers can arbitrarily set the current state at that specific
point in time.
A common use-case of a tracker is for tracing method invocation, such as:
Tracker tracker = ...
tracker.moveTo("Started);
someObject.invokeMethod();
tracker.moveTo("Finished");
The above code tells the tracker to move to the "Start" state, invoke the
method, and finally move to the "Finished" state.
invoke method
| Start | --------------------> | Finished |
Not all invocations may succeed - so callers may catch the exception thrown
in their code, and move the tracker to a different state such as:
Tracker tracker = ...
tracker.moveTo("Started);
try {
someObject.invokeMethod();
} catch ( SomeException ex ) {
tracker.moveTo("Failed");
throw ex;
}
tracker.moveTo("Finished");
The above code treats the exception as fatal - so the last transition is not
called.
Data collected by the tracker are retrievable and may serve as an audit
trail for observing execution flow.-
Method Summary
Modifier and TypeMethodDescriptionvoidRegister a child to the document associated with the trackervoidRegister a parent to the document associated with the trackerdefault voidLogs message asDEBUGdefault voidLogs message asERRORdefault StringgetOrDefault(String key, String defaultValue) id()default voidLogs message asINFOvoidLogs themessageunder thetypeas levelvoidmoveTo(Document.State state, byte[] content) Tells the tracker to move to thestate, usingstateas name, and then associates thecontentto it.voidmoveTo(Document.State state, Throwable throwable) Tells the tracker to move tostate, and associates the stacktrace of thethrowabledefault voidTells the tracker to move thestatewith default state Typedefault voidTells the tracker to move to thestate, usingstateas name, and then associates thecontentto it with default state typedefault voidmoveTo(String state, Document.State.StateType stateType) Tells the tracker to move thestatedefault voidmoveTo(String stateName, Document.State.StateType stateType, byte[] content) Tells the tracker to move to thestate, usingstateas name, and then associates thecontentto it.default voidmoveTo(String stateName, Document.State.StateType stateType, Throwable throwable) Tells the tracker to move tostate, and associates the stacktrace of thethrowabledefault voidTells the tracker to move tostate, and associates the stacktrace of thethrowablevoidPuts thevaluein this context, associated with thekeyRemoves the value associated withkeybooleanremoveChild(String trackerId) Unregister a child from the document associated with the trackerbooleanremoveParent(String trackerId) Unregister a parent from the document associated with the trackerdefault voidLogs message asWARN
-
Method Details
-
id
String id()- Returns:
- the identifier for this tracker
-
moveTo
Tells the tracker to move thestatewith default state Type -
moveTo
Tells the tracker to move thestate -
moveTo
Tells the tracker to move to thestate, usingstateas name, and then associates thecontentto it with default state type -
moveTo
Tells the tracker to move to thestate, usingstateas name, and then associates thecontentto it. -
moveTo
Tells the tracker to move to thestate, usingstateas name, and then associates thecontentto it. -
moveTo
Tells the tracker to move tostate, and associates the stacktrace of thethrowable -
moveTo
Tells the tracker to move tostate, and associates the stacktrace of thethrowable -
moveTo
Tells the tracker to move tostate, and associates the stacktrace of thethrowable -
log
Logs themessageunder thetypeas level -
info
Logs message asINFO -
warn
Logs message asWARN -
error
Logs message asERROR -
debug
Logs message asDEBUG -
get
- Returns:
- the value associated with
key, ornull
-
getOrDefault
- Returns:
- the value associated with
key, ordefaultValue
-
put
Puts thevaluein this context, associated with thekey -
remove
Removes the value associated withkey- Returns:
- The previous value associated with
key, ornull
-
addParent
Register a parent to the document associated with the tracker- Parameters:
trackerId- The id of the tracker to be set as a parent
-
removeParent
Unregister a parent from the document associated with the tracker- Parameters:
trackerId- The id of the parent to be unregistered- Returns:
- whether an association was removed
-
addChild
Register a child to the document associated with the tracker- Parameters:
trackerId- The id of the tracker to be set as a child
-
removeChild
Unregister a child from the document associated with the tracker- Parameters:
trackerId- The id of the child to be unregistered- Returns:
- whether an association was removed
-