* If a scheduler is available, a job is scheduled or stopped.
* @param event The incomming event.
* @return
*/
protected boolean processEvent(final Event event, final ScheduleInfo scheduleInfo) {
final Scheduler localScheduler = this.scheduler;
if ( localScheduler != null ) {
// is this a stop event?
if ( scheduleInfo.isStopEvent() ) {
if ( this.logger.isDebugEnabled() ) {
this.logger.debug("Stopping timed event " + event.getProperty(EventUtil.PROPERTY_TIMED_EVENT_TOPIC) + "(" + scheduleInfo.jobId + ")");
}
try {
localScheduler.removeJob(scheduleInfo.jobId);
} catch (NoSuchElementException nsee) {
// this can happen if the job is scheduled on another node
// so we can just ignore this
}
return true;
}
// we ignore remote job events
if ( !EventUtil.isLocal(event) ) {
return true;
}
// Create configuration for scheduled job
final Map<String, Serializable> config = new HashMap<String, Serializable>();
// copy properties
final Hashtable<String, Object> properties = new Hashtable<String, Object>();
config.put(JOB_TOPIC, (String)event.getProperty(EventUtil.PROPERTY_TIMED_EVENT_TOPIC));
final String[] names = event.getPropertyNames();
if ( names != null ) {
for(int i=0; i<names.length; i++) {
properties.put(names[i], event.getProperty(names[i]));
}
}
config.put(JOB_CONFIG, properties);
config.put(JOB_SCHEDULE_INFO, scheduleInfo);
try {
if ( scheduleInfo.expression != null ) {
if ( this.logger.isDebugEnabled() ) {
this.logger.debug("Adding timed event " + config.get(JOB_TOPIC) + "(" + scheduleInfo.jobId + ")" + " with cron expression " + scheduleInfo.expression);
}
localScheduler.addJob(scheduleInfo.jobId, this, config, scheduleInfo.expression, false);
} else if ( scheduleInfo.period != null ) {
if ( this.logger.isDebugEnabled() ) {
this.logger.debug("Adding timed event " + config.get(JOB_TOPIC) + "(" + scheduleInfo.jobId + ")" + " with period " + scheduleInfo.period);
}
localScheduler.addPeriodicJob(scheduleInfo.jobId, this, config, scheduleInfo.period, false);
} else {
// then it must be date
if ( this.logger.isDebugEnabled() ) {
this.logger.debug("Adding timed event " + config.get(JOB_TOPIC) + "(" + scheduleInfo.jobId + ")" + " with date " + scheduleInfo.date);
}
localScheduler.fireJobAt(scheduleInfo.jobId, this, config, scheduleInfo.date);
}
return true;
} catch (Exception e) {
this.ignoreException(e);
}