Instead of extending Liferay's JobScheduler (as I suggested in the previous post), it made more sense to create a singleton POJO that then invokes com.liferay.portal.kernel.job.JobSchedulerUtil.getJobScheduler().schedule(). That way the dependency is relying on Liferay's Quartz integration altogether (not thinking any of this would ever live outside of Liferay, but in the event that it does should be able to propagate that dependency with minor adjustments). Everything said and done (and tested), this is the scheduler:
public class JobScheduler {
private static Log _log = LogFactory.getLog(JobScheduler.class);
public Setjobs = new HashSet ();
/**
* Set all of the scheduled jobs.
*
* @param jobs Set of jobs to schedule.
*/
public void setJobs(Setjobs) {
this.jobs = jobs;
}
public void init(){
com.liferay.portal.kernel.job.JobScheduler scheduler = JobSchedulerUtil.getJobScheduler();
for(IntervalJob job : jobs){
try {
_log.info("Initializating " + job);
scheduler.schedule(job);
}
catch (Exception e) {
_log.error("Initialization error instantiating " +job);
_log.error(e);
}
}
}
public void destroy() {
com.liferay.portal.kernel.job.JobScheduler scheduler = JobSchedulerUtil.getJobScheduler();
for(IntervalJob job : jobs){
try {
_log.info("Unscheduling " + job);
scheduler.unschedule(job);
}
catch (Exception e) {
_log.error("Unscheduling error with" +job);
_log.error(e);
}
}
}
}
No comments:
Post a Comment