View Javadoc

1   /*
2    * Copyright 2007 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.sys.batch;
17  
18  import java.util.Date;
19  
20  import org.apache.log4j.Logger;
21  import org.kuali.ole.sys.OLEConstants;
22  import org.kuali.ole.sys.batch.service.SchedulerService;
23  
24  public class ScheduleStep extends AbstractStep {
25      private static final Logger LOG = Logger.getLogger(ScheduleStep.class);
26      private SchedulerService schedulerService;
27  
28      /**
29       * @see org.kuali.ole.sys.batch.Step#execute(String, Date)
30       */
31      public boolean execute(String jobName, Date jobRunDate) {
32          boolean isPastScheduleCutoffTime = false;
33          schedulerService.reinitializeScheduledJobs();
34          while (schedulerService.hasIncompleteJob() && !isPastScheduleCutoffTime) {
35              schedulerService.processWaitingJobs();
36              isPastScheduleCutoffTime = schedulerService.isPastScheduleCutoffTime();
37              try {
38                  Thread.sleep(Integer.parseInt(getParameterService().getParameterValueAsString(getClass(), OLEConstants.SystemGroupParameterNames.BATCH_SCHEDULE_STATUS_CHECK_INTERVAL)));
39              }
40              catch (InterruptedException e) {
41                  throw new RuntimeException("Schedule step encountered interrupt exception while trying to wait for the specified batch schedule status check interval", e);
42              }
43          }
44          if (isPastScheduleCutoffTime) {
45              LOG.info("Schedule exceeded cutoff time, so it was terminated before completion");
46          }
47          schedulerService.logScheduleResults();
48          return !isPastScheduleCutoffTime;
49      }
50  
51      /**
52       * Sets the schedulerService attribute value.
53       * 
54       * @param schedulerService The schedulerService to set.
55       */
56      public void setSchedulerService(SchedulerService schedulerService) {
57          this.schedulerService = schedulerService;
58      }
59  }