001package org.apache.turbine.services.schedule; 002 003 004/* 005 * Licensed to the Apache Software Foundation (ASF) under one 006 * or more contributor license agreements. See the NOTICE file 007 * distributed with this work for additional information 008 * regarding copyright ownership. The ASF licenses this file 009 * to you under the Apache License, Version 2.0 (the 010 * "License"); you may not use this file except in compliance 011 * with the License. You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, 016 * software distributed under the License is distributed on an 017 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 018 * KIND, either express or implied. See the License for the 019 * specific language governing permissions and limitations 020 * under the License. 021 */ 022 023 024import java.util.List; 025 026import org.apache.commons.logging.Log; 027import org.apache.commons.logging.LogFactory; 028import org.apache.turbine.services.TurbineServices; 029import org.apache.turbine.services.pull.ApplicationTool; 030import org.apache.turbine.util.TurbineException; 031 032/** 033 * This tool is used to retrieve information about the job scheduler. 034 * 035 * @author <a href="mailto:qmccombs@nequalsone.com">Quinton McCombs</a> 036 * @version $Id: SchedulerTool.java 1706239 2015-10-01 13:18:35Z tv $ 037 */ 038public class SchedulerTool implements ApplicationTool 039{ 040 /** Used for logging */ 041 private static Log log = LogFactory.getLog(ScheduleService.LOGGER_NAME); 042 043 /** 044 * Initialize the pull tool 045 */ 046 @Override 047 public void init(Object data) 048 { 049 if (!TurbineServices.getInstance().isRegistered( 050 ScheduleService.SERVICE_NAME)) 051 { 052 log.error("You can not use the SchedulerTool unless you enable " 053 +"the Scheduler Service!!!!"); 054 } 055 } 056 057 /** 058 * Does nothing 059 */ 060 @Override 061 public void refresh() 062 { 063 // empty 064 } 065 066 /** 067 * Gets the list of scheduled jobs. 068 * 069 * @return List of JobEntry objects. 070 */ 071 public List<? extends JobEntry> getScheduledJobs() 072 { 073 return TurbineScheduler.listJobs(); 074 } 075 076 /** 077 * Determines if the scheduler service is currently enabled. 078 * @return true if the scheduler is enabled 079 */ 080 public boolean isEnabled() 081 { 082 return TurbineScheduler.isEnabled(); 083 } 084 085 /** 086 * Gets the job identified by the jobId. 087 * 088 * @param jobId Id of the job to retrieve. 089 * @return The job. Null if the jobId is not found. 090 */ 091 public JobEntry getJob(String jobId) 092 { 093 JobEntry je = null; 094 095 try 096 { 097 je = TurbineScheduler.getJob(Integer.parseInt(jobId)); 098 } 099 catch (TurbineException e) 100 { 101 log.error("Could not retreive job id #" + jobId, e); 102 } 103 104 return je; 105 } 106 107}