Package de.christofreichardt.diagnosis
Class QueueTracer<T extends AbstractTracer>
- java.lang.Object
-
- de.christofreichardt.diagnosis.AbstractTracer
-
- de.christofreichardt.diagnosis.QueueTracer<T>
-
- Type Parameters:
T- the wrapped tracer
- Direct Known Subclasses:
OueueNetTracer,QueueFileTracer,QueueNullTracer
public abstract class QueueTracer<T extends AbstractTracer> extends AbstractTracer
A special tracer intended for the use by a bounded blocking queue. This is an option to retrieve tracer within a multi-threaded environment when we cannot control the creation of the threads. An example would be applications within a container that manages a thread pool. This tracer honors the contract of anAbstractTracerbut does so by wrapping and delegating to anotherAbstractTracer. In particular the current tracing context will be automatically cleared when callingwayout()and the method stack remains empty afterwards. Thus the tracer can be reused for another thread's tracing context without any danger to create a memory leak.- Author:
- Christof Reichardt
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class de.christofreichardt.diagnosis.AbstractTracer
AbstractTracer.Exception
-
-
Field Summary
Fields Modifier and Type Field Description protected TtracerSome tracer.-
Fields inherited from class de.christofreichardt.diagnosis.AbstractTracer
VERSION
-
-
Constructor Summary
Constructors Constructor Description QueueTracer(String name, T tracer)Constructor expects the tracer name and the to be wrapped tracer instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearCurrentTracingContext()Delegates to the corresponding method of the wrapped tracer.voidclose()Closes the wrapped tracer.TraceMethodentry(String returnType, Class<?> clazz, String methodSignature)Delegates to the corresponding method of the wrapped tracer.TraceMethodentry(String returnType, Object object, String methodSignature)Delegates to the corresponding method of the wrapped tracer.intgetBufferSize()Delegates to the corresponding method of the wrapped tracer.intgetLevel()Returns the configured debuglevel.protected AbstractThreadMapgetThreadMap()Delegates to the corresponding method of the wrapped tracer.voidinitCurrentTracingContext()Delegates to the corresponding method of the wrapped tracer by using the config parameter global to all queued tracer.voidinitCurrentTracingContext(int debugLevel, boolean online)Delegates to the corresponding method of the wrapped tracer.booleanisAutoflush()Delegates to the corresponding method of the wrapped tracer.booleanisOnline()Returns the configuredonlinevalue.booleanisOpened()Delegates to the corresponding method of the wrapped tracer.voidlogException(LogLevel logLevel, Throwable throwable, Class<?> clazz, String methodName)Delegates to the corresponding method of the wrapped tracer.voidlogMessage(LogLevel logLevel, String message, Class<?> clazz, String methodName)Delegates to the corresponding method of the wrapped tracer.voidopen()Opens the wrapped tracer.IndentablePrintStreamout()Delegates to the corresponding method of the wrapped tracer.protected IndentablePrintStreamout(int level)Delegates to the corresponding method of the wrapped tracer.protected voidreadConfiguration(XPath xpath, Node node)Reads the configuration for this particular tracer instance by evaluating the given node with the given xpath engine.protected voidsetAutoflush(boolean autoflush)Sets the autoflush mode of the wrapped tracervoidsetBufferSize(int bufferSize)Sets the buffer size of the wrapped tracer.TraceMethodwayout()Delegates to the corresponding method of the wrapped tracer.-
Methods inherited from class de.christofreichardt.diagnosis.AbstractTracer
entry, formatStreamErrorState, formatVersionInfo, getBufferedOutputStream, getLevel, getName, getNullPrintStream, getTracePrintStream, isOnline, setBufferedOutputStream, setOpened, setTracePrintStream
-
-
-
-
Field Detail
-
tracer
protected final T extends AbstractTracer tracer
Some tracer.
-
-
Method Detail
-
getBufferSize
public int getBufferSize()
Delegates to the corresponding method of the wrapped tracer.- Overrides:
getBufferSizein classAbstractTracer- Returns:
- the buffer size of the wrapped tracer
-
isAutoflush
public boolean isAutoflush()
Delegates to the corresponding method of the wrapped tracer.- Overrides:
isAutoflushin classAbstractTracer- Returns:
- indicates the autoflush mode of the wrapped tracer
-
isOpened
public boolean isOpened()
Delegates to the corresponding method of the wrapped tracer.- Overrides:
isOpenedin classAbstractTracer- Returns:
- indicates if the wrapped tracer is openend
-
setBufferSize
public void setBufferSize(int bufferSize)
Sets the buffer size of the wrapped tracer.- Overrides:
setBufferSizein classAbstractTracer- Parameters:
bufferSize- the bufferSize to set
-
setAutoflush
protected void setAutoflush(boolean autoflush)
Sets the autoflush mode of the wrapped tracer- Overrides:
setAutoflushin classAbstractTracer- Parameters:
autoflush- the autoflush to set
-
isOnline
public boolean isOnline()
Returns the configuredonlinevalue. Will be used by the parameterlessinitCurrentTracingContext()method.- Returns:
- the configured
onlinevalue
-
getLevel
public int getLevel()
Returns the configured debuglevel. Will be used by the parameterlessinitCurrentTracingContext()method.- Returns:
- the configured debug level
-
readConfiguration
protected void readConfiguration(XPath xpath, Node node) throws XPathExpressionException, AbstractTracer.Exception
Description copied from class:AbstractTracerReads the configuration for this particular tracer instance by evaluating the given node with the given xpath engine.- Overrides:
readConfigurationin classAbstractTracer- Parameters:
xpath- the xpath enginenode- the config node- Throws:
XPathExpressionException- indicates xpath problemsAbstractTracer.Exception- indicates problems when configuring certain tracer instances
-
open
public void open()
Opens the wrapped tracer.- Specified by:
openin classAbstractTracer
-
close
public void close()
Closes the wrapped tracer.- Specified by:
closein classAbstractTracer
-
initCurrentTracingContext
public void initCurrentTracingContext()
Delegates to the corresponding method of the wrapped tracer by using the config parameter global to all queued tracer.- Overrides:
initCurrentTracingContextin classAbstractTracer
-
initCurrentTracingContext
public void initCurrentTracingContext(int debugLevel, boolean online)Delegates to the corresponding method of the wrapped tracer.- Overrides:
initCurrentTracingContextin classAbstractTracer- Parameters:
debugLevel- controls the extent of the outputonline- a value of false delivers no output of the current thread at all whereas a value of true delivers output controlled by debugLevel
-
entry
public TraceMethod entry(String returnType, Class<?> clazz, String methodSignature)
Delegates to the corresponding method of the wrapped tracer.- Overrides:
entryin classAbstractTracer- Parameters:
returnType- the return type of the method as string representationclazz- the class to which that method belongmethodSignature- the remaining method signature (without return type) inclusive parameter as string representation- Returns:
- the TraceMethod which has been put onto the stack - a mere data object for internal use primarily. May be null.
-
entry
public TraceMethod entry(String returnType, Object object, String methodSignature)
Delegates to the corresponding method of the wrapped tracer.- Overrides:
entryin classAbstractTracer- Parameters:
returnType- the return type of the method as string representationobject- the object that owns the methodmethodSignature- the remaining method signature (without return type) inclusive parameter as string representation- Returns:
- the TraceMethod which has been put onto the stack - a mere data object for internal use primarily. May be null.
-
logMessage
public void logMessage(LogLevel logLevel, String message, Class<?> clazz, String methodName)
Delegates to the corresponding method of the wrapped tracer.- Overrides:
logMessagein classAbstractTracer- Parameters:
logLevel- one of the predefined levels INFO, WARNING, ERROR, FATAL and SEVEREmessage- the to be logged messageclazz- the originating classmethodName- the originating method
-
logException
public void logException(LogLevel logLevel, Throwable throwable, Class<?> clazz, String methodName)
Delegates to the corresponding method of the wrapped tracer.- Overrides:
logExceptionin classAbstractTracer- Parameters:
logLevel- one of the predefined levels INFO, WARNING, ERROR, FATAL and SEVEREthrowable- the to be logged throwableclazz- the originating classmethodName- the name of the relevant method
-
getThreadMap
protected AbstractThreadMap getThreadMap()
Delegates to the corresponding method of the wrapped tracer.- Overrides:
getThreadMapin classAbstractTracer- Returns:
- the thread map of the wrapped tracer
-
wayout
public TraceMethod wayout()
Delegates to the corresponding method of the wrapped tracer. Besides it checks if the stack size of the current tracing context has decreased to zero. If so then the current tracing context will be cleared.- Overrides:
wayoutin classAbstractTracer- Returns:
- the TraceMethod which has been popped from the stack - a mere data object for internal use primarily. May be null.
-
out
public IndentablePrintStream out()
Delegates to the corresponding method of the wrapped tracer.- Overrides:
outin classAbstractTracer- Returns:
- an
IndentablePrintStream
-
out
protected IndentablePrintStream out(int level)
Delegates to the corresponding method of the wrapped tracer.- Overrides:
outin classAbstractTracer- Parameters:
level- the level of the to be printed data- Returns:
- an
IndentablePrintStream
-
clearCurrentTracingContext
public void clearCurrentTracingContext()
Delegates to the corresponding method of the wrapped tracer.- Overrides:
clearCurrentTracingContextin classAbstractTracer
-
-