Refine search
Map<String, TransactedPolicy> mapPolicy = routeContext.lookupByType(TransactedPolicy.class); if (mapPolicy != null && mapPolicy.size() == 1) { TransactedPolicy policy = mapPolicy.values().iterator().next(); TransactedPolicy policy = routeContext.lookup(PROPAGATION_REQUIRED, TransactedPolicy.class); if (policy instanceof SpringTransactionPolicy) { transactionTemplate = ((SpringTransactionPolicy) policy).getTransactionTemplate(); Map<String, TransactionTemplate> mapTemplate = routeContext.lookupByType(TransactionTemplate.class); if (mapTemplate == null || mapTemplate.isEmpty()) { LOG.trace("No TransactionTemplate found in registry."); Map<String, PlatformTransactionManager> mapManager = routeContext.lookupByType(PlatformTransactionManager.class); if (mapManager == null || mapManager.isEmpty()) { LOG.trace("No PlatformTransactionManager found in registry."); ObjectHelper.notNull(transactionTemplate, "transactionTemplate", this); TransactionErrorHandler answer = new TransactionErrorHandler(routeContext.getCamelContext(), processor, getLogger(), getOnRedelivery(), getRedeliveryPolicy(), getExceptionPolicyStrategy(), transactionTemplate, getRetryWhilePolicy(routeContext.getCamelContext()), getExecutorService(routeContext.getCamelContext()), getRollbackLoggingLevel(), getOnExceptionOccurred());
@Override public synchronized void onInit(Route route) { super.onInit(route); LOGGER.info("Route managed by {}. Setting route {} AutoStartup flag to false.", getClass(), route.getId()); route.getRouteContext().getRoute().setAutoStartup("false"); stoppeddRoutes.add(route); this.refCount.retain(); startManagedRoutes(); }
@Override public void onInit(Route route) { super.onInit(route); if (getMeterRegistry() == null) { setMeterRegistry(MicrometerUtils.getOrCreateMeterRegistry( route.getRouteContext().getCamelContext().getRegistry(), METRICS_REGISTRY_NAME)); } try { MicrometerRoutePolicyService registryService = route.getRouteContext().getCamelContext().hasService(MicrometerRoutePolicyService.class); if (registryService == null) { registryService = new MicrometerRoutePolicyService(); registryService.setMeterRegistry(getMeterRegistry()); registryService.setPrettyPrint(isPrettyPrint()); registryService.setDurationUnit(getDurationUnit()); registryService.setMatchingTags(Tags.of(SERVICE_NAME, MicrometerRoutePolicyService.class.getSimpleName())); route.getRouteContext().getCamelContext().addService(registryService); ServiceHelper.startService(registryService); } } catch (Exception e) { throw ObjectHelper.wrapRuntimeCamelException(e); } // create statistics holder // for now we record only all the timings of a complete exchange (responses) // we have in-flight / total statistics already from camel-core statistics = new MetricsStatistics(getMeterRegistry(), route, getNamingStrategy()); }
public void scheduleRoute(Action action, Route route) throws Exception { JobDetail jobDetail = createJobDetail(action, route); Trigger trigger = createTrigger(action, route); updateScheduledRouteDetails(action, jobDetail, trigger, route); loadCallbackDataIntoSchedulerContext(jobDetail, action, route); boolean isClustered = route.getRouteContext().getCamelContext().getComponent("quartz2", QuartzComponent.class).isClustered(); if (isClustered) { // check to see if the same job has already been setup through another node of the cluster JobDetail existingJobDetail = getScheduler().getJobDetail(jobDetail.getKey()); if (jobDetail.equals(existingJobDetail)) { if (LOG.isInfoEnabled()) { LOG.info("Skipping to schedule the job: {} for action: {} on route {} as the job: {} already existing inside the cluster", new Object[] {jobDetail.getKey(), action, route.getId(), existingJobDetail.getKey()}); } // skip scheduling the same job again as one is already existing for the same routeId and action return; } } getScheduler().scheduleJob(jobDetail, trigger); if (LOG.isInfoEnabled()) { LOG.info("Scheduled trigger: {} for action: {} on route {}", trigger.getKey(), action, route.getId()); } }
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; }
/** * 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(); }
protected void onJobExecute(Action action, Route route) throws Exception { LOG.debug("Scheduled Event notification received. Performing action: {} on route: {}", action, route.getId()); ServiceStatus routeStatus = route.getRouteContext().getCamelContext().getRouteStatus(route.getId()); if (action == Action.START) { if (routeStatus == ServiceStatus.Stopped) {
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 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(); } }
this.sourceContextId = source.getContext().getName(); ? null : source.getUnitOfWork().getRouteContext().getRoute().getId(); this.breadCrumbId = getBreadCrumbId(source); this.exception = source.getException() == null ? source.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class) : source.getException();
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { LOG.debug("Running ScheduledJob: jobExecutionContext={}", jobExecutionContext); SchedulerContext schedulerContext = getSchedulerContext(jobExecutionContext); ScheduledJobState state = (ScheduledJobState) schedulerContext.get(jobExecutionContext.getJobDetail().getKey().toString()); Action storedAction = state.getAction(); Route storedRoute = state.getRoute(); List<RoutePolicy> policyList = storedRoute.getRouteContext().getRoutePolicyList(); for (RoutePolicy policy : policyList) { try { if (policy instanceof ScheduledRoutePolicy) { ((ScheduledRoutePolicy)policy).onJobExecute(storedAction, storedRoute); } } catch (Exception e) { throw new JobExecutionException("Failed to execute Scheduled Job for route " + storedRoute.getId() + " with trigger name: " + jobExecutionContext.getTrigger().getKey(), e); } } }
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); }
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; }
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 static DataFormatDefinition processDataFormatType(RouteContext routeContext, String ref, DataFormatDefinition dformatDefinition) { if ( dformatDefinition == null ) { if ( "json".equals( ref ) ) { dformatDefinition = new XStreamDataFormat(); ((XStreamDataFormat) dformatDefinition).setDriver( "json" ); } else if ( "xstream".equals( ref ) ) { dformatDefinition = new XStreamDataFormat(); } else if ( "jaxb".equals( ref ) ) { dformatDefinition = new JaxbDataFormat(); } else { dformatDefinition = routeContext.getCamelContext().resolveDataFormatDefinition( ref ); } } // always clone before changing dformatDefinition = new FastCloner().deepClone( dformatDefinition ); if ( dformatDefinition instanceof JaxbDataFormat ) { dformatDefinition = augmentJaxbDataFormatDefinition( (JaxbDataFormat) dformatDefinition ); } else if ( dformatDefinition instanceof XStreamDataFormat ) { XStreamDataFormat xstreamDataFormat = (XStreamDataFormat) dformatDefinition; if ( "json".equals( xstreamDataFormat.getDriver() ) ) { dformatDefinition = XStreamJson.newJSonMarshaller( xstreamDataFormat );; } else { dformatDefinition = XStreamXml.newXStreamMarshaller( (XStreamDataFormat) dformatDefinition ); } } return dformatDefinition; }
ErrorHandlerBuilder builder = (ErrorHandlerBuilder)routeContext.getRoute().getErrorHandlerBuilder(); routeContext.getRoute().setErrorHandlerBuilder(txBuilder);
@Override protected Processor doCreateDelegate(RouteContext routeContext) { if (auditProcessorBeanName != null) { auditProcessor = routeContext.lookup(auditProcessorBeanName, Processor.class); } return auditProcessor; }
public Processor wrap(RouteContext routeContext, Processor processor) { RouteDefinition routeDef = routeContext.getRoute(); ToDefinition toDrools = getDroolsNode( routeDef ); Processor returnedProcessor; if ( toDrools != null ) { returnedProcessor = new DroolsProcess( toDrools.getUri(), processor ); } else { returnedProcessor = processor;//new DroolsClientProcessor( processor ); } return returnedProcessor; }