org.apache.camel.Route.getRouteContext()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(15.3k)|赞(0)|评价(0)|浏览(129)

本文整理了Java中org.apache.camel.Route.getRouteContext方法的一些代码示例,展示了Route.getRouteContext的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Route.getRouteContext方法的具体详情如下:
包路径:org.apache.camel.Route
类名称:Route
方法名:getRouteContext

Route.getRouteContext介绍

暂无

代码示例

代码示例来源:origin: org.apache.camel/camel-zookeeper

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

代码示例来源:origin: org.apache.camel/camel-zookeeper

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

代码示例来源:origin: org.apache.camel/camel-metrics

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;
}

代码示例来源:origin: org.apache.camel/camel-micrometer

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

代码示例来源:origin: org.apache.camel/camel-zookeeper

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

代码示例来源:origin: org.apache.camel/camel-infinispan

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

代码示例来源:origin: funktionio/funktion-connectors

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

代码示例来源:origin: org.apache.camel/camel-micrometer

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

代码示例来源:origin: org.apache.camel/camel-zookeeper

@Override
public void onInit(Route route) {
  ensureElectionIsCreated();
  LOG.info("Route managed by {}. Setting route [{}] AutoStartup flag to false.", this.getClass(), route.getId());
  route.getRouteContext().getRoute().setAutoStartup("false");
  if (election.isMaster()) {
    if (shouldStopRoute) {
      startManagedRoute(route);
    }
  } else {
    if (shouldStopRoute) {
      stopManagedRoute(route);
    }
  }
}

代码示例来源:origin: org.apache.camel/camel-zookeeper

@Override
public void onInit(Route route) {
  ensureElectionIsCreated(route);
  LOG.info("Route managed by {}. Setting route {} AutoStartup flag to false.", this.getClass(), route.getId());
  route.getRouteContext().getRoute().setAutoStartup("false");
  ensureElectionIsCreated(route);
  if (election.isMaster()) {
    if (shouldStopRoute) {
      startManagedRoute(route);
    }
  } else {
    if (shouldStopRoute) {
      stopManagedRoute(route);
    }
  }
}

代码示例来源:origin: com.bosch.bis.monitoring/bis-event-publisher-impl

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

代码示例来源:origin: org.apache.camel/camel-quartz2

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

代码示例来源:origin: org.apache.camel/camel-quartz2

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

代码示例来源:origin: org.apache.camel/camel-quartz

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("quartz", 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.getName(), jobDetail.getGroup());
    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.getFullName(), action, route.getId(), existingJobDetail.getFullName()});
      }
      // 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.getFullName(), action, route.getId());
  }
}

代码示例来源:origin: org.apache.camel/camel-quartz

public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
  SchedulerContext schedulerContext;
  try {
    schedulerContext = jobExecutionContext.getScheduler().getContext();
  } catch (SchedulerException e) {
    throw new JobExecutionException("Failed to obtain scheduler context for job " + jobExecutionContext.getJobDetail().getName());
  }
  
  ScheduledJobState state = (ScheduledJobState) schedulerContext.get(jobExecutionContext.getJobDetail().getName());
  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().getFullName(), e);
    }
  }
}

代码示例来源:origin: org.apache.camel/camel-micrometer

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

代码示例来源:origin: org.drools/drools-camel-legacy5

public JAXBContext getJaxbContext() {
  if ( this.jaxbContext == null ) {
    JaxbDataFormat def = new JaxbDataFormat();
    def.setPrettyPrint( true );
    def.setContextPath( "org.drools.model:org.drools.pipeline.camel" );
    // create a jaxbContext for the test to use outside of Camel.
    StatefulKnowledgeSession ksession1 = (StatefulKnowledgeSession) node.get( "ksession1",
                                         CommandExecutor.class );
    KnowledgeBase kbase = ksession1.getKieBase();
    ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
    try {
      Thread.currentThread().setContextClassLoader( ((ReteooRuleBase) ((KnowledgeBaseImpl) kbase).getRuleBase()).getRootClassLoader() );
      def = DroolsPolicy.augmentJaxbDataFormatDefinition( def );
      org.apache.camel.converter.jaxb.JaxbDataFormat jaxbDataformat = (org.apache.camel.converter.jaxb.JaxbDataFormat) def.getDataFormat( this.context.getRoutes().get( 0 ).getRouteContext() );
      jaxbDataformat.setCamelContext(routeBuilder.getContext());
      try {
        jaxbDataformat.start();
      } catch (Exception e) {
        throw new IllegalStateException(e);
      }
      jaxbContext = jaxbDataformat.getContext();
    } finally {
      Thread.currentThread().setContextClassLoader( originalCl );
    }
  }
  return jaxbContext;
}

代码示例来源:origin: org.drools/drools-camel-legacy5

public JAXBContext getJaxbContext() {
  if ( this.jaxbContext == null ) {
    JaxbDataFormat def = new JaxbDataFormat();
    def.setPrettyPrint( true );
    // TODO does not work: def.setContextPath( "org.drools.camel.testdomain:org.drools.pipeline.camel" );
    def.setContextPath( "org.drools.pipeline.camel" );
    // create a jaxbContext for the test to use outside of Camel.
    StatefulKnowledgeSession ksession1 = (StatefulKnowledgeSession) node.get( "ksession1",
                                         CommandExecutor.class );
    KnowledgeBase kbase = ksession1.getKieBase();
    ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
    try {
      Thread.currentThread().setContextClassLoader( ((ReteooRuleBase) ((KnowledgeBaseImpl) kbase).getRuleBase()).getRootClassLoader() );
      def = DroolsPolicy.augmentJaxbDataFormatDefinition( def );
      org.apache.camel.converter.jaxb.JaxbDataFormat jaxbDataformat = (org.apache.camel.converter.jaxb.JaxbDataFormat) def.getDataFormat( this.context.getRoutes().get( 0 ).getRouteContext() );
      jaxbDataformat.setCamelContext(routeBuilder.getContext());
      try {
        jaxbDataformat.start();
      } catch (Exception e) {
        throw new IllegalStateException(e);
      }
      jaxbContext = jaxbDataformat.getContext();
    } finally {
      Thread.currentThread().setContextClassLoader( originalCl );
    }
  }
  return jaxbContext;
}

代码示例来源:origin: org.apache.camel/camel-quartz

protected void doOnInit(Route route) throws Exception {
  QuartzComponent quartz = route.getRouteContext().getCamelContext().getComponent("quartz", QuartzComponent.class);
  setScheduler(quartz.getScheduler());
  // Important: do not start scheduler as QuartzComponent does that automatic
  // when CamelContext has been fully initialized and started
  if (getRouteStopGracePeriod() == 0) {
    setRouteStopGracePeriod(10000);
  }
  if (getTimeUnit() == null) {
    setTimeUnit(TimeUnit.MILLISECONDS);
  }
  // validate time options has been configured
  if ((getRouteStartTime() == null) && (getRouteStopTime() == null) && (getRouteSuspendTime() == null) && (getRouteResumeTime() == null)) {
    throw new IllegalArgumentException("Scheduled Route Policy for route " + route.getId() + " has no start/stop/suspend/resume times specified");
  }
  registerRouteToScheduledRouteDetails(route);
  if (getRouteStartTime() != null) {
    scheduleRoute(Action.START, route);
  }
  if (getRouteStopTime() != null) {
    scheduleRoute(Action.STOP, route);
  }
  if (getRouteSuspendTime() != null) {
    scheduleRoute(Action.SUSPEND, route);
  }
  if (getRouteResumeTime() != null) {
    scheduleRoute(Action.RESUME, route);
  }
}

代码示例来源:origin: org.apache.camel/camel-quartz

protected void doOnInit(Route route) throws Exception {
  QuartzComponent quartz = route.getRouteContext().getCamelContext().getComponent("quartz", QuartzComponent.class);
  setScheduler(quartz.getScheduler());
  // Important: do not start scheduler as QuartzComponent does that automatic
  // when CamelContext has been fully initialized and started
  if (getRouteStopGracePeriod() == 0) {
    setRouteStopGracePeriod(10000);
  }
  if (getTimeUnit() == null) {
    setTimeUnit(TimeUnit.MILLISECONDS);
  }
  // validate time options has been configured
  if ((getRouteStartDate() == null) && (getRouteStopDate() == null) && (getRouteSuspendDate() == null) && (getRouteResumeDate() == null)) {
    throw new IllegalArgumentException("Scheduled Route Policy for route " + route.getId() + " has no start/stop/suspend/resume times specified");
  }
  registerRouteToScheduledRouteDetails(route);
  if (getRouteStartDate() != null) {
    scheduleRoute(Action.START, route);
  }
  if (getRouteStopDate() != null) {
    scheduleRoute(Action.STOP, route);
  }
  if (getRouteSuspendDate() != null) {
    scheduleRoute(Action.SUSPEND, route);
  }
  if (getRouteResumeDate() != null) {
    scheduleRoute(Action.RESUME, route);
  }
}

相关文章