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.logging.log4j.LogManager;
027import org.apache.logging.log4j.Logger;
028import org.apache.turbine.annotation.TurbineService;
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$
037 */
038public class SchedulerTool implements ApplicationTool
039{
040    /** Used for logging */
041    private static final Logger log = LogManager.getLogger(ScheduleService.LOGGER_NAME);
042
043    /**
044     * The scheduler service.
045     */
046    @TurbineService
047    private ScheduleService schedulerService;
048
049    /**
050     * Initialize the pull tool
051     */
052    @Override
053    public void init(Object data)
054    {
055        // Rely on injection
056        if (schedulerService == null)
057        {
058            log.error("You can not use the SchedulerTool unless you enable "
059                    +"the Scheduler Service!!!!");
060        }
061    }
062
063    /**
064     * Does nothing
065     */
066    @Override
067    public void refresh()
068    {
069        // empty
070    }
071
072    /**
073     * Gets the list of scheduled jobs.
074     *
075     * @return List of JobEntry objects.
076     */
077    public List<? extends JobEntry> getScheduledJobs()
078    {
079        return schedulerService.listJobs();
080    }
081
082    /**
083     * Determines if the scheduler service is currently enabled.
084     * @return true if the scheduler is enabled
085     */
086    public boolean isEnabled()
087    {
088        return schedulerService.isEnabled();
089    }
090
091    /**
092     * Gets the job identified by the jobId.
093     *
094     * @param jobId Id of the job to retrieve.
095     * @return The job.  Null if the jobId is not found.
096     */
097    public JobEntry getJob(String jobId)
098    {
099        JobEntry je = null;
100
101        try
102        {
103            je = schedulerService.getJob(Integer.parseInt(jobId));
104        }
105        catch (TurbineException e)
106        {
107            log.error("Could not retreive job id #{}", jobId, e);
108        }
109
110        return je;
111    }
112
113}