Package io.toro.martini.tracker
Interface Tracker
-
public interface TrackerTracker 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:
The above code tells the tracker to move to the "Start" state, invoke the method, and finally move to the "Finished" state.Tracker tracker = ... tracker.moveTo("Started); someObject.invokeMethod(); tracker.moveTo("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:invoke method | Start | --------------------> | 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.Tracker tracker = ... tracker.moveTo("Started); try { someObject.invokeMethod(); } catch ( SomeException ex ) { tracker.moveTo("Failed"); throw ex; } tracker.moveTo("Finished");
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidaddChild(String trackerId)Register a child to the document associated with the trackervoidaddParent(String trackerId)Register a parent to the document associated with the trackerdefault voiddebug(String message)Logs message asDEBUGdefault voiderror(String message)Logs message asERRORdefault Stringget(String key)StringgetOrDefault(String key, String defaultValue)Stringid()default voidinfo(String message)Logs message asINFOvoidlog(String type, String message)Logs 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 voidmoveTo(String state)Tells the tracker to move thestatedefault voidmoveTo(String stateName, byte[] content)Tells the tracker to move to thestate, usingstateas name, and then associates thecontentto it.default voidmoveTo(String stateName, Throwable throwable)Tells the tracker to move tostate, and associates the stacktrace of thethrowablevoidput(String key, String value)Puts thevaluein this context, associated with thekeyStringremove(String key)Removes 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 voidwarn(String message)Logs message asWARN
-
-
-
Method Detail
-
id
String id()
- Returns:
- the identifier for this tracker
-
moveTo
default void moveTo(String state)
Tells the tracker to move thestate
-
moveTo
default void moveTo(String stateName, byte[] content)
Tells the tracker to move to thestate, usingstateas name, and then associates thecontentto it.
-
moveTo
void moveTo(Document.State state, byte[] content)
Tells the tracker to move to thestate, usingstateas name, and then associates thecontentto it.
-
moveTo
default void moveTo(String stateName, Throwable throwable)
Tells the tracker to move tostate, and associates the stacktrace of thethrowable
-
moveTo
void moveTo(Document.State state, Throwable throwable)
Tells the tracker to move tostate, and associates the stacktrace of thethrowable
-
info
default void info(String message)
Logs message asINFO
-
warn
default void warn(String message)
Logs message asWARN
-
error
default void error(String message)
Logs message asERROR
-
debug
default void debug(String message)
Logs message asDEBUG
-
getOrDefault
String getOrDefault(String key, String defaultValue)
- Returns:
- the value associated with
key, ordefaultValue
-
remove
String remove(String key)
Removes the value associated withkey- Returns:
- The previous value associated with
key, ornull
-
addParent
void addParent(String trackerId)
Register a parent to the document associated with the tracker- Parameters:
trackerId- The id of the tracker to be set as a parent
-
removeParent
boolean removeParent(String trackerId)
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
void addChild(String trackerId)
Register a child to the document associated with the tracker- Parameters:
trackerId- The id of the tracker to be set as a child
-
removeChild
boolean removeChild(String trackerId)
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
-
-