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.Properties;
19  
20  import javax.sql.DataSource;
21  
22  import org.kuali.rice.core.api.config.property.ConfigContext;
23  import org.kuali.rice.core.api.util.RiceConstants;
24  import org.kuali.rice.ksb.messaging.quartz.MessageServiceExecutorJobListener;
25  import org.quartz.Scheduler;
26  import org.quartz.SchedulerException;
27  import org.quartz.SchedulerFactory;
28  
29  /**
30   * This class wraps the spring version to allow deploy time determination of whether to actually create a scheduler and whether to
31   * use the jdbc or ram job store.
32   */
33  public class SchedulerFactoryBean extends org.springframework.scheduling.quartz.SchedulerFactoryBean {
34      private static final Scheduler SCHEDULER_DUMMY = new SchedulerDummy();
35      private boolean useQuartzScheduling;
36      private boolean useJdbcJobstore;
37      private Properties quartzPropertiesReference;
38  
39      @Override
40      public void destroy() throws SchedulerException {
41          if (useQuartzScheduling) {
42              super.destroy();
43          }
44      }
45  
46      @Override
47      public void afterPropertiesSet() throws Exception {
48          if (useQuartzScheduling) {
49              if (useJdbcJobstore) {
50                  quartzPropertiesReference.put("org.quartz.jobStore.useProperties", "false");
51                  quartzPropertiesReference.put("org.quartz.jobStore.isClustered", "true");
52                  setDataSource((DataSource) ConfigContext.getCurrentContextConfig().getObject(RiceConstants.DATASOURCE_OBJ));
53                  setNonTransactionalDataSource((DataSource) ConfigContext.getCurrentContextConfig().getObject(RiceConstants.NON_TRANSACTIONAL_DATASOURCE_OBJ));
54              }
55              setQuartzProperties(quartzPropertiesReference);
56              super.afterPropertiesSet();
57          }
58      }
59  
60      @Override
61      public Scheduler getObject() {
62          if (useQuartzScheduling) {
63              return super.getObject();
64          }
65          return SCHEDULER_DUMMY;
66      }
67  
68      /**
69       * @see org.springframework.scheduling.quartz.SchedulerFactoryBean#createScheduler(org.quartz.SchedulerFactory, java.lang.String)
70       */
71      @Override
72      protected Scheduler createScheduler(SchedulerFactory schedulerFactory, String schedulerName) throws SchedulerException {
73          Scheduler scheduler = super.createScheduler(schedulerFactory, schedulerName);
74          scheduler.addJobListener(new MessageServiceExecutorJobListener());
75          return scheduler;
76      }
77      
78      /**
79       * Sets the useJdbcJobstore attribute value.
80       * 
81       * @param useJdbcJobstore The useJdbcJobstore to set.
82       */
83      public void setUseJdbcJobstore(boolean useJdbcJobstore) {
84          this.useJdbcJobstore = useJdbcJobstore;
85      }
86  
87      /**
88       * Sets the useQuartzScheduling attribute value.
89       * 
90       * @param useQuartzScheduling The useQuartzScheduling to set.
91       */
92      public void setUseQuartzScheduling(boolean useQuartzScheduling) {
93          this.useQuartzScheduling = useQuartzScheduling;
94      }
95  
96      /**
97       * Sets the quartzPropertiesReference attribute value.
98       * 
99       * @param quartzPropertiesReference The quartzPropertiesReference to set.
100      */
101     public void setQuartzPropertiesReference(Properties quartzPropertiesReference) {
102         this.quartzPropertiesReference = quartzPropertiesReference;
103     }
104 }