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