View Javadoc
1 package org.apache.turbine.modules; 2 3 /* ==================================================================== 4 * The Apache Software License, Version 1.1 5 * 6 * Copyright (c) 2001 The Apache Software Foundation. All rights 7 * reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in 18 * the documentation and/or other materials provided with the 19 * distribution. 20 * 21 * 3. The end-user documentation included with the redistribution, 22 * if any, must include the following acknowledgment: 23 * "This product includes software developed by the 24 * Apache Software Foundation (http://www.apache.org/)." 25 * Alternately, this acknowledgment may appear in the software itself, 26 * if and wherever such third-party acknowledgments normally appear. 27 * 28 * 4. The names "Apache" and "Apache Software Foundation" and 29 * "Apache Turbine" must not be used to endorse or promote products 30 * derived from this software without prior written permission. For 31 * written permission, please contact apache@apache.org. 32 * 33 * 5. Products derived from this software may not be called "Apache", 34 * "Apache Turbine", nor may "Apache" appear in their name, without 35 * prior written permission of the Apache Software Foundation. 36 * 37 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 38 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 39 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 40 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 41 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 44 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 45 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 46 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 47 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 48 * SUCH DAMAGE. 49 * ==================================================================== 50 * 51 * This software consists of voluntary contributions made by many 52 * individuals on behalf of the Apache Software Foundation. For more 53 * information on the Apache Software Foundation, please see 54 * <http://www.apache.org/>;. 55 */ 56 57 // Java Core Classes 58 import java.util.Vector; 59 60 // Turbine Utility Classes 61 import org.apache.turbine.TurbineConstants; 62 import org.apache.turbine.services.resources.TurbineResources; 63 import org.apache.turbine.services.TurbineServices; 64 import org.apache.turbine.services.assemblerbroker.AssemblerBrokerService; 65 import org.apache.turbine.util.ObjectUtils; 66 import org.apache.turbine.util.RunData; 67 68 //Turbine Schedule Classes 69 import org.apache.turbine.services.schedule.JobEntry; 70 71 /*** 72 * ScheduledJobs loader class. 73 * 74 * @author <a href="mailto:mbryson@mindspring.com">Dave Bryson</a> 75 * @version $Id: ScheduledJobLoader.java,v 1.1.1.1 2001/08/16 05:08:30 jvanzyl Exp $ 76 */ 77 public class ScheduledJobLoader extends GenericLoader 78 { 79 /*** The single instance of this class. */ 80 private static ScheduledJobLoader instance = new ScheduledJobLoader( 81 TurbineResources.getInt(TurbineConstants.SCHEDULED_JOB_CACHE_SIZE, 10)); 82 83 /*** 84 * These constructor's are private to force clients to use getInstance() 85 * to access this class. 86 */ 87 private ScheduledJobLoader() 88 { 89 super(); 90 } 91 92 /*** 93 * These constructor's are private to force clients to use getInstance() 94 * to access this class. 95 */ 96 private ScheduledJobLoader(int i) 97 { 98 super(i); 99 } 100 101 /*** 102 * Adds an instance of an object into the hashtable. 103 * 104 * @param name Name of object. 105 * @param job Job to be associated with name. 106 */ 107 private void addInstance( String name, ScheduledJob job ) 108 { 109 if ( cache() ) 110 this.put( name, (ScheduledJob) job ); 111 } 112 113 /*** 114 * Attempts to load and execute the external ScheduledJob. 115 * 116 * @param job The JobEntry. 117 * @param name Name of object that will execute the job. 118 * @exception Exception a generic exception. 119 */ 120 public void exec( JobEntry job, String name ) 121 throws Exception 122 { 123 // Execute job 124 getInstance(name).run(job); 125 } 126 127 /*** 128 * Attempts to load and execute the external ScheduledJob. 129 * 130 * HELP! - THIS IS UGLY! 131 * 132 * I want the cache stuff from GenericLoader, BUT, I don't think 133 * the scheduler needs the Rundata object. The scheduler runs 134 * independently of an HTTP request. This should not extend 135 * GenericLoader! Thoughts?? 136 * 137 * @param data Turbine information. 138 * @param name Name of object that will execute the job. 139 * @exception Exception a generic exception. 140 */ 141 public void exec(RunData data, String name) 142 throws Exception 143 { 144 throw new Exception("RunData objects not accepted for Scheduled jobs"); 145 } 146 147 /*** 148 * Pulls out an instance of the object by name. Name is just the 149 * single name of the object. 150 * 151 * @param name Name of object instance. 152 * @return An ScheduledJob with the specified name, or null. 153 * @exception Exception a generic exception. 154 */ 155 public ScheduledJob getInstance(String name) 156 throws Exception 157 { 158 ScheduledJob job = null; 159 160 // Check if the screen is already in the cache 161 if ( cache() && this.containsKey( name ) ) 162 { 163 job = (ScheduledJob) this.get( name ); 164 } 165 else 166 { 167 // We get the broker service 168 AssemblerBrokerService ab = 169 (AssemblerBrokerService)TurbineServices.getInstance() 170 .getService (AssemblerBrokerService.SERVICE_NAME); 171 172 try 173 { 174 // Attempt to load the screen 175 job = (ScheduledJob) ab.getAssembler( 176 AssemblerBrokerService.SCHEDULEDJOB_TYPE,name); 177 } 178 catch (ClassCastException cce) 179 { 180 // This can alternatively let this exception be thrown 181 // So that the ClassCastException is shown in the 182 // browser window. Like this it shows "Screen not Found" 183 job = null; 184 } 185 186 if (job == null) 187 { 188 // If we did not find a screen we should try and give 189 // the user a reason for that... 190 // FIX ME: The AssemblerFactories should each add it's own 191 // string here... 192 Vector packages = TurbineResources.getVector( 193 TurbineConstants.MODULE_PACKAGES); 194 ObjectUtils.addOnce( packages, GenericLoader.getBasePackage() ); 195 196 throw new ClassNotFoundException( 197 "\n\n\tRequested ScheduledJob not found: " + name + "\n" + 198 "\tTurbine looked in the following modules.packages " + 199 "path: \n\t" + packages.toString() + "\n"); 200 } 201 else if ( cache() ) 202 { 203 // The new instance is added to the cache 204 addInstance( name, job ); 205 } 206 } 207 return job; 208 } 209 210 /*** 211 * The method through which this class is accessed. 212 * 213 * @return The single instance of this class. 214 */ 215 public static ScheduledJobLoader getInstance() 216 { 217 return instance; 218 } 219 }

This page was automatically generated by Maven