use of org.apache.camel.api.management.PerformanceCounter in project camel by apache.
the class DefaultManagementLifecycleStrategy method onRouteContextCreate.
public void onRouteContextCreate(RouteContext routeContext) {
if (!initialized) {
return;
}
// Create a map (ProcessorType -> PerformanceCounter)
// to be passed to InstrumentationInterceptStrategy.
Map<ProcessorDefinition<?>, PerformanceCounter> registeredCounters = new HashMap<ProcessorDefinition<?>, PerformanceCounter>();
// Each processor in a route will have its own performance counter.
// These performance counter will be embedded to InstrumentationProcessor
// and wrap the appropriate processor by InstrumentationInterceptStrategy.
RouteDefinition route = routeContext.getRoute();
// register performance counters for all processors and its children
for (ProcessorDefinition<?> processor : route.getOutputs()) {
registerPerformanceCounters(routeContext, processor, registeredCounters);
}
// set this managed intercept strategy that executes the JMX instrumentation for performance metrics
// so our registered counters can be used for fine grained performance instrumentation
routeContext.setManagedInterceptStrategy(new InstrumentationInterceptStrategy(registeredCounters, wrappedProcessors));
}
use of org.apache.camel.api.management.PerformanceCounter in project camel by apache.
the class InstrumentationInterceptStrategy method wrapProcessorInInterceptors.
public Processor wrapProcessorInInterceptors(CamelContext context, ProcessorDefinition<?> definition, Processor target, Processor nextTarget) throws Exception {
// do not double wrap it
if (target instanceof InstrumentationProcessor) {
return target;
}
// only wrap a performance counter if we have it registered in JMX by the jmx agent
PerformanceCounter counter = registeredCounters.get(definition);
if (counter != null) {
InstrumentationProcessor wrapper = new InstrumentationProcessor(counter);
wrapper.setProcessor(target);
wrapper.setType(definition.getShortName());
// add it to the mapping of wrappers so we can later change it to a decorated counter
// that when we register the processor
KeyValueHolder<ProcessorDefinition<?>, InstrumentationProcessor> holder = new KeyValueHolder<ProcessorDefinition<?>, InstrumentationProcessor>(definition, wrapper);
wrappedProcessors.put(target, holder);
return wrapper;
}
return target;
}
Aggregations