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.services.schedule.JobEntry;
26  import org.apache.turbine.util.RunData;
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 1078552 2011-03-06 19:58:46Z 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       * @exception 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 Rundata object.  The scheduler runs
72       * independently of an HTTP request.  This should not extend
73       * GenericLoader!  Thoughts??
74       *
75       * @param data Turbine information.
76       * @param name Name of object that will execute the job.
77       * @exception Exception a generic exception.
78       */
79      @Override
80      public void exec(RunData data, String name)
81              throws Exception
82      {
83          throw new Exception("RunData objects not accepted for Scheduled jobs");
84      }
85  
86      /**
87       * Pulls out an instance of the object by name.  Name is just the
88       * single name of the object. This is equal to getInstance but
89       * returns an Assembler object and is needed to fulfil the Loader
90       * interface.
91       *
92       * @param name Name of object instance.
93       * @return A ScheduledJob with the specified name, or null.
94       * @exception Exception a generic exception.
95       */
96      public ScheduledJob getAssembler(String name)
97          throws Exception
98      {
99          return getAssembler(ScheduledJob.NAME, name);
100     }
101 
102     /**
103      * @see org.apache.turbine.modules.Loader#getCacheSize()
104      */
105     public int getCacheSize()
106     {
107         return ScheduledJobLoader.getConfiguredCacheSize();
108     }
109 
110     /**
111      * The method through which this class is accessed.
112      *
113      * @return The single instance of this class.
114      */
115     public static ScheduledJobLoader getInstance()
116     {
117         return instance;
118     }
119 
120     /**
121      * Helper method to get the configured cache size for this module
122      *
123      * @return the configure cache size
124      */
125     private static int getConfiguredCacheSize()
126     {
127         return Turbine.getConfiguration().getInt(ScheduledJob.CACHE_SIZE_KEY,
128                 ScheduledJob.CACHE_SIZE_DEFAULT);
129     }
130 }