1 package org.apache.turbine.services.schedule; 2 3 18 19 import java.util.List ; 20 import java.util.Vector ; 21 22 import javax.servlet.ServletConfig ; 23 24 import org.apache.commons.configuration.Configuration; 25 26 import org.apache.commons.lang.StringUtils; 27 28 import org.apache.commons.logging.Log; 29 import org.apache.commons.logging.LogFactory; 30 31 import org.apache.turbine.services.InitializationException; 32 import org.apache.turbine.util.TurbineException; 33 34 70 public class TurbineNonPersistentSchedulerService 71 extends TurbineSchedulerService 72 { 73 74 private static Log log = LogFactory.getLog(ScheduleService.LOGGER_NAME); 75 76 81 public TurbineNonPersistentSchedulerService() 82 throws TurbineException 83 { 84 super(); 85 } 86 87 94 public void init() 95 throws InitializationException 96 { 97 Configuration conf = getConfiguration(); 98 99 try 100 { 101 scheduleQueue = new JobQueue(); 102 mainLoop = new MainLoop(); 103 104 List jobProps = conf.getList("scheduler.jobs"); 105 List jobs = new Vector (); 106 if (!jobProps.isEmpty()) 109 { 110 for (int i = 0; i < jobProps.size(); i++) 111 { 112 String jobName = (String ) jobProps.get(i); 113 String jobPrefix = "scheduler.job." + jobName; 114 115 String jobId = conf.getString(jobPrefix + ".ID", null); 116 if (StringUtils.isEmpty(jobId)) 117 { 118 throw new Exception ( 119 "There is an error in the TurbineResources.properties file. \n" 120 + jobPrefix + ".ID is not found.\n"); 121 } 122 123 int sec = conf.getInt(jobPrefix + ".SECOND", -1); 124 int min = conf.getInt(jobPrefix + ".MINUTE", -1); 125 int hr = conf.getInt(jobPrefix + ".HOUR", -1); 126 int wkday = conf.getInt(jobPrefix + ".WEEKDAY", -1); 127 int dayOfMonth = conf.getInt(jobPrefix + ".DAY_OF_MONTH", -1); 128 129 JobEntry je = new JobEntry( 130 sec, 131 min, 132 hr, 133 wkday, 134 dayOfMonth, 135 jobName); 136 je.setJobId(Integer.parseInt(jobId)); 137 jobs.add(je); 138 139 } 140 } 141 142 if (jobs != null && jobs.size() > 0) 143 { 144 scheduleQueue.batchLoad(jobs); 145 } 146 147 setEnabled(getConfiguration().getBoolean("enabled", true)); 148 restart(); 149 150 setInit(true); 151 } 152 catch (Exception e) 153 { 154 String errorMessage = "Could not initialize the scheduler service"; 155 log.error(errorMessage, e); 156 throw new InitializationException(errorMessage, e); 157 } 158 } 159 160 170 public void init(ServletConfig config) 171 throws InitializationException 172 { 173 init(); 174 } 175 176 183 public JobEntry getJob(int oid) 184 throws TurbineException 185 { 186 JobEntry je = new JobEntry(); 187 je.setJobId(oid); 188 return scheduleQueue.getJob(je); 189 } 190 191 197 public void addJob(JobEntry je) 198 throws TurbineException 199 { 200 updateJob(je); 201 } 202 203 208 public void removeJob(JobEntry je) 209 { 210 scheduleQueue.remove(je); 212 restart(); 213 } 214 215 221 public void updateJob(JobEntry je) 222 throws TurbineException 223 { 224 try 225 { 226 je.calcRunTime(); 227 228 scheduleQueue.modify(je); 230 restart(); 231 } 232 catch (Exception e) 233 { 234 String errorMessage = "Problem updating Scheduled Job: " + je.getTask(); 235 log.error(errorMessage, e); 236 throw new TurbineException(errorMessage, e); 237 } 238 } 239 } 240 | Popular Tags |