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

项目:Camel    文件:ScheduledJob.java   
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);
        }
    }
}
项目:Camel    文件:CamelInternalProcessor.java   
@Override
public void after(Exchange exchange, Object data) throws Exception {
    // do not invoke it if Camel is stopping as we don't want
    // the policy to start a consumer during Camel is stopping
    if (isCamelStopping(exchange.getContext())) {
        return;
    }

    for (RoutePolicy policy : routePolicies) {
        try {
            if (isRoutePolicyRunAllowed(policy)) {
                policy.onExchangeDone(route, exchange);
            }
        } catch (Exception e) {
            LOG.warn("Error occurred during onExchangeDone on RoutePolicy: " + policy
                    + ". This exception will be ignored", e);
        }
    }
}
项目:Camel    文件:ManagedRoute.java   
public String getRoutePolicyList() {
    List<RoutePolicy> policyList = route.getRouteContext().getRoutePolicyList();

    if (policyList == null || policyList.isEmpty()) {
        // return an empty string to have it displayed nicely in JMX consoles
        return "";
    }

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < policyList.size(); i++) {
        RoutePolicy policy = policyList.get(i);
        sb.append(policy.getClass().getSimpleName());
        sb.append("(").append(ObjectHelper.getIdentityHashCode(policy)).append(")");
        if (i < policyList.size() - 1) {
            sb.append(", ");
        }
    }
    return sb.toString();
}
项目:Camel    文件:RouteService.java   
protected void doStart() throws Exception {
    warmUp();

    for (Route route : routes) {
        // start the route itself
        ServiceHelper.startService(route);

        // invoke callbacks on route policy
        if (route.getRouteContext().getRoutePolicyList() != null) {
            for (RoutePolicy routePolicy : route.getRouteContext().getRoutePolicyList()) {
                routePolicy.onStart(route);
            }
        }

        // fire event
        EventHelper.notifyRouteStarted(camelContext, route);
    }
}
项目:Camel    文件:FlipRoutePolicyTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            // create the flip route policy
            RoutePolicy policy = new FlipRoutePolicy("foo", "bar");

            // use the flip route policy in the foo route
            from("timer://foo")
                .routeId("foo").routePolicy(policy)
                .setBody().constant("Foo message")
                .to("log:foo")
                .to("mock:foo");

            // use the flip route policy in the bar route and do NOT start
            // this route on startup
            from("timer://bar")
                .routeId("bar").routePolicy(policy).noAutoStartup()
                .setBody().constant("Bar message")
                .to("log:bar")
                .to("mock:bar");
        }
    };
}
项目:camelinaction2    文件:FlipRoutePolicyJavaDSLTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            // create the flip route policy
            RoutePolicy policy = new FlipRoutePolicy("foo", "bar");

            // use the flip route policy in the foo route
            from("timer:foo?delay=500")
                .routeId("foo").routePolicy(policy)
                .setBody().constant("Foo message")
                .to("log:foo")
                .to("mock:foo");

            // use the flip route policy in the bar route and do NOT start
            // this route on startup
            from("timer:bar?delay=500")
                .routeId("bar").routePolicy(policy).noAutoStartup()
                .setBody().constant("Bar message")
                .to("log:bar")
                .to("mock:bar");
        }
    };
}
项目:camelinaction    文件:FlipRoutePolicyJavaDSLTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            // create the flip route policy
            RoutePolicy policy = new FlipRoutePolicy("foo", "bar");

            // use the flip route policy in the foo route
            from("timer://foo?delay=500")
                .routeId("foo").routePolicy(policy)
                .setBody().constant("Foo message")
                .to("log:foo")
                .to("mock:foo");

            // use the flip route policy in the bar route and do NOT start
            // this route on startup
            from("timer://bar?delay=500")
                .routeId("bar").routePolicy(policy).noAutoStartup()
                .setBody().constant("Bar message")
                .to("log:bar")
                .to("mock:bar");
        }
    };
}
项目:t4f-data    文件:FlipRoutePolicyJavaDSLTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            // create the flip route policy
            RoutePolicy policy = new FlipRoutePolicy("foo", "bar");

            // use the flip route policy in the foo route
            from("timer://foo")
                .routeId("foo").routePolicy(policy)
                .setBody().constant("Foo message")
                .to("log:foo")
                .to("mock:foo");

            // use the flip route policy in the bar route and do NOT start
            // this route on startup
            from("timer://bar")
                .routeId("bar").routePolicy(policy).noAutoStartup()
                .setBody().constant("Bar message")
                .to("log:bar")
                .to("mock:bar");
        }
    };
}
项目:Camel    文件:RouteDefinition.java   
/**
 * Configures route policies for this route
 *
 * @param policies the route policies
 * @return the builder
 */
public RouteDefinition routePolicy(RoutePolicy... policies) {
    if (routePolicies == null) {
        routePolicies = new ArrayList<RoutePolicy>();
    }
    for (RoutePolicy policy : policies) {
        routePolicies.add(policy);
    }
    return this;
}
项目:Camel    文件:CamelInternalProcessor.java   
/**
 * Strategy to determine if this policy is allowed to run
 *
 * @param policy the policy
 * @return <tt>true</tt> to run
 */
protected boolean isRoutePolicyRunAllowed(RoutePolicy policy) {
    if (policy instanceof StatefulService) {
        StatefulService ss = (StatefulService) policy;
        return ss.isRunAllowed();
    }
    return true;
}
项目:Camel    文件:CamelInternalProcessor.java   
@Override
public Object before(Exchange exchange) throws Exception {
    // invoke begin
    for (RoutePolicy policy : routePolicies) {
        try {
            if (isRoutePolicyRunAllowed(policy)) {
                policy.onExchangeBegin(route, exchange);
            }
        } catch (Exception e) {
            LOG.warn("Error occurred during onExchangeBegin on RoutePolicy: " + policy
                    + ". This exception will be ignored", e);
        }
    }
    return null;
}
项目:Camel    文件:RouteService.java   
@Override
protected void doSuspend() throws Exception {
    // suspend and resume logic is provided by DefaultCamelContext which leverages ShutdownStrategy
    // to safely suspend and resume
    for (Route route : routes) {
        if (route.getRouteContext().getRoutePolicyList() != null) {
            for (RoutePolicy routePolicy : route.getRouteContext().getRoutePolicyList()) {
                routePolicy.onSuspend(route);
            }
        }
    }
}
项目:Camel    文件:RouteService.java   
@Override
protected void doResume() throws Exception {
    // suspend and resume logic is provided by DefaultCamelContext which leverages ShutdownStrategy
    // to safely suspend and resume
    for (Route route : routes) {
        if (route.getRouteContext().getRoutePolicyList() != null) {
            for (RoutePolicy routePolicy : route.getRouteContext().getRoutePolicyList()) {
                routePolicy.onResume(route);
            }
        }
    }
}
项目:Camel    文件:MultiplePoliciesOnRouteTest.java   
private RoutePolicy createRouteStartPolicy() {
    SimpleScheduledRoutePolicy policy = new SimpleScheduledRoutePolicy();
    long startTime = System.currentTimeMillis() + 3000L;
    policy.setRouteStartDate(new Date(startTime));
    policy.setRouteStartRepeatCount(1);
    policy.setRouteStartRepeatInterval(3000);

    return policy;
}
项目:Camel    文件:SpringScheduledRoutePolicyTest.java   
@SuppressWarnings("unchecked")
private CamelContext startRouteWithPolicy(String policyBeanName) throws Exception {
    CamelContext context = new DefaultCamelContext();
    List<RouteDefinition> routes = (List<RouteDefinition>)applicationContext.getBean("testRouteContext");
    RoutePolicy policy = applicationContext.getBean(policyBeanName, RoutePolicy.class);
    assertTrue(getTestType() == TestType.SIMPLE 
        ? policy instanceof SimpleScheduledRoutePolicy 
        : policy instanceof CronScheduledRoutePolicy);
    routes.get(0).routePolicy(policy);
    ((ModelCamelContext)context).addRouteDefinitions(routes);
    context.start();
    return context;
}
项目:Camel    文件:MetricsRoutePolicyFactory.java   
@Override
public RoutePolicy createRoutePolicy(CamelContext camelContext, String routeId, RouteDefinition routeDefinition) {
    MetricsRoutePolicy answer = new MetricsRoutePolicy();
    answer.setMetricsRegistry(getMetricsRegistry());
    answer.setUseJmx(isUseJmx());
    answer.setJmxDomain(getJmxDomain());
    answer.setPrettyPrint(isPrettyPrint());
    answer.setRateUnit(getRateUnit());
    answer.setDurationUnit(getDurationUnit());
    return answer;
}
项目:Camel    文件:MultiplePoliciesOnRouteTest.java   
private RoutePolicy createRouteStartPolicy() {
    SimpleScheduledRoutePolicy policy = new SimpleScheduledRoutePolicy();
    long startTime = System.currentTimeMillis() + 3000L;
    policy.setRouteStartDate(new Date(startTime));
    policy.setRouteStartRepeatCount(1);
    policy.setRouteStartRepeatInterval(3000);

    return policy;
}
项目:Camel    文件:SpringScheduledRoutePolicyTest.java   
@SuppressWarnings("unchecked")
private CamelContext startRouteWithPolicy(String policyBeanName) throws Exception {
    CamelContext context = new DefaultCamelContext();
    List<RouteDefinition> routes = (List<RouteDefinition>)applicationContext.getBean("testRouteContext");
    RoutePolicy policy = applicationContext.getBean(policyBeanName, RoutePolicy.class);
    assertTrue(getTestType() == TestType.SIMPLE 
        ? policy instanceof SimpleScheduledRoutePolicy 
        : policy instanceof CronScheduledRoutePolicy);
    routes.get(0).routePolicy(policy);
    ((ModelCamelContext)context).addRouteDefinitions(routes);
    context.start();
    return context;
}
项目:syndesis    文件:SingleMessageRoutePolicyFactory.java   
@Override
public RoutePolicy createRoutePolicy(CamelContext camelContext, String s, RouteDefinition routeDefinition) {
    return new SingleMessageRoutePolicy();
}
项目:syndesis-integration-runtime    文件:SingleMessageRoutePolicyFactory.java   
@Override
public RoutePolicy createRoutePolicy(CamelContext camelContext, String s, RouteDefinition routeDefinition) {
    return new SingleMessageRoutePolicy();
}
项目:funktion-connectors    文件:SingleMessageRoutePolicyFactory.java   
@Override
public RoutePolicy createRoutePolicy(CamelContext camelContext, String routeId, RouteDefinition route) {
    return new SingleMessageRoutePolicy();
}
项目:Camel    文件:RouteDefinition.java   
public List<RoutePolicy> getRoutePolicies() {
    return routePolicies;
}
项目:Camel    文件:RouteDefinition.java   
@XmlTransient
public void setRoutePolicies(List<RoutePolicy> routePolicies) {
    this.routePolicies = routePolicies;
}
项目:Camel    文件:CamelInternalProcessor.java   
public RoutePolicyAdvice(List<RoutePolicy> routePolicies) {
    this.routePolicies = routePolicies;
}
项目:Camel    文件:RouteService.java   
protected void doStop() throws Exception {

        // if we are stopping CamelContext then we are shutting down
        boolean isShutdownCamelContext = camelContext.isStopping();

        if (isShutdownCamelContext || isRemovingRoutes()) {
            // need to call onRoutesRemove when the CamelContext is shutting down or Route is shutdown
            for (LifecycleStrategy strategy : camelContext.getLifecycleStrategies()) {
                strategy.onRoutesRemove(routes);
            }
        }

        for (Route route : routes) {
            LOG.debug("Stopping services on route: {}", route.getId());

            // gather list of services to stop as we need to start child services as well
            Set<Service> services = gatherChildServices(route, true);

            // stop services
            stopChildService(route, services, isShutdownCamelContext);

            // stop the route itself
            if (isShutdownCamelContext) {
                ServiceHelper.stopAndShutdownServices(route);
            } else {
                ServiceHelper.stopServices(route);
            }

            // invoke callbacks on route policy
            if (route.getRouteContext().getRoutePolicyList() != null) {
                for (RoutePolicy routePolicy : route.getRouteContext().getRoutePolicyList()) {
                    routePolicy.onStop(route);
                }
            }
            // fire event
            EventHelper.notifyRouteStopped(camelContext, route);
        }
        if (isRemovingRoutes()) {
            camelContext.removeRouteCollection(routes);
        }
        // need to warm up again
        warmUpDone.set(false);
    }
项目:Camel    文件:DefaultRouteContext.java   
public void setRoutePolicyList(List<RoutePolicy> routePolicyList) {
    this.routePolicyList = routePolicyList;
}
项目:Camel    文件:DefaultRouteContext.java   
public List<RoutePolicy> getRoutePolicyList() {
    return routePolicyList;
}
项目:Camel    文件:RoutePolicyFactoryTest.java   
@Override
public RoutePolicy createRoutePolicy(CamelContext camelContext, String routeId, RouteDefinition route) {
    return new MyRoutePolicy(routeId);
}
项目:Camel    文件:MultiplePoliciesOnRouteTest.java   
private RoutePolicy createThrottlePolicy() {
    ThrottlingInflightRoutePolicy policy = new ThrottlingInflightRoutePolicy();
    policy.setMaxInflightExchanges(10);
    return policy;
}
项目:Camel    文件:ZipkinTracer.java   
@Override
public RoutePolicy createRoutePolicy(CamelContext camelContext, String routeId, RouteDefinition route) {
    return new ZipkinRoutePolicy(routeId);
}
项目:Camel    文件:MultiplePoliciesOnRouteTest.java   
private RoutePolicy createThrottlePolicy() {
    ThrottlingInflightRoutePolicy policy = new ThrottlingInflightRoutePolicy();
    policy.setMaxInflightExchanges(10);
    return policy;
}