Search in sources :

Example 1 with PerformanceCounter

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));
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) HashMap(java.util.HashMap) ProcessorDefinition(org.apache.camel.model.ProcessorDefinition) PerformanceCounter(org.apache.camel.api.management.PerformanceCounter)

Example 2 with PerformanceCounter

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;
}
Also used : ProcessorDefinition(org.apache.camel.model.ProcessorDefinition) KeyValueHolder(org.apache.camel.util.KeyValueHolder) ManagedPerformanceCounter(org.apache.camel.management.mbean.ManagedPerformanceCounter) PerformanceCounter(org.apache.camel.api.management.PerformanceCounter)

Aggregations

PerformanceCounter (org.apache.camel.api.management.PerformanceCounter)2 ProcessorDefinition (org.apache.camel.model.ProcessorDefinition)2 HashMap (java.util.HashMap)1 ManagedPerformanceCounter (org.apache.camel.management.mbean.ManagedPerformanceCounter)1 RouteDefinition (org.apache.camel.model.RouteDefinition)1 KeyValueHolder (org.apache.camel.util.KeyValueHolder)1