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