View Javadoc

1   package org.apache.turbine.services.schedule;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "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  {
38      /*** Used for logging */
39      private static Log log = LogFactory.getLog(ScheduleService.LOGGER_NAME);
40  
41      /***
42       * Initialize the pull tool
43       */
44      public void init(Object data)
45      {
46          if (!TurbineServices.getInstance().isRegistered(
47                  ScheduleService.SERVICE_NAME))
48          {
49              log.error("You can not use the SchedulerTool unless you enable "
50                      +"the Scheduler Service!!!!");
51          }
52      }
53  
54      /***
55       * Does nothing
56       */
57      public void refresh()
58      {
59      }
60  
61      /***
62       * Gets the list of scheduled jobs.
63       *
64       * @return List of JobEntry objects.
65       */
66      public List getScheduledJobs()
67      {
68          return TurbineScheduler.listJobs();
69      }
70  
71      /***
72       * Determines if the scheduler service is currently enabled.
73       */
74      public boolean isEnabled()
75      {
76          return TurbineScheduler.isEnabled();
77      }
78  
79      /***
80       * Gets the job identified by the jobId.
81       *
82       * @param jobId Id of the job to retreive.
83       * @return The job.  Null if the jobId is not found.
84       */
85      public JobEntry getJob(String jobId)
86      {
87          JobEntry je = null;
88  
89          try
90          {
91              je = TurbineScheduler.getJob(Integer.parseInt(jobId));
92          }
93          catch (TurbineException e)
94          {
95              log.error("Could not retreive job id #" + jobId, e);
96          }
97  
98          return je;
99      }
100 
101 }