1 /***
2 * @(#)QuartzServiceImpl.java
3 *
4 * JFoxSOAF, Service-Oriented Application Framework
5 *
6 * Copyright(c) JFoxSOAF Team
7 *
8 * Licensed under the GNU LGPL, Version 2.1 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.gnu.org/copyleft/lesser.html
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 *
20 * For more information, please visit:
21 * http://www.jfox.cn/confluence/display/JFoxSOAF/Home
22 * http://www.huihoo.org/jfox/jfoxsoaf
23 */
24 package org.huihoo.jfox.soaf.services.timer;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.picocontainer.Startable;
29 import org.quartz.JobDetail;
30 import org.quartz.Scheduler;
31 import org.quartz.SchedulerException;
32 import org.quartz.Trigger;
33 import org.quartz.impl.StdSchedulerFactory;
34
35 /***
36 * <p>
37 * Quartz service implementation.
38 * </p>
39 *
40 * @author <a href="mailto:founder_chen@yahoo.com.cn">Peter Cheng </a>
41 * @version $Revision: 1.1 $ $Date: 2006/02/15 08:45:45 $
42 * @version Revision: 1.0
43 */
44
45 public class QuartzServiceImpl implements QuartzService, Startable {
46
47 private static final Log log = LogFactory.getLog(QuartzServiceImpl.class);
48
49 private Scheduler scheduler;
50
51 /***
52 * Retrieve scheduler.
53 *
54 * @return scheduler.
55 */
56 public Scheduler getScheduler() {
57 return this.scheduler;
58 }
59
60 /***
61 * Schedule job with job detail.
62 *
63 * @param jobDetail
64 * @param trigger
65 */
66 public void schedule(JobDetail jobDetail, Trigger trigger)
67 throws SchedulerException {
68 scheduler.scheduleJob(jobDetail, trigger);
69 }
70
71 /***
72 * Schedule job with trigger.
73 *
74 * @param trigger
75 * @throws SchedulerException
76 */
77 public void schedule(Trigger trigger) throws SchedulerException {
78 scheduler.scheduleJob(trigger);
79 }
80
81 /***
82 * Start quartz service.
83 *
84 * @see org.picocontainer.Startable#start()
85 */
86 public void start() {
87 log.info("Starting quartz service");
88 try {
89 scheduler = StdSchedulerFactory.getDefaultScheduler();
90 scheduler.start();
91 } catch (SchedulerException e) {
92 log.error("Cannot start quartz scheduler.", e);
93 }
94 }
95
96 /***
97 * Stopping quartz service.
98 *
99 * @see org.picocontainer.Startable#stop()
100 */
101 public void stop() {
102 log.info("Stopping quartz service");
103 try {
104 scheduler.shutdown();
105 } catch (SchedulerException se) {
106 log.error("Cannot shutdown quartz scheduler.", se);
107 }
108 }
109
110 }