CachedTracer

Abstract tracer that caches recorded traces in memory and periodically dumps them.

Implements: ITracer, IReconfigurable, IReferenceable

Description

The CachedTracer class allows you to create a tracer that caches the recorded traces in memory and periodically dumps them.

Important points

  • Child classes implement saving cached traces to their specified destinations.

Configuration parameters

  • source: source (context) name
  • options:
    • interval: interval in milliseconds to save log messages (default: 10 seconds)
    • max_cache_size: maximum number of messages stored in this cache (default: 100)

References

  • *:context-info:*:*:1.0 - (optional) ContextInfo to detect the context id and specify counters source

Fields

_source

Source (context) name

String _source = null

_cache

List of traces

List _cache = new ArrayList<>()

_updated

Boolean variable that indicates whether there has been an update or not.

boolean _updated = false

_last_dump_time

Time of the last dump

long _lastDumpTime = System.currentTimeMillis()

_max_cache_size

Maximum number of messages stored in this cache (default: 100)

int _maxCacheSize = 100

_interval

Interval in milliseconds to save log messages (default: 10 seconds)

long _interval = 10000

Instance methods

begin_trace

Begins recording an operation trace.

TraceTiming beginTrace(IContext context, String component, String operation)

  • context: IContext - (optional) a context to trace execution through a call chain.
  • component: String - name of a called component
  • operation: String - name of the executed operation.
  • return: TraceTiming - a trace timing object.

clear

Clears (removes) all cached log messages.

void clear()

configure

Configures component by passing configuration parameters.

void configure(ConfigParams config) throws ConfigException

  • config: ConfigParams - configuration parameters to be set.

dump

Dumps (writes) the currently cached log messages.

void dump()

failure

Records an operation failure with its name, duration and error.

void failure(IContext context, String component, String operation, Exception error, long duration)

  • context: IContext - (optional) a context to trace execution through a call chain.
  • component: String - name of the called component
  • operation: String - name of the executed operation.
  • error: Exception - an error object associated with this trace.
  • duration: long - execution duration in milliseconds.

save

Saves log messages from the cache. Throws error if not done.

abstract void save(List<OperationTrace> messages)

setReferences

Sets references to dependent components.

void setReferences(IReferencess references) throws ReferenceException, ConfigException

  • references: IReferences - references to locate the component dependencies.

trace

Records an operation trace with its name and duration.

void trace(IContext context, String component, String operation, Long duration)

  • context: IContext - (optional) a context to trace execution through a call chain.
  • component: String - name of the called component
  • operation: String - name of the executed operation.
  • duration: Long - execution duration in milliseconds.

update

Sets trace cache as updated and dumps it when timeout expires.

void update()

_write

Writes a log message to the logger destination.

void write(IContext context, String component, String operation, Exception error, long duration)

  • context: IContext - (optional) a context to trace execution through a call chain.
  • component: String - name of the called component
  • operation: String - name of the executed operation.
  • error: Exception - an error object associated with this trace.
  • duration: long - execution duration in milliseconds.

See also