Search in sources :

Example 6 with ProcessorDefinition

use of org.apache.camel.model.ProcessorDefinition in project camel by apache.

the class DefaultManagementLifecycleStrategy method removeWrappedProcessorsForRoutes.

/**
     * Removes the wrapped processors for the given routes, as they are no longer in use.
     * <p/>
     * This is needed to avoid accumulating memory, if a lot of routes is being added and removed.
     *
     * @param routes the routes
     */
private void removeWrappedProcessorsForRoutes(Collection<Route> routes) {
    // loop the routes, and remove the route associated wrapped processors, as they are no longer in use
    for (Route route : routes) {
        String id = route.getId();
        Iterator<KeyValueHolder<ProcessorDefinition<?>, InstrumentationProcessor>> it = wrappedProcessors.values().iterator();
        while (it.hasNext()) {
            KeyValueHolder<ProcessorDefinition<?>, InstrumentationProcessor> holder = it.next();
            RouteDefinition def = ProcessorDefinitionHelper.getRoute(holder.getKey());
            if (def != null && id.equals(def.getId())) {
                it.remove();
            }
        }
    }
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) ProcessorDefinition(org.apache.camel.model.ProcessorDefinition) KeyValueHolder(org.apache.camel.util.KeyValueHolder) ManagedRoute(org.apache.camel.management.mbean.ManagedRoute) Route(org.apache.camel.Route) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute)

Example 7 with ProcessorDefinition

use of org.apache.camel.model.ProcessorDefinition in project camel by apache.

the class CamelGroovyMethods method dataFormat.

// DataFormatClause.dataFormat(DataFormatDefinition) is private...
private static ProcessorDefinition<?> dataFormat(DataFormatClause<?> self, DataFormatDefinition format) {
    try {
        Method m = self.getClass().getDeclaredMethod("dataFormat", DataFormatDefinition.class);
        m.setAccessible(true);
        return (ProcessorDefinition<?>) m.invoke(self, format);
    } catch (Exception e) {
        throw new IllegalArgumentException("Unknown DataFormat operation", e);
    }
}
Also used : ProcessorDefinition(org.apache.camel.model.ProcessorDefinition) Method(java.lang.reflect.Method)

Example 8 with ProcessorDefinition

use of org.apache.camel.model.ProcessorDefinition 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 9 with ProcessorDefinition

use of org.apache.camel.model.ProcessorDefinition 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)

Example 10 with ProcessorDefinition

use of org.apache.camel.model.ProcessorDefinition in project camel by apache.

the class AdviceWithTasks method doReplace.

private static AdviceWithTask doReplace(final RouteDefinition route, final MatchBy matchBy, final ProcessorDefinition<?> replace, boolean selectFirst, boolean selectLast, int selectFrom, int selectTo, int maxDeep) {
    return new AdviceWithTask() {

        public void task() throws Exception {
            Iterator<ProcessorDefinition<?>> it = AdviceWithTasks.createMatchByIterator(route, matchBy, selectFirst, selectLast, selectFrom, selectTo, maxDeep);
            boolean match = false;
            while (it.hasNext()) {
                ProcessorDefinition<?> output = it.next();
                if (matchBy.match(output)) {
                    List<ProcessorDefinition<?>> outputs = getOutputs(output);
                    if (outputs != null) {
                        int index = outputs.indexOf(output);
                        if (index != -1) {
                            match = true;
                            outputs.add(index + 1, replace);
                            Object old = outputs.remove(index);
                            // must set parent on the node we added in the route
                            replace.setParent(output.getParent());
                            LOG.info("AdviceWith (" + matchBy.getId() + ") : [" + old + "] --> replace [" + replace + "]");
                        }
                    }
                }
            }
            if (!match) {
                throw new IllegalArgumentException("There are no outputs which matches: " + matchBy.getId() + " in the route: " + route);
            }
        }
    };
}
Also used : ProcessorDefinition(org.apache.camel.model.ProcessorDefinition) Endpoint(org.apache.camel.Endpoint)

Aggregations

ProcessorDefinition (org.apache.camel.model.ProcessorDefinition)17 RouteDefinition (org.apache.camel.model.RouteDefinition)5 Endpoint (org.apache.camel.Endpoint)4 HashMap (java.util.HashMap)3 Processor (org.apache.camel.Processor)3 MalformedObjectNameException (javax.management.MalformedObjectNameException)2 NamedNode (org.apache.camel.NamedNode)2 PerformanceCounter (org.apache.camel.api.management.PerformanceCounter)2 FromDefinition (org.apache.camel.model.FromDefinition)2 SendDefinition (org.apache.camel.model.SendDefinition)2 KeyValueHolder (org.apache.camel.util.KeyValueHolder)2 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 URISyntaxException (java.net.URISyntaxException)1 EventObject (java.util.EventObject)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1