1 package org.apache.turbine.modules; 2 3 18 19 import java.util.List ; 20 21 import org.apache.commons.logging.Log; 22 import org.apache.commons.logging.LogFactory; 23 24 import org.apache.turbine.Turbine; 25 import org.apache.turbine.TurbineConstants; 26 import org.apache.turbine.services.assemblerbroker.AssemblerBrokerService; 27 import org.apache.turbine.services.assemblerbroker.TurbineAssemblerBroker; 28 import org.apache.turbine.services.schedule.JobEntry; 29 import org.apache.turbine.util.ObjectUtils; 30 import org.apache.turbine.util.RunData; 31 32 39 public class ScheduledJobLoader 40 extends GenericLoader 41 { 42 43 private static Log log = LogFactory.getLog(ScheduledJobLoader.class); 44 45 46 private static ScheduledJobLoader instance = 47 new ScheduledJobLoader(Turbine.getConfiguration() 48 .getInt(TurbineConstants.SCHEDULED_JOB_CACHE_SIZE_KEY, 49 TurbineConstants.SCHEDULED_JOB_CACHE_SIZE_DEFAULT)); 50 51 52 private static AssemblerBrokerService ab = TurbineAssemblerBroker.getService(); 53 54 58 private ScheduledJobLoader() 59 { 60 super(); 61 } 62 63 67 private ScheduledJobLoader(int i) 68 { 69 super(i); 70 } 71 72 78 private void addInstance(String name, ScheduledJob job) 79 { 80 if (cache()) 81 { 82 this.put(name, (ScheduledJob) job); 83 } 84 } 85 86 93 public void exec(JobEntry job, String name) 94 throws Exception 95 { 96 getInstance(name).run(job); 98 } 99 100 114 public void exec(RunData data, String name) 115 throws Exception 116 { 117 throw new Exception ("RunData objects not accepted for Scheduled jobs"); 118 } 119 120 128 public ScheduledJob getInstance(String name) 129 throws Exception 130 { 131 ScheduledJob job = null; 132 133 if (cache() && this.containsKey(name)) 135 { 136 job = (ScheduledJob) this.get(name); 137 log.debug("Found Job " + name + " in the cache!"); 138 } 139 else 140 { 141 log.debug("Loading Job " + name + " from the Assembler Broker"); 142 143 try 144 { 145 if (ab != null) 146 { 147 job = (ScheduledJob) ab.getAssembler( 149 AssemblerBrokerService.SCHEDULEDJOB_TYPE, name); 150 } 151 } 152 catch (ClassCastException cce) 153 { 154 job = null; 158 } 159 160 if (job == null) 161 { 162 List packages = Turbine.getConfiguration() 167 .getList(TurbineConstants.MODULE_PACKAGES); 168 169 ObjectUtils.addOnce(packages, GenericLoader.getBasePackage()); 170 171 throw new ClassNotFoundException ( 172 "\n\n\tRequested ScheduledJob not found: " + name + 173 "\n\tTurbine looked in the following " + 174 "modules.packages path: \n\t" + packages.toString() + "\n"); 175 } 176 else if (cache()) 177 { 178 addInstance(name, job); 180 } 181 } 182 return job; 183 } 184 185 190 public static ScheduledJobLoader getInstance() 191 { 192 return instance; 193 } 194 } 195 | Popular Tags |