Search in sources :

Example 26 with Route

use of org.apache.camel.Route in project camel by apache.

the class ScheduledJob method execute.

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);
        }
    }
}
Also used : JobExecutionException(org.quartz.JobExecutionException) SchedulerContext(org.quartz.SchedulerContext) RoutePolicy(org.apache.camel.spi.RoutePolicy) Route(org.apache.camel.Route) JobExecutionException(org.quartz.JobExecutionException) SchedulerException(org.quartz.SchedulerException)

Example 27 with Route

use of org.apache.camel.Route in project camel by apache.

the class CronScheduledRoutePolicyTest method testScheduledStartAndStopRoutePolicy.

@Test
public void testScheduledStartAndStopRoutePolicy() throws Exception {
    MockEndpoint success = context.getEndpoint("mock:success", MockEndpoint.class);
    success.expectedMessageCount(1);
    final CountDownLatch startedLatch = new CountDownLatch(1);
    final CountDownLatch stoppedLatch = new CountDownLatch(1);
    context.getComponent("quartz2", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz2/myquartz.properties");
    context.addRoutes(new RouteBuilder() {

        public void configure() {
            CronScheduledRoutePolicy policy = new CronScheduledRoutePolicy() {

                @Override
                public void onStart(final Route route) {
                    super.onStart(route);
                    startedLatch.countDown();
                }

                @Override
                public void onStop(final Route route) {
                    super.onStop(route);
                    stoppedLatch.countDown();
                }
            };
            policy.setRouteStartTime("*/3 * * * * ?");
            policy.setRouteStopTime("*/6 * * * * ?");
            policy.setRouteStopGracePeriod(0);
            from("direct:start").routeId("test").routePolicy(policy).noAutoStartup().to("mock:success");
        }
    });
    context.start();
    startedLatch.await(5000, TimeUnit.SECONDS);
    ServiceStatus startedStatus = context.getRouteStatus("test");
    assertTrue(startedStatus == ServiceStatus.Started || startedStatus == ServiceStatus.Starting);
    template.sendBody("direct:start", "Ready or not, Here, I come");
    stoppedLatch.await(5000, TimeUnit.SECONDS);
    ServiceStatus stoppedStatus = context.getRouteStatus("test");
    assertTrue(stoppedStatus == ServiceStatus.Stopped || stoppedStatus == ServiceStatus.Stopping);
    success.assertIsSatisfied();
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ServiceStatus(org.apache.camel.ServiceStatus) CountDownLatch(java.util.concurrent.CountDownLatch) Route(org.apache.camel.Route) QuartzComponent(org.apache.camel.component.quartz2.QuartzComponent) Test(org.junit.Test)

Example 28 with Route

use of org.apache.camel.Route in project camel by apache.

the class CustomProcessorWithNamespacesTest method assertValidContext.

protected void assertValidContext(SpringCamelContext context) {
    assertNotNull("No context found!", context);
    List<Route> routes = context.getRoutes();
    assertNotNull("Should have some routes defined", routes);
    assertEquals("Number of routes defined", 1, routes.size());
    Route route = routes.get(0);
    log.debug("Found route: " + route);
}
Also used : Route(org.apache.camel.Route)

Example 29 with Route

use of org.apache.camel.Route in project camel by apache.

the class TestSupport method getRouteList.

/**
     * A helper method to create a list of Route objects for a given route builder
     */
public static List<Route> getRouteList(RouteBuilder builder) throws Exception {
    CamelContext context = new DefaultCamelContext();
    context.addRoutes(builder);
    context.start();
    List<Route> answer = context.getRoutes();
    context.stop();
    return answer;
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Route(org.apache.camel.Route)

Example 30 with Route

use of org.apache.camel.Route in project camel by apache.

the class TestSupport method getRouteList.

/**
     * A helper method to create a list of Route objects for a given route builder
     */
public static List<Route> getRouteList(RouteBuilder builder) throws Exception {
    CamelContext context = new DefaultCamelContext();
    context.addRoutes(builder);
    context.start();
    List<Route> answer = context.getRoutes();
    context.stop();
    return answer;
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Route(org.apache.camel.Route)

Aggregations

Route (org.apache.camel.Route)90 EventDrivenConsumerRoute (org.apache.camel.impl.EventDrivenConsumerRoute)27 Endpoint (org.apache.camel.Endpoint)24 Channel (org.apache.camel.Channel)17 DeadLetterChannel (org.apache.camel.processor.DeadLetterChannel)15 Processor (org.apache.camel.Processor)13 ArrayList (java.util.ArrayList)12 SendProcessor (org.apache.camel.processor.SendProcessor)11 CamelContext (org.apache.camel.CamelContext)10 ShutdownRoute (org.apache.camel.ShutdownRoute)8 FilterProcessor (org.apache.camel.processor.FilterProcessor)7 RoutePolicy (org.apache.camel.spi.RoutePolicy)6 HashMap (java.util.HashMap)5 Service (org.apache.camel.Service)5 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)4 DelegateProcessor (org.apache.camel.DelegateProcessor)4 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)4 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)4