TransactionErrorHandler answer = new TransactionErrorHandler(routeContext.getCamelContext(), processor, getLogger(), getOnRedelivery(), getRedeliveryPolicy(), getExceptionPolicyStrategy(), transactionTemplate, getRetryWhilePolicy(routeContext.getCamelContext()), getExecutorService(routeContext.getCamelContext()), getRollbackLoggingLevel(), getOnExceptionOccurred());
public Processor wrap(RouteContext routeContext, ProcessorDefinition<?> definition, Processor processor) { if (processor == null) { return null; } if (processor instanceof FilterProcessor) { return processor; } BreadcrumbsProcessor breadcrumbsProcessor = new BreadcrumbsProcessor(this, processor); breadcrumbsProcessor.setCamelContext(routeContext.getCamelContext()); if (processor instanceof CamelContextAware) { ((CamelContextAware) processor).setCamelContext(routeContext.getCamelContext()); } return breadcrumbsProcessor; }
@Override public Processor createProcessor(RouteContext routeContext) throws Exception { Processor delegate = doCreateDelegate(routeContext); Processor next = createChildProcessor(routeContext, false); List<Processor> processors = new ArrayList<>(); processors.add(delegate); if (next != null) { processors.add(next); } return Pipeline.newInstance(routeContext.getCamelContext(), processors); }
private void forceAutoAssigningIds() { for (RouteContext routeContext : routeContexts) { CamelContext camelContext = routeContext.getCamelContext(); NodeIdFactory factory = camelContext.getNodeIdFactory(); if (factory != null) { for (ProcessorDefinition<?> child : processors) { // ensure also the children get ids assigned RouteDefinitionHelper.forceAssignIds(camelContext, child); } } } }
private void ensureElectionIsCreated(Route route) { if (election == null) { electionLock.lock(); try { if (election == null) { // re-test election = new ZooKeeperElection(route.getRouteContext().getCamelContext(), uri, enabledCount); election.addElectionWatcher(this); } } finally { electionLock.unlock(); } } }
private void ensureElectionIsCreated(Route route) { if (election == null) { electionLock.lock(); try { if (election == null) { // re-test election = new CuratorLeaderElection(route.getRouteContext().getCamelContext(), uri); election.addElectionWatcher(this); } } finally { electionLock.unlock(); } } }
private void forceAutoAssigningIds() { for (RouteContext routeContext : routeContexts) { CamelContext camelContext = routeContext.getCamelContext(); NodeIdFactory factory = camelContext.getNodeIdFactory(); if (factory != null) { for (ProcessorDefinition<?> child : processors) { // ensure also the children get ids assigned RouteDefinitionHelper.forceAssignIds(camelContext, child); } } } }
public Processor wrap(RouteContext routeContext, ProcessorDefinition<?> definition, Processor proc) { if (proc == null) { return null; } RouteDefinition route = ProcessorDefinitionHelper.getRoute(definition); if (route != null) { if (routeContext.getCamelContext().getNodeIdFactory() != null) { RouteDefinitionHelper.forceAssignIds(routeContext.getCamelContext(), route); } } return new ProfilerProcessor(this, proc, getStats(definition), exchanges); }
private String createName(String type) { CamelContext context = route.getRouteContext().getCamelContext(); String name = context.getManagementName() != null ? context.getManagementName() : context.getName(); String answer = namePattern; answer = answer.replaceFirst("##name##", name); answer = answer.replaceFirst("##routeId##", Matcher.quoteReplacement(route.getId())); answer = answer.replaceFirst("##type##", type); return answer; }
public Processor wrap(RouteContext routeContext, ProcessorDefinition<?> definition, Processor processor) { if (processor == null) { return null; } // is this the first output from a route, as we want to know this so we can do special logic in first boolean first = false; RouteDefinition route = ProcessorDefinitionHelper.getRoute(definition); if (route != null) { if (routeContext.getCamelContext().getNodeIdFactory() != null) { RouteDefinitionHelper.forceAssignIds(routeContext.getCamelContext(), route); } if (!route.getOutputs().isEmpty()) { first = route.getOutputs().get(0) == definition; } } routeContexts.add(routeContext); processors.add(definition); TraceProcessor traceProcessor = new TraceProcessor(queue, processor, definition, route, first, this); traceProcessor.setCamelContext(routeContext.getCamelContext()); if (processor instanceof CamelContextAware) { ((CamelContextAware) processor).setCamelContext(routeContext.getCamelContext()); } return traceProcessor; }
public Processor wrap(RouteContext routeContext, ProcessorDefinition<?> definition, Processor processor) { if (processor == null) { return null; } // is this the first output from a route, as we want to know this so we can do special logic in first boolean first = false; RouteDefinition route = ProcessorDefinitionHelper.getRoute(definition); if (route != null) { if (routeContext.getCamelContext().getNodeIdFactory() != null) { RouteDefinitionHelper.forceAssignIds(routeContext.getCamelContext(), route); } if (!route.getOutputs().isEmpty()) { first = route.getOutputs().get(0) == definition; } } routeContexts.add(routeContext); processors.add(definition); return new TraceProcessor(queue, processor, definition, route, first, this); }
default Tags getTags(Route route, Exchange exchange) { return Tags.of( CAMEL_CONTEXT_TAG, route.getRouteContext().getCamelContext().getName(), SERVICE_NAME, MicrometerRoutePolicyService.class.getSimpleName(), ROUTE_ID_TAG, route.getId(), FAILED_TAG, Boolean.toString(exchange.isFailed()) ); }
private void startAllStoppedRoutes() { try { lock.lock(); if (!suspendedRoutes.isEmpty()) { if (log.isDebugEnabled()) { log.info("{} route(s) have been stopped previously by policy, restarting.", suspendedRoutes.size()); } for (Route suspended : suspendedRoutes) { DefaultCamelContext ctx = (DefaultCamelContext)suspended.getRouteContext().getCamelContext(); while (!ctx.isStarted()) { log.info("Context {} is not started yet. Sleeping for a bit.", ctx.getName()); Thread.sleep(5000); } log.info("Starting route [{}] defined in context [{}].", suspended.getId(), ctx.getName()); startRoute(suspended); } suspendedRoutes.clear(); } } catch (Exception e) { handleException(e); } finally { lock.unlock(); } }
default Tags getTags(Route route, NamedNode node) { return Tags.of( CAMEL_CONTEXT_TAG, route.getRouteContext().getCamelContext().getName(), SERVICE_NAME, MicrometerMessageHistoryService.class.getSimpleName(), ROUTE_ID_TAG, route.getId(), NODE_ID_TAG, node.getId() ); }
/** * Allows to stop a route asynchronously using a separate background thread which can allow any current in-flight exchange * to complete while the route is being shutdown. * You may attempt to stop a route from processing an exchange which would be in-flight and therefore attempting to stop * the route will defer due there is an inflight exchange in-progress. By stopping the route independently using a separate * thread ensures the exchange can continue process and complete and the route can be stopped. */ // TODO: in Camel 2.19 there is a stopRouteAsync method we can use private void stopCurrentRouteAsync(final Route route) { String threadId = route.getRouteContext().getCamelContext().getExecutorServiceManager().resolveThreadName("StopRouteAsync"); Runnable task = () -> { try { route.getRouteContext().getCamelContext().stopRoute(route.getId()); } catch (Exception e) { handleException(e); } }; new Thread(task, threadId).start(); }
private static Dedupe createDedupe(RouteContext routeContext) { CamelContext camelContext = routeContext.getCamelContext(); Dedupe dedupe = Contexts.beanOrNull(Dedupe.class, camelContext); if (dedupe != null) { return dedupe; } dedupe = new Dedupe(); dedupe.setFlowManager(Contexts.bean(FlowManager.class, camelContext)); return dedupe; }
private static FlowErrorProcessor createFlowErrorProcessor(RouteContext routeContext) { CamelContext camelContext = routeContext.getCamelContext(); FlowErrorProcessor processor = Contexts.beanOrNull(FlowErrorProcessor.class, camelContext); if (processor != null) { return processor; } processor = new FlowErrorProcessor(); processor.setCamelContext(camelContext); processor.setFlowManager(Contexts.bean(FlowManager.class, camelContext)); return processor; }
private static FlowEndProcessor createFlowEndProcessor(RouteContext routeContext) { CamelContext camelContext = routeContext.getCamelContext(); FlowEndProcessor processor = Contexts.beanOrNull(FlowEndProcessor.class, camelContext); if (processor != null) { return processor; } processor = new FlowEndProcessor(); processor.setCamelContext(camelContext); processor.setFlowManager(Contexts.bean(FlowManager.class, camelContext)); return processor; }
private void reportNonCustomRouteIDs(Route route) { CamelContext camelContext = route.getRouteContext().getCamelContext(); RouteDefinition routeDefinition = camelContext.getRouteDefinition(route.getId()); if (routeDefinition.getCustomId() == null || !routeDefinition.getCustomId()) { LOG.warn("Problem detected: Route " + StringUtils.quote(route.getId()) + " has no custom ID set! Endpoint URI is " + route.getEndpoint().getEndpointUri()); } }
private static FlowBeginProcessor createFlowBeginProcessor(RouteContext routeContext) { CamelContext camelContext = routeContext.getCamelContext(); // Try to obtain a FlowBeginProcessor bean (its definition is optional) FlowBeginProcessor processor = Contexts.beanOrNull(FlowBeginProcessor.class, camelContext); if (processor != null) { return processor; } // No FlowBeginProcessor bean found so let's create one. We need a // - reference to a ReplayStrategyRegistry // - reference to a FlowManager processor = new FlowBeginProcessor(); processor.setCamelContext(camelContext); processor.setFlowManager(Contexts.bean(FlowManager.class, camelContext)); processor.setRegistry(Contexts.bean(ReplayStrategyRegistry.class, camelContext)); return processor; }