use of org.apache.camel.component.quartz2.QuartzComponent in project camel by apache.
the class QuartzComponentAutoConfiguration method configureQuartzComponent.
@Lazy
@Bean(name = "quartz2-component")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(QuartzComponent.class)
public QuartzComponent configureQuartzComponent(CamelContext camelContext, QuartzComponentConfiguration configuration) throws Exception {
QuartzComponent component = new QuartzComponent();
component.setCamelContext(camelContext);
Map<String, Object> parameters = new HashMap<>();
IntrospectionSupport.getProperties(configuration, parameters, null, false);
for (Map.Entry<String, Object> entry : parameters.entrySet()) {
Object value = entry.getValue();
Class<?> paramClass = value.getClass();
if (paramClass.getName().endsWith("NestedConfiguration")) {
Class nestedClass = null;
try {
nestedClass = (Class) paramClass.getDeclaredField("CAMEL_NESTED_CLASS").get(null);
HashMap<String, Object> nestedParameters = new HashMap<>();
IntrospectionSupport.getProperties(value, nestedParameters, null, false);
Object nestedProperty = nestedClass.newInstance();
IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), nestedProperty, nestedParameters);
entry.setValue(nestedProperty);
} catch (NoSuchFieldException e) {
}
}
}
IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), component, parameters);
return component;
}
use of org.apache.camel.component.quartz2.QuartzComponent in project camel by apache.
the class QuartzScheduledPollConsumerScheduler method doStart.
@Override
protected void doStart() throws Exception {
ObjectHelper.notEmpty(cron, "cron", this);
if (quartzScheduler == null) {
// get the scheduler form the quartz component
QuartzComponent quartz = getCamelContext().getComponent("quartz2", QuartzComponent.class);
setQuartzScheduler(quartz.getScheduler());
}
JobDataMap map = new JobDataMap();
// do not store task as its not serializable, if we have route id
if (routeId != null) {
map.put("routeId", routeId);
} else {
map.put("task", runnable);
}
map.put(QuartzConstants.QUARTZ_TRIGGER_TYPE, "cron");
map.put(QuartzConstants.QUARTZ_TRIGGER_CRON_EXPRESSION, getCron());
map.put(QuartzConstants.QUARTZ_TRIGGER_CRON_TIMEZONE, getTimeZone().getID());
job = JobBuilder.newJob(QuartzScheduledPollConsumerJob.class).usingJobData(map).build();
// store additional information on job such as camel context etc
QuartzHelper.updateJobDataMap(getCamelContext(), job, null);
String id = triggerId;
if (id == null) {
id = "trigger-" + getCamelContext().getUuidGenerator().generateUuid();
}
trigger = TriggerBuilder.newTrigger().withIdentity(id, triggerGroup).withSchedule(CronScheduleBuilder.cronSchedule(getCron()).inTimeZone(getTimeZone())).build();
LOG.debug("Scheduling job: {} with trigger: {}", job, trigger.getKey());
quartzScheduler.scheduleJob(job, trigger);
}
use of org.apache.camel.component.quartz2.QuartzComponent in project camel by apache.
the class CronScheduledRoutePolicy method doOnInit.
protected void doOnInit(Route route) throws Exception {
QuartzComponent quartz = route.getRouteContext().getCamelContext().getComponent("quartz2", QuartzComponent.class);
setScheduler(quartz.getScheduler());
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 {} 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);
}
}
use of org.apache.camel.component.quartz2.QuartzComponent in project wildfly-camel by wildfly-extras.
the class QuartzIntegrationTest method testManualComponentConfig.
@Test
public void testManualComponentConfig() throws Exception {
final CountDownLatch startLatch = new CountDownLatch(1);
final CountDownLatch procLatch = new CountDownLatch(3);
CamelContext camelctx = new DefaultCamelContext();
camelctx.addComponent("quartz2", new QuartzComponent() {
@Override
public void onCamelContextStarted(CamelContext context, boolean alreadyStarted) throws Exception {
super.onCamelContextStarted(context, alreadyStarted);
if (!alreadyStarted) {
startLatch.countDown();
}
}
});
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("quartz2://mytimer?trigger.repeatCount=3&trigger.repeatInterval=100").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
procLatch.countDown();
}
}).to("mock:result");
}
});
camelctx.start();
try {
Assert.assertEquals("StartLatch is zero", 0, startLatch.getCount());
Assert.assertTrue("ProcLatch reached zero", procLatch.await(500, TimeUnit.MILLISECONDS));
} finally {
camelctx.stop();
}
}
use of org.apache.camel.component.quartz2.QuartzComponent in project camel by apache.
the class SimpleScheduledRoutePolicy method doOnInit.
protected void doOnInit(Route route) throws Exception {
QuartzComponent quartz = route.getRouteContext().getCamelContext().getComponent("quartz2", QuartzComponent.class);
setScheduler(quartz.getScheduler());
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 {} 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);
}
}
Aggregations