View Javadoc

    1   package org.apache.turbine.modules;
    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 org.apache.turbine.Turbine;
    25  import org.apache.turbine.pipeline.PipelineData;
    26  import org.apache.turbine.services.schedule.JobEntry;
    27
    28  /**
    29   * ScheduledJobs loader class.
    30   *
    31   * @author <a href="mailto:mbryson@mindspring.com">Dave Bryson</a>
    32   * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
    33   * @version $Id: ScheduledJobLoader.java 1773378 2016-12-09 13:19:59Z tv $
    34   */
    35  public class ScheduledJobLoader
    36      extends GenericLoader<ScheduledJob>
    37      implements Loader<ScheduledJob>
    38  {
    39      /** The single instance of this class. */
    40      private static ScheduledJobLoader instance = new ScheduledJobLoader();
    41
    42      /**
    43       * These ctor's are private to force clients to use getInstance()
    44       * to access this class.
    45       */
    46      private ScheduledJobLoader()
    47      {
    48          super();
    49      }
    50
    51      /**
    52       * Attempts to load and execute the external ScheduledJob.
    53       *
    54       * @param job The JobEntry.
    55       * @param name Name of object that will execute the job.
    56       * @throws Exception a generic exception.
    57       */
    58      public void exec(JobEntry job, String name)
    59              throws Exception
    60      {
    61          // Execute job
    62          getAssembler(name).run(job);
    63      }
    64
    65      /**
    66       * Attempts to load and execute the external ScheduledJob.
    67       *
    68       * HELP! - THIS IS UGLY!
    69       *
    70       * I want the cache stuff from GenericLoader, BUT, I don't think
    71       * the scheduler needs the PipelineData object.  The scheduler runs
    72       * independently of an HTTP request.  This should not extend
    73       * GenericLoader!  Thoughts??
    74       *
    75       * @param pipelineData Turbine information.
    76       * @param name Name of object that will execute the job.
    77       * @throws Exception a generic exception.
    78       * @deprecated
    79       */
    80      @Deprecated
    81      @Override
    82      public void exec(PipelineData pipelineData, String name)
    83              throws Exception
    84      {
    85          throw new Exception("PipelineData objects not accepted for Scheduled jobs");
    86      }
    87
    88      /**
    89       * Pulls out an instance of the object by name.  Name is just the
    90       * single name of the object.
    91       *
    92       * @param name Name of object instance.
    93       * @return A ScheduledJob with the specified name, or null.
    94       * @throws Exception a generic exception.
    95       */
    96      @Override
    97      public ScheduledJob getAssembler(String name)
    98          throws Exception
    99      {
    100         return getAssembler(ScheduledJob.class, name);
    101     }
    102
    103     /**
    104      * @see org.apache.turbine.modules.Loader#getCacheSize()
    105      */
    106     @Override
    107     public int getCacheSize()
    108     {
    109         return ScheduledJobLoader.getConfiguredCacheSize();
    110     }
    111
    112     /**
    113      * The method through which this class is accessed.
    114      *
    115      * @return The single instance of this class.
    116      */
    117     public static ScheduledJobLoader getInstance()
    118     {
    119         return instance;
    120     }
    121
    122     /**
    123      * Helper method to get the configured cache size for this module
    124      *
    125      * @return the configure cache size
    126      */
    127     private static int getConfiguredCacheSize()
    128     {
    129         return Turbine.getConfiguration().getInt(ScheduledJob.CACHE_SIZE_KEY,
    130                 ScheduledJob.CACHE_SIZE_DEFAULT);
    131     }
    132 }