001 package org.apache.turbine.modules;
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 org.apache.turbine.Turbine;
025 import org.apache.turbine.services.schedule.JobEntry;
026 import org.apache.turbine.util.RunData;
027
028 /**
029 * ScheduledJobs loader class.
030 *
031 * @author <a href="mailto:mbryson@mindspring.com">Dave Bryson</a>
032 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
033 * @version $Id: ScheduledJobLoader.java 1078552 2011-03-06 19:58:46Z tv $
034 */
035 public class ScheduledJobLoader
036 extends GenericLoader<ScheduledJob>
037 implements Loader<ScheduledJob>
038 {
039 /** The single instance of this class. */
040 private static ScheduledJobLoader instance = new ScheduledJobLoader();
041
042 /**
043 * These ctor's are private to force clients to use getInstance()
044 * to access this class.
045 */
046 private ScheduledJobLoader()
047 {
048 super();
049 }
050
051 /**
052 * Attempts to load and execute the external ScheduledJob.
053 *
054 * @param job The JobEntry.
055 * @param name Name of object that will execute the job.
056 * @exception Exception a generic exception.
057 */
058 public void exec(JobEntry job, String name)
059 throws Exception
060 {
061 // Execute job
062 getAssembler(name).run(job);
063 }
064
065 /**
066 * Attempts to load and execute the external ScheduledJob.
067 *
068 * HELP! - THIS IS UGLY!
069 *
070 * I want the cache stuff from GenericLoader, BUT, I don't think
071 * the scheduler needs the Rundata object. The scheduler runs
072 * independently of an HTTP request. This should not extend
073 * GenericLoader! Thoughts??
074 *
075 * @param data Turbine information.
076 * @param name Name of object that will execute the job.
077 * @exception Exception a generic exception.
078 */
079 @Override
080 public void exec(RunData data, String name)
081 throws Exception
082 {
083 throw new Exception("RunData objects not accepted for Scheduled jobs");
084 }
085
086 /**
087 * Pulls out an instance of the object by name. Name is just the
088 * single name of the object. This is equal to getInstance but
089 * returns an Assembler object and is needed to fulfil the Loader
090 * interface.
091 *
092 * @param name Name of object instance.
093 * @return A ScheduledJob with the specified name, or null.
094 * @exception Exception a generic exception.
095 */
096 public ScheduledJob getAssembler(String name)
097 throws Exception
098 {
099 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 }