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)
ContextInfoto detect the context id and specify counters source
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected List<OperationTrace>protected longprotected longprotected intprotected Stringprotected boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbeginTrace(String correlationId, String component, String operation) Begings recording an operation tracevoidclear()Clears (removes) all cached log messages.voidconfigure(org.pipservices3.commons.config.ConfigParams config) Configures component by passing configuration parameters.voiddump()Dumps (writes) the currently cached log messages.voidRecords an operation failure with its name, duration and errorabstract voidsave(List<OperationTrace> messages) Saves log messages from the cache.voidsetReferences(org.pipservices3.commons.refer.IReferences references) Sets references to dependent components.voidRecords an operation trace with its name and durationprotected voidupdate()Makes trace cache as updated and dumps it when timeout expires.voidWrites a log message to the logger destination.
-
Field Details
-
_source
-
_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:
configurein interfaceorg.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:
setReferencesin interfaceorg.pipservices3.commons.refer.IReferenceable- Parameters:
references- references to locate the component dependencies.- Throws:
org.pipservices3.commons.refer.ReferenceExceptionorg.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 componentoperation- a name of the executed operation.error- an error object associated with this trace.duration- execution duration in milliseconds.
-
trace
Records an operation trace with its name and duration -
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:
failurein interfaceITracer- Parameters:
correlationId- (optional) transaction id to trace execution through call chain.component- a name of called componentoperation- a name of the executed operation.error- an error object associated with this trace.duration- execution duration in milliseconds.
-
beginTrace
Begings recording an operation trace- Specified by:
beginTracein interfaceITracer- Parameters:
correlationId- (optional) transaction id to trace execution through call chain.component- a name of called componentoperation- a name of the executed operation.- Returns:
- a trace timing object.
-
save
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. -
update
protected void update()Makes trace cache as updated and dumps it when timeout expires.- See Also:
-