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:
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 void
addChild(String trackerId)
Register a child to the document associated with the trackervoid
addParent(String trackerId)
Register a parent to the document associated with the trackerdefault void
debug(String message)
Logs message asDEBUG
default void
error(String message)
Logs message asERROR
default String
get(String key)
String
getOrDefault(String key, String defaultValue)
String
id()
default void
info(String message)
Logs message asINFO
void
log(String type, String message)
Logs themessage
under thetype
as levelvoid
moveTo(Document.State state, byte[] content)
Tells the tracker to move to thestate
, usingstate
as name, and then associates thecontent
to it.void
moveTo(Document.State state, Throwable throwable)
Tells the tracker to move tostate
, and associates the stacktrace of thethrowable
default void
moveTo(String state)
Tells the tracker to move thestate
default void
moveTo(String stateName, byte[] content)
Tells the tracker to move to thestate
, usingstate
as name, and then associates thecontent
to it.default void
moveTo(String stateName, Throwable throwable)
Tells the tracker to move tostate
, and associates the stacktrace of thethrowable
void
put(String key, String value)
Puts thevalue
in this context, associated with thekey
String
remove(String key)
Removes the value associated withkey
boolean
removeChild(String trackerId)
Unregister a child from the document associated with the trackerboolean
removeParent(String trackerId)
Unregister a parent from the document associated with the trackerdefault void
warn(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
, usingstate
as name, and then associates thecontent
to it.
-
moveTo
void moveTo(Document.State state, byte[] content)
Tells the tracker to move to thestate
, usingstate
as name, and then associates thecontent
to 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
-
-