Class CachedTracer

java.lang.Object
org.pipservices3.components.trace.CachedTracer
All Implemented Interfaces:
org.pipservices3.commons.config.IConfigurable, org.pipservices3.commons.config.IReconfigurable, org.pipservices3.commons.refer.IReferenceable, ITracer

public abstract class CachedTracer extends Object implements ITracer, org.pipservices3.commons.config.IReconfigurable, org.pipservices3.commons.refer.IReferenceable
Abstract tracer that caches recorded traces in memory and periodically dumps them. 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

See Also:
  • Field Details

    • _source

      protected String _source
    • _cache

      protected List<OperationTrace> _cache
    • _updated

      protected boolean _updated
    • _lastDumpTime

      protected long _lastDumpTime
    • _maxCacheSize

      protected int _maxCacheSize
    • _interval

      protected long _interval
  • Constructor Details

    • CachedTracer

      public CachedTracer()
  • Method Details

    • configure

      public void configure(org.pipservices3.commons.config.ConfigParams config) throws org.pipservices3.commons.errors.ConfigException
      Configures component by passing configuration parameters.
      Specified by:
      configure in interface org.pipservices3.commons.config.IConfigurable
      Parameters:
      config - configuration parameters to be set.
      Throws:
      org.pipservices3.commons.errors.ConfigException
    • setReferences

      public void setReferences(org.pipservices3.commons.refer.IReferences references) throws org.pipservices3.commons.refer.ReferenceException, org.pipservices3.commons.errors.ConfigException
      Sets references to dependent components.
      Specified by:
      setReferences in interface org.pipservices3.commons.refer.IReferenceable
      Parameters:
      references - references to locate the component dependencies.
      Throws:
      org.pipservices3.commons.refer.ReferenceException
      org.pipservices3.commons.errors.ConfigException
    • write

      public void write(String correlationId, String component, String operation, Exception error, long duration)
      Writes a log message to the logger destination.
      Parameters:
      correlationId - (optional) transaction id to trace execution through call chain.
      component - a name of called component
      operation - a name of the executed operation.
      error - an error object associated with this trace.
      duration - execution duration in milliseconds.
    • trace

      public void trace(String correlationId, String component, String operation, Long duration)
      Records an operation trace with its name and duration
      Specified by:
      trace in interface ITracer
      Parameters:
      correlationId - (optional) transaction id to trace execution through call chain.
      component - a name of called component
      operation - a name of the executed operation.
      duration - execution duration in milliseconds.
    • failure

      public void failure(String correlationId, String component, String operation, Exception error, long duration)
      Records an operation failure with its name, duration and error
      Specified by:
      failure in interface ITracer
      Parameters:
      correlationId - (optional) transaction id to trace execution through call chain.
      component - a name of called component
      operation - a name of the executed operation.
      error - an error object associated with this trace.
      duration - execution duration in milliseconds.
    • beginTrace

      public TraceTiming beginTrace(String correlationId, String component, String operation)
      Begings recording an operation trace
      Specified by:
      beginTrace in interface ITracer
      Parameters:
      correlationId - (optional) transaction id to trace execution through call chain.
      component - a name of called component
      operation - a name of the executed operation.
      Returns:
      a trace timing object.
    • save

      public abstract void save(List<OperationTrace> messages)
      Saves log messages from the cache.
      Parameters:
      messages - a list with log messages
    • clear

      public void clear()
      Clears (removes) all cached log messages.
    • dump

      public void dump()
      Dumps (writes) the currently cached log messages.
      See Also:
    • update

      protected void update()
      Makes trace cache as updated and dumps it when timeout expires.
      See Also: