01: /*
02: * Copyright 2007 Pentaho Corporation. All rights reserved.
03: * This software was developed by Pentaho Corporation and is provided under the terms
04: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
05: * this file except in compliance with the license. If you need a copy of the license,
06: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
07: * BI Platform. The Initial Developer is Pentaho Corporation.
08: *
09: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11: * the license for the specific language governing your rights and limitations.
12: */
13: package org.pentaho.core.subscribe.quartz;
14:
15: import java.util.Date;
16:
17: import org.pentaho.core.subscribe.IScheduledJob;
18: import org.pentaho.plugin.quartz.QuartzSystemListener;
19: import org.quartz.JobDetail;
20: import org.quartz.Scheduler;
21: import org.quartz.Trigger;
22:
23: public class QuartzScheduledJob implements IScheduledJob {
24:
25: private Trigger trigger;
26:
27: private Throwable lastException = null;
28:
29: public QuartzScheduledJob(Trigger trigger) {
30: this .trigger = trigger;
31: }
32:
33: public Date getNextTriggerTime() {
34: return ((trigger == null ? null : trigger.getNextFireTime()));
35: }
36:
37: public Date getLastTriggerTime() {
38: return ((trigger == null ? null : trigger.getPreviousFireTime()));
39: }
40:
41: public String getDescription() {
42: return ((trigger == null ? null : trigger.getDescription()));
43: }
44:
45: public int getExecutionState() {
46: lastException = null;
47: try {
48: Scheduler scheduler = QuartzSystemListener
49: .getSchedulerInstance();
50: int state = scheduler.getTriggerState(trigger.getName(),
51: trigger.getGroup());
52: try {
53: JobDetail job = scheduler.getJobDetail(trigger
54: .getName(), trigger.getGroup());
55: job.validate();
56: } catch (Throwable t) {
57: lastException = t;
58: return (STATE_ERROR);
59: }
60: return (state);
61: } catch (Throwable t) {
62: lastException = t;
63: return (STATE_NONE);
64: }
65: }
66:
67: public String getErrorMessage() {
68: getExecutionState();
69: return (lastException == null ? null : lastException
70: .getLocalizedMessage());
71: }
72:
73: public String getUniqueId() {
74: return (trigger == null ? null : trigger.getFullJobName());
75: }
76:
77: }
|