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();
}
}
}
}
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);
}
}
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));
}
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;
}
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);
}
}
};
}
Aggregations