private InterceptStrategy getOrCreateBacklogTracer() { InterceptStrategy tracer = BacklogTracer.getBacklogTracer(camelContext); if (tracer == null) { if (camelContext.getRegistry() != null) { // lookup in registry Map<String, BacklogTracer> map = camelContext.getRegistry().findByTypeWithName(BacklogTracer.class); if (map.size() == 1) { tracer = map.values().iterator().next(); } } if (tracer == null) { // fallback to use the default tracer tracer = camelContext.getDefaultBacklogTracer(); } } return tracer; }
private InterceptStrategy getOrCreateBacklogDebugger() { InterceptStrategy debugger = BacklogDebugger.getBacklogDebugger(camelContext); if (debugger == null) { if (camelContext.getRegistry() != null) { // lookup in registry Map<String, BacklogDebugger> map = camelContext.getRegistry().findByTypeWithName(BacklogDebugger.class); if (map.size() == 1) { debugger = map.values().iterator().next(); } } if (debugger == null) { // fallback to use the default debugger debugger = camelContext.getDefaultBacklogDebugger(); } } return debugger; }
/** * Adds the given list of interceptors to the channel. * * @param routeContext the route context * @param channel the channel to add strategies * @param strategies list of strategies to add. */ protected void addInterceptStrategies(RouteContext routeContext, Channel channel, List<InterceptStrategy> strategies) { for (InterceptStrategy strategy : strategies) { if (!routeContext.isStreamCaching() && strategy instanceof StreamCaching) { // stream cache is disabled so we should not add it continue; } if (!routeContext.isHandleFault() && strategy instanceof HandleFault) { // handle fault is disabled so we should not add it continue; } if (strategy instanceof Delayer) { if (routeContext.getDelayer() == null || routeContext.getDelayer() <= 0) { // delayer is disabled so we should not add it continue; } else { // replace existing delayer as delayer have individual configuration Iterator<InterceptStrategy> it = channel.getInterceptStrategies().iterator(); while (it.hasNext()) { InterceptStrategy existing = it.next(); if (existing instanceof Delayer) { it.remove(); } } // add the new correct delayer channel.addInterceptStrategy(strategy); continue; } } // add strategy channel.addInterceptStrategy(strategy); } }
@Override public Processor createProcessor(final RouteContext routeContext) throws Exception { // create the output processor output = this.createChildProcessor(routeContext, true); // add the output as a intercept strategy to the route context so its invoked on each processing step routeContext.getInterceptStrategies().add(new InterceptStrategy() { private Processor interceptedTarget; public Processor wrapProcessorInInterceptors(CamelContext context, ProcessorDefinition<?> definition, Processor target, Processor nextTarget) throws Exception { // store the target we are intercepting this.interceptedTarget = target; // remember the target that was intercepted intercepted.add(interceptedTarget); if (interceptedTarget != null) { // wrap in a pipeline so we continue routing to the next List<Processor> list = new ArrayList<Processor>(2); list.add(output); list.add(interceptedTarget); return new Pipeline(context, list); } else { return output; } } @Override public String toString() { return "intercept[" + (interceptedTarget != null ? interceptedTarget : output) + "]"; } }); // remove me from the route so I am not invoked in a regular route path routeContext.getRoute().getOutputs().remove(this); // and return no processor to invoke next from me return null; }
/** * A helper method to return the StreamCaching instance * for a given list of interceptors * * @param interceptors the list of interceptors * @return the stream cache or null if none can be found */ public static StreamCaching getStreamCaching(List<InterceptStrategy> interceptors) { for (InterceptStrategy interceptStrategy : interceptors) { if (interceptStrategy instanceof StreamCaching) { return (StreamCaching)interceptStrategy; } } return null; }
/** * Remove the {@link StreamCachingInterceptor} from the given list of interceptors * * @param interceptors the list of interceptors */ public static void noStreamCaching(List<InterceptStrategy> interceptors) { for (InterceptStrategy strategy : interceptors) { if (strategy instanceof StreamCaching) { interceptors.remove(strategy); } } }
/** * A helper method to return the HandleFault instance * for a given {@link org.apache.camel.CamelContext} if one is enabled * * @param context the camel context the handlefault intercept strategy is connected to * @return the stream cache or null if none can be found */ public static HandleFault getHandleFault(CamelContext context) { List<InterceptStrategy> list = context.getInterceptStrategies(); for (InterceptStrategy interceptStrategy : list) { if (interceptStrategy instanceof HandleFault) { return (HandleFault)interceptStrategy; } } return null; }
/** * A helper method to return the Delayer instance for a given {@link org.apache.camel.CamelContext} if one is enabled * * @param context the camel context the delayer is connected to * @return the delayer or null if none can be found */ public static Delayer getDelayer(CamelContext context) { List<InterceptStrategy> list = context.getInterceptStrategies(); for (InterceptStrategy interceptStrategy : list) { if (interceptStrategy instanceof Delayer) { return (Delayer)interceptStrategy; } } return null; }
/** * A helper method to return the Tracer instance if one is enabled * * @return the tracer or null if none can be found */ public static Tracer getTracer(CamelContext context) { List<InterceptStrategy> list = context.getInterceptStrategies(); for (InterceptStrategy interceptStrategy : list) { if (interceptStrategy instanceof Tracer) { return (Tracer) interceptStrategy; } } return null; }
/** * A helper method to return the BacklogDebugger instance if one is enabled * * @return the backlog debugger or null if none can be found */ public static BacklogDebugger getBacklogDebugger(CamelContext context) { List<InterceptStrategy> list = context.getInterceptStrategies(); for (InterceptStrategy interceptStrategy : list) { if (interceptStrategy instanceof BacklogDebugger) { return (BacklogDebugger) interceptStrategy; } } return null; }
public boolean hasInterceptorStrategy(Class<?> type) { for (InterceptStrategy strategy : interceptors) { if (type.isInstance(strategy)) { return true; } } return false; }
private InterceptStrategy getOrCreateTracer() { // only use tracer if explicit enabled if (camelContext.isTracing() != null && !camelContext.isTracing()) { return null; } InterceptStrategy tracer = Tracer.getTracer(camelContext); if (tracer == null) { if (camelContext.getRegistry() != null) { // lookup in registry Map<String, Tracer> map = camelContext.getRegistry().findByTypeWithName(Tracer.class); if (map.size() == 1) { tracer = map.values().iterator().next(); } } if (tracer == null) { // fallback to use the default tracer tracer = camelContext.getDefaultTracer(); // configure and use any trace formatter if any exists Map<String, TraceFormatter> formatters = camelContext.getRegistry().findByTypeWithName(TraceFormatter.class); if (formatters.size() == 1) { TraceFormatter formatter = formatters.values().iterator().next(); if (tracer instanceof Tracer) { ((Tracer) tracer).setFormatter(formatter); } } } } return tracer; }
/** * Returns true if the given node should be logged in the trace list */ protected boolean shouldLogNode(ProcessorDefinition<?> node) { if (node == null) { return false; } if (!tracer.isTraceInterceptors() && (node instanceof InterceptStrategy)) { return false; } return true; }
/** * A helper method to return the BacklogTracer instance if one is enabled * * @return the backlog tracer or null if none can be found */ public static BacklogTracer getBacklogTracer(CamelContext context) { List<InterceptStrategy> list = context.getInterceptStrategies(); for (InterceptStrategy interceptStrategy : list) { if (interceptStrategy instanceof BacklogTracer) { return (BacklogTracer) interceptStrategy; } } return null; }
public ObjectName getObjectNameForTracer(CamelContext context, InterceptStrategy tracer) throws MalformedObjectNameException { // use the simple name of the class as the mbean name (eg Tracer, BacklogTracer, BacklogDebugger) String name = tracer.getClass().getSimpleName(); StringBuilder buffer = new StringBuilder(); buffer.append(domainName).append(":"); buffer.append(KEY_CONTEXT + "=").append(getContextId(context)).append(","); buffer.append(KEY_TYPE + "=" + TYPE_TRACER + ","); buffer.append(KEY_NAME + "=").append(name); return createObjectName(buffer); }
public void addInterceptStrategy(InterceptStrategy interceptStrategy) { getInterceptStrategies().add(interceptStrategy); // for backwards compatible or if user add them here instead of the setXXX methods if (interceptStrategy instanceof Tracer) { setTracing(true); } else if (interceptStrategy instanceof HandleFault) { setHandleFault(true); } else if (interceptStrategy instanceof StreamCaching) { setStreamCaching(true); } else if (interceptStrategy instanceof Delayer) { setDelayer(((Delayer)interceptStrategy).getDelay()); } }
public void initStatisticsInterceptor() throws NullPointerException { theContext.addInterceptStrategy(new InterceptStrategy() { public Processor wrapProcessorInInterceptors(CamelContext context, final ProcessorDefinition<?> node, final Processor target, Processor nextTarget) throws Exception { return new DelegateAsyncProcessor(target) { public boolean process(Exchange exchange, AsyncCallback callback) { CamelStat.this.addRowByTargetNode(node.getId()); return super.process(exchange, callback); } }; } }); }
public List<InterceptStrategy> getInterceptStrategies() { return interceptStrategies; }
public void addInterceptStrategy(InterceptStrategy strategy) { this.interceptStrategies.add(strategy); }
public void addInterceptStrategy(InterceptStrategy strategy) { interceptors.add(strategy); }
public void addInterceptStrategies(List<InterceptStrategy> strategies) { interceptors.addAll(strategies); }
public List<InterceptStrategy> getInterceptStrategies() { return interceptors; }
public void setInterceptStrategies(List<InterceptStrategy> interceptStrategies) { this.interceptStrategies = interceptStrategies; }
public void setDefaultTracer(InterceptStrategy tracer) { this.defaultTracer = tracer; }
public InterceptStrategy getDefaultBacklogTracer() { if (defaultBacklogTracer == null) { defaultBacklogTracer = BacklogTracer.createTracer(this); } return defaultBacklogTracer; }
public void setDefaultBacklogTracer(InterceptStrategy backlogTracer) { this.defaultBacklogTracer = backlogTracer; }
public InterceptStrategy getDefaultBacklogDebugger() { if (defaultBacklogDebugger == null) { defaultBacklogDebugger = new BacklogDebugger(this); } return defaultBacklogDebugger; }
public void setDefaultBacklogDebugger(InterceptStrategy defaultBacklogDebugger) { this.defaultBacklogDebugger = defaultBacklogDebugger; }
public void addInterceptStrategy(InterceptStrategy interceptStrategy) { getInterceptStrategies().add(interceptStrategy); }
public void setManagedInterceptStrategy(InterceptStrategy interceptStrategy) { this.managedInterceptStrategy = interceptStrategy; }
public InterceptStrategy getManagedInterceptStrategy() { return managedInterceptStrategy; }
@Override @Inject(optional = true) public void setInterceptStrategies(List<InterceptStrategy> interceptStrategies) { super.setInterceptStrategies(interceptStrategies); }
@Override public void addInterceptStrategy(InterceptStrategy interceptStrategy) { context.addInterceptStrategy(interceptStrategy); }
@Override public List<InterceptStrategy> getInterceptStrategies() { return context.getInterceptStrategies(); }
@Override public InterceptStrategy getDefaultTracer() { return context.getDefaultTracer(); }
@Override public void setDefaultTracer(InterceptStrategy tracer) { context.setDefaultTracer(tracer); }
@Override public InterceptStrategy getDefaultBacklogTracer() { return context.getDefaultBacklogTracer(); }