Java 类org.apache.camel.spi.InterceptStrategy 实例源码

项目:Camel    文件:DefaultChannel.java   
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;
}
项目:Camel    文件:DefaultChannel.java   
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;
}
项目:Camel    文件:ProcessorDefinition.java   
/**
 * 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);
    }
}
项目:Camel    文件:InterceptDefinition.java   
@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;
}
项目:Camel    文件:StreamCaching.java   
/**
 * 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;
}
项目:Camel    文件:StreamCaching.java   
/**
 * 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);
        }
    }
}
项目:Camel    文件:HandleFault.java   
/**
 * 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;
}
项目:Camel    文件:Delayer.java   
/**
 * 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;
}
项目:Camel    文件:Tracer.java   
/**
 * 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;
}
项目:Camel    文件:BacklogDebugger.java   
/**
 * 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;
}
项目:Camel    文件:DefaultChannel.java   
public boolean hasInterceptorStrategy(Class<?> type) {
    for (InterceptStrategy strategy : interceptors) {
        if (type.isInstance(strategy)) {
            return true;
        }
    }
    return false;
}
项目:Camel    文件:DefaultChannel.java   
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;
}
项目:Camel    文件:TraceInterceptor.java   
/**
 * 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;
}
项目:Camel    文件:BacklogTracer.java   
/**
 * 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;
}
项目:Camel    文件:DefaultManagementNamingStrategy.java   
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);
}
项目:Camel    文件:DefaultCamelContext.java   
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());
    }
}
项目:bio2rdf-rest    文件:CamelStat.java   
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);
            }
        };
    }
});
  }
项目:Camel    文件:ProcessorDefinition.java   
public List<InterceptStrategy> getInterceptStrategies() {
    return interceptStrategies;
}
项目:Camel    文件:ProcessorDefinition.java   
public void addInterceptStrategy(InterceptStrategy strategy) {
    this.interceptStrategies.add(strategy);
}
项目:Camel    文件:DefaultChannel.java   
public void addInterceptStrategy(InterceptStrategy strategy) {
    interceptors.add(strategy);
}
项目:Camel    文件:DefaultChannel.java   
public void addInterceptStrategies(List<InterceptStrategy> strategies) {
    interceptors.addAll(strategies);
}
项目:Camel    文件:DefaultChannel.java   
public List<InterceptStrategy> getInterceptStrategies() {
    return interceptors;
}
项目:Camel    文件:DefaultCamelContext.java   
public List<InterceptStrategy> getInterceptStrategies() {
    return interceptStrategies;
}
项目:Camel    文件:DefaultCamelContext.java   
public void setInterceptStrategies(List<InterceptStrategy> interceptStrategies) {
    this.interceptStrategies = interceptStrategies;
}
项目:Camel    文件:DefaultCamelContext.java   
public void setDefaultTracer(InterceptStrategy tracer) {
    this.defaultTracer = tracer;
}
项目:Camel    文件:DefaultCamelContext.java   
public InterceptStrategy getDefaultBacklogTracer() {
    if (defaultBacklogTracer == null) {
        defaultBacklogTracer = BacklogTracer.createTracer(this);
    }
    return defaultBacklogTracer;
}
项目:Camel    文件:DefaultCamelContext.java   
public void setDefaultBacklogTracer(InterceptStrategy backlogTracer) {
    this.defaultBacklogTracer = backlogTracer;
}
项目:Camel    文件:DefaultCamelContext.java   
public InterceptStrategy getDefaultBacklogDebugger() {
    if (defaultBacklogDebugger == null) {
        defaultBacklogDebugger = new BacklogDebugger(this);
    }
    return defaultBacklogDebugger;
}
项目:Camel    文件:DefaultCamelContext.java   
public void setDefaultBacklogDebugger(InterceptStrategy defaultBacklogDebugger) {
    this.defaultBacklogDebugger = defaultBacklogDebugger;
}
项目:Camel    文件:DefaultRouteContext.java   
public List<InterceptStrategy> getInterceptStrategies() {
    return interceptStrategies;
}
项目:Camel    文件:DefaultRouteContext.java   
public void setInterceptStrategies(List<InterceptStrategy> interceptStrategies) {
    this.interceptStrategies = interceptStrategies;
}
项目:Camel    文件:DefaultRouteContext.java   
public void addInterceptStrategy(InterceptStrategy interceptStrategy) {
    getInterceptStrategies().add(interceptStrategy);
}
项目:Camel    文件:DefaultRouteContext.java   
public void setManagedInterceptStrategy(InterceptStrategy interceptStrategy) {
    this.managedInterceptStrategy = interceptStrategy;
}
项目:Camel    文件:DefaultRouteContext.java   
public InterceptStrategy getManagedInterceptStrategy() {
    return managedInterceptStrategy;
}
项目:Camel    文件:GuiceCamelContext.java   
@Override
@Inject(optional = true)
public void setInterceptStrategies(List<InterceptStrategy> interceptStrategies) {
    super.setInterceptStrategies(interceptStrategies);
}
项目:microservice-bundle    文件:ManagedCamelContext.java   
@Override
public void addInterceptStrategy(InterceptStrategy interceptStrategy) {
  context.addInterceptStrategy(interceptStrategy);
}
项目:microservice-bundle    文件:ManagedCamelContext.java   
@Override
public List<InterceptStrategy> getInterceptStrategies() {
  return context.getInterceptStrategies();
}
项目:microservice-bundle    文件:ManagedCamelContext.java   
@Override
public InterceptStrategy getDefaultTracer() {
  return context.getDefaultTracer();
}
项目:microservice-bundle    文件:ManagedCamelContext.java   
@Override
public void setDefaultTracer(InterceptStrategy tracer) {
  context.setDefaultTracer(tracer);
}
项目:microservice-bundle    文件:ManagedCamelContext.java   
@Override
public InterceptStrategy getDefaultBacklogTracer() {
  return context.getDefaultBacklogTracer();
}