View Javadoc

    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.annotation.TurbineService;
    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 1723697 2016-01-08 11:27:14Z 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       * The scheduler service.
    45       */
    46      @TurbineService
    47      private ScheduleService schedulerService;
    48
    49      /**
    50       * Initialize the pull tool
    51       */
    52      @Override
    53      public void init(Object data)
    54      {
    55          // Rely on injection
    56          if (schedulerService == null)
    57          {
    58              log.error("You can not use the SchedulerTool unless you enable "
    59                      +"the Scheduler Service!!!!");
    60          }
    61      }
    62
    63      /**
    64       * Does nothing
    65       */
    66      @Override
    67      public void refresh()
    68      {
    69          // empty
    70      }
    71
    72      /**
    73       * Gets the list of scheduled jobs.
    74       *
    75       * @return List of JobEntry objects.
    76       */
    77      public List<? extends JobEntry> getScheduledJobs()
    78      {
    79          return schedulerService.listJobs();
    80      }
    81
    82      /**
    83       * Determines if the scheduler service is currently enabled.
    84       * @return true if the scheduler is enabled
    85       */
    86      public boolean isEnabled()
    87      {
    88          return schedulerService.isEnabled();
    89      }
    90
    91      /**
    92       * Gets the job identified by the jobId.
    93       *
    94       * @param jobId Id of the job to retrieve.
    95       * @return The job.  Null if the jobId is not found.
    96       */
    97      public JobEntry getJob(String jobId)
    98      {
    99          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 }