01: package org.apache.turbine.services.schedule;
02:
03: /*
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
20: */
21:
22: import java.util.List;
23:
24: import org.apache.commons.logging.Log;
25: import org.apache.commons.logging.LogFactory;
26: import org.apache.turbine.services.TurbineServices;
27: import org.apache.turbine.services.pull.ApplicationTool;
28: import org.apache.turbine.util.TurbineException;
29:
30: /**
31: * This tool is used to retrieve information about the job scheduler.
32: *
33: * @author <a href="mailto:qmccombs@nequalsone.com">Quinton McCombs</a>
34: * @version $Id: SchedulerTool.java 534527 2007-05-02 16:10:59Z tv $
35: */
36: public class SchedulerTool implements ApplicationTool {
37: /** Used for logging */
38: private static Log log = LogFactory
39: .getLog(ScheduleService.LOGGER_NAME);
40:
41: /**
42: * Initialize the pull tool
43: */
44: public void init(Object data) {
45: if (!TurbineServices.getInstance().isRegistered(
46: ScheduleService.SERVICE_NAME)) {
47: log
48: .error("You can not use the SchedulerTool unless you enable "
49: + "the Scheduler Service!!!!");
50: }
51: }
52:
53: /**
54: * Does nothing
55: */
56: public void refresh() {
57: }
58:
59: /**
60: * Gets the list of scheduled jobs.
61: *
62: * @return List of JobEntry objects.
63: */
64: public List getScheduledJobs() {
65: return TurbineScheduler.listJobs();
66: }
67:
68: /**
69: * Determines if the scheduler service is currently enabled.
70: */
71: public boolean isEnabled() {
72: return TurbineScheduler.isEnabled();
73: }
74:
75: /**
76: * Gets the job identified by the jobId.
77: *
78: * @param jobId Id of the job to retreive.
79: * @return The job. Null if the jobId is not found.
80: */
81: public JobEntry getJob(String jobId) {
82: JobEntry je = null;
83:
84: try {
85: je = TurbineScheduler.getJob(Integer.parseInt(jobId));
86: } catch (TurbineException e) {
87: log.error("Could not retreive job id #" + jobId, e);
88: }
89:
90: return je;
91: }
92:
93: }
|