org.apache.camel.processor.interceptor
Class Tracer

java.lang.Object
  extended by org.apache.camel.processor.interceptor.Tracer
All Implemented Interfaces:
Service, InterceptStrategy

public class Tracer
extends Object
implements InterceptStrategy, Service

An interceptor strategy for tracing routes

Version:

Constructor Summary
Tracer()
           
 
Method Summary
static Tracer createTracer(CamelContext context)
          Creates a new tracer.
 DefaultTraceFormatter getDefaultTraceFormatter()
           
 Endpoint getDestination()
           
 String getDestinationUri()
           
 TraceFormatter getFormatter()
           
 String getJpaTraceEventMessageClassName()
           
 CamelLogger getLogger(ExchangeFormatter formatter)
          Gets the logger to be used for tracers that can format and log a given exchange.
 LoggingLevel getLogLevel()
           
 String getLogName()
           
 Predicate getTraceFilter()
           
 TraceEventHandler getTraceHandler()
           
 TraceInterceptorFactory getTraceInterceptorFactory()
           
static Tracer getTracer(CamelContext context)
          A helper method to return the Tracer instance if one is enabled
 boolean isEnabled()
           
 boolean isLogStackTrace()
           
 boolean isTraceExceptions()
           
 boolean isTraceInterceptors()
           
 boolean isTraceOutExchanges()
           
 boolean isUseJpa()
           
 void setDestination(Endpoint destination)
          See setDestinationUri(String)
 void setDestinationUri(String destinationUri)
          Sets an optional destination to send the traced Exchange.
 void setEnabled(boolean flag)
           
 void setFormatter(TraceFormatter formatter)
           
 void setJpaTraceEventMessageClassName(String jpaTraceEventMessageClassName)
          Set the fully qualified name of the class to be used by the JPA event tracing.
 void setLogLevel(LoggingLevel logLevel)
          Sets the logging level to output tracing.
 void setLogName(String logName)
          Sets the logging name to use.
 void setLogStackTrace(boolean logStackTrace)
          Sets whether thrown exception stacktrace should be traced, if disabled then only the exception message is logged
 void setTraceExceptions(boolean traceExceptions)
          Sets whether thrown exceptions should be traced
 void setTraceFilter(Predicate traceFilter)
          Sets a predicate to be used as filter when tracing
 void setTraceHandler(TraceEventHandler traceHandler)
          Set the object to be used to perform tracing.
 void setTraceInterceptorFactory(TraceInterceptorFactory traceInterceptorFactory)
          Set the factory to be used to create the trace interceptor.
 void setTraceInterceptors(boolean traceInterceptors)
          Sets whether interceptors should be traced or not
 void setTraceOutExchanges(boolean traceOutExchanges)
          Sets whether exchanges coming out of processors should be traced
 void setUseJpa(boolean useJpa)
          Sets whether we should use a JpaTraceEventMessage instead of an ordinary DefaultTraceEventMessage

Use this to allow persistence of trace events into a database using JPA.

 void start()
          Starts the service
 void stop()
          Stops the service
 String toString()
           
 Processor wrapProcessorInInterceptors(CamelContext context, ProcessorDefinition<?> definition, Processor target, Processor nextTarget)
          This method is invoked by ProcessorDefinition.wrapProcessor(RouteContext, Processor) to give the implementor an opportunity to wrap the target processor in a route.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Tracer

public Tracer()
Method Detail

createTracer

public static Tracer createTracer(CamelContext context)
Creates a new tracer.

Parameters:
context - Camel context
Returns:
a new tracer

getTracer

public static Tracer getTracer(CamelContext context)
A helper method to return the Tracer instance if one is enabled

Returns:
the tracer or null if none can be found

getLogger

public CamelLogger getLogger(ExchangeFormatter formatter)
Gets the logger to be used for tracers that can format and log a given exchange.

Parameters:
formatter - the exchange formatter
Returns:
the logger to use

wrapProcessorInInterceptors

public Processor wrapProcessorInInterceptors(CamelContext context,
                                             ProcessorDefinition<?> definition,
                                             Processor target,
                                             Processor nextTarget)
                                      throws Exception
Description copied from interface: InterceptStrategy
This method is invoked by ProcessorDefinition.wrapProcessor(RouteContext, Processor) to give the implementor an opportunity to wrap the target processor in a route.

Important: See the class javadoc for advice on letting interceptor be compatible with the asynchronous routing engine.

Specified by:
wrapProcessorInInterceptors in interface InterceptStrategy
Parameters:
context - Camel context
definition - the model this interceptor represents
target - the processor to be wrapped
nextTarget - the next processor to be routed to
Returns:
processor wrapped with an interceptor or not wrapped.
Throws:
Exception - can be thrown

getFormatter

public TraceFormatter getFormatter()

getDefaultTraceFormatter

public DefaultTraceFormatter getDefaultTraceFormatter()

setFormatter

public void setFormatter(TraceFormatter formatter)

setEnabled

public void setEnabled(boolean flag)

isEnabled

public boolean isEnabled()

isTraceInterceptors

public boolean isTraceInterceptors()

setTraceInterceptors

public void setTraceInterceptors(boolean traceInterceptors)
Sets whether interceptors should be traced or not


getTraceFilter

public Predicate getTraceFilter()

setTraceFilter

public void setTraceFilter(Predicate traceFilter)
Sets a predicate to be used as filter when tracing


getLogLevel

public LoggingLevel getLogLevel()

setLogLevel

public void setLogLevel(LoggingLevel logLevel)
Sets the logging level to output tracing. Will use INFO level by default.


isTraceExceptions

public boolean isTraceExceptions()

setTraceExceptions

public void setTraceExceptions(boolean traceExceptions)
Sets whether thrown exceptions should be traced


isLogStackTrace

public boolean isLogStackTrace()

setLogStackTrace

public void setLogStackTrace(boolean logStackTrace)
Sets whether thrown exception stacktrace should be traced, if disabled then only the exception message is logged


getLogName

public String getLogName()

setLogName

public void setLogName(String logName)
Sets the logging name to use. Will default use org.apache.camel.processor.interceptor.TraceInterceptor.


setTraceOutExchanges

public void setTraceOutExchanges(boolean traceOutExchanges)
Sets whether exchanges coming out of processors should be traced


isTraceOutExchanges

public boolean isTraceOutExchanges()

getDestinationUri

public String getDestinationUri()

setDestinationUri

public void setDestinationUri(String destinationUri)
Sets an optional destination to send the traced Exchange.

Can be used to store tracing as files, in a database or whatever. The routing of the Exchange will happen synchronously and the original route will first continue when this destination routing has been completed.


getDestination

public Endpoint getDestination()

setDestination

public void setDestination(Endpoint destination)
See setDestinationUri(String)


isUseJpa

public boolean isUseJpa()

setUseJpa

public void setUseJpa(boolean useJpa)
Sets whether we should use a JpaTraceEventMessage instead of an ordinary DefaultTraceEventMessage

Use this to allow persistence of trace events into a database using JPA. This requires camel-jpa in the classpath.


getTraceInterceptorFactory

public TraceInterceptorFactory getTraceInterceptorFactory()

setTraceInterceptorFactory

public void setTraceInterceptorFactory(TraceInterceptorFactory traceInterceptorFactory)
Set the factory to be used to create the trace interceptor. It is expected that the factory will create a subclass of TraceInterceptor.

Use this to take complete control of how trace events are handled. The TraceInterceptorFactory should only be set before any routes are created, hence this method is not thread safe.


getTraceHandler

public TraceEventHandler getTraceHandler()

setTraceHandler

public void setTraceHandler(TraceEventHandler traceHandler)
Set the object to be used to perform tracing.

Use this to take more control of how trace events are persisted. Setting the traceHandler provides a simpler mechanism for controlling tracing than the TraceInterceptorFactory. The TraceHandler should only be set before any routes are created, hence this method is not thread safe.


getJpaTraceEventMessageClassName

public String getJpaTraceEventMessageClassName()

setJpaTraceEventMessageClassName

public void setJpaTraceEventMessageClassName(String jpaTraceEventMessageClassName)
Set the fully qualified name of the class to be used by the JPA event tracing.

The class must exist in the classpath and be available for dynamic loading. The class name should only be set before any routes are created, hence this method is not thread safe.


toString

public String toString()
Overrides:
toString in class Object

start

public void start()
           throws Exception
Description copied from interface: Service
Starts the service

Specified by:
start in interface Service
Throws:
Exception - is thrown if starting failed

stop

public void stop()
          throws Exception
Description copied from interface: Service
Stops the service

Specified by:
stop in interface Service
Throws:
Exception - is thrown if stopping failed


Apache CAMEL