    001    package 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
    024    import java.util.List;
    025
    026    import org.apache.commons.logging.Log;
    027    import org.apache.commons.logging.LogFactory;
    028    import org.apache.turbine.services.TurbineServices;
    029    import org.apache.turbine.services.pull.ApplicationTool;
    030    import 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 1078552 2011-03-06 19:58:46Z tv $
    037     */
    038    public 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        public void init(Object data)
    047        {
    048            if (!TurbineServices.getInstance().isRegistered(
    049                    ScheduleService.SERVICE_NAME))
    050            {
    051                log.error("You can not use the SchedulerTool unless you enable "
    052                        +"the Scheduler Service!!!!");
    053            }
    054        }
    055
    056        /**
    057         * Does nothing
    058         */
    059        public void refresh()
    060        {
    061            // empty
    062        }
    063
    064        /**
    065         * Gets the list of scheduled jobs.
    066         *
    067         * @return List of JobEntry objects.
    068         */
    069        public List<JobEntry> getScheduledJobs()
    070        {
    071            return TurbineScheduler.listJobs();
    072        }
    073
    074        /**
    075         * Determines if the scheduler service is currently enabled.
    076         */
    077        public boolean isEnabled()
    078        {
    079            return TurbineScheduler.isEnabled();
    080        }
    081
    082        /**
    083         * Gets the job identified by the jobId.
    084         *
    085         * @param jobId Id of the job to retreive.
    086         * @return The job.  Null if the jobId is not found.
    087         */
    088        public JobEntry getJob(String jobId)
    089        {
    090            JobEntry je = null;
    091
    092            try
    093            {
    094                je = TurbineScheduler.getJob(Integer.parseInt(jobId));
    095            }
    096            catch (TurbineException e)
    097            {
    098                log.error("Could not retreive job id #" + jobId, e);
    099            }
    100
    101            return je;
    102        }
    103
    104    }