001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.kfs.sys.batch;
017
018 import java.util.Properties;
019
020 import javax.sql.DataSource;
021
022 import org.kuali.rice.ksb.messaging.quartz.MessageServiceExecutorJobListener;
023 import org.quartz.Scheduler;
024 import org.quartz.SchedulerException;
025 import org.quartz.SchedulerFactory;
026
027 /**
028 * This class wraps the spring version to allow deploy time determination of whether to actually create a scheduler and whether to
029 * use the jdbc or ram job store.
030 */
031 public class SchedulerFactoryBean extends org.springframework.scheduling.quartz.SchedulerFactoryBean {
032 private static final Scheduler SCHEDULER_DUMMY = new SchedulerDummy();
033 private boolean useQuartzScheduling;
034 private boolean useJdbcJobstore;
035 private DataSource dataSourceReference;
036 private Properties quartzPropertiesReference;
037 private DataSource nonTransactionalDataSourceReference;
038
039 @Override
040 public void destroy() throws SchedulerException {
041 if (useQuartzScheduling) {
042 super.destroy();
043 }
044 }
045
046 public void afterPropertiesSet() throws Exception {
047 if (useQuartzScheduling) {
048 if (useJdbcJobstore) {
049 quartzPropertiesReference.put("org.quartz.jobStore.useProperties", "false");
050 quartzPropertiesReference.put("org.quartz.jobStore.isClustered", "true");
051 setDataSource(dataSourceReference);
052 setNonTransactionalDataSource(nonTransactionalDataSourceReference);
053 }
054 setQuartzProperties(quartzPropertiesReference);
055 super.afterPropertiesSet();
056 }
057 }
058
059 public Object getObject() {
060 if (useQuartzScheduling) {
061 return super.getObject();
062 }
063 return SCHEDULER_DUMMY;
064 }
065
066 /**
067 * @see org.springframework.scheduling.quartz.SchedulerFactoryBean#createScheduler(org.quartz.SchedulerFactory, java.lang.String)
068 */
069 @Override
070 protected Scheduler createScheduler(SchedulerFactory schedulerFactory, String schedulerName) throws SchedulerException {
071 Scheduler scheduler = super.createScheduler(schedulerFactory, schedulerName);
072 scheduler.addJobListener(new MessageServiceExecutorJobListener());
073 return scheduler;
074 }
075
076 /**
077 * Sets the dataSourceReference attribute value.
078 *
079 * @param dataSourceReference The dataSourceReference to set.
080 */
081 public void setDataSourceReference(DataSource dataSourceReference) {
082 this.dataSourceReference = dataSourceReference;
083 }
084
085 /**
086 * Sets the useJdbcJobstore attribute value.
087 *
088 * @param useJdbcJobstore The useJdbcJobstore to set.
089 */
090 public void setUseJdbcJobstore(boolean useJdbcJobstore) {
091 this.useJdbcJobstore = useJdbcJobstore;
092 }
093
094 /**
095 * Sets the useQuartzScheduling attribute value.
096 *
097 * @param useQuartzScheduling The useQuartzScheduling to set.
098 */
099 public void setUseQuartzScheduling(boolean useQuartzScheduling) {
100 this.useQuartzScheduling = useQuartzScheduling;
101 }
102
103 /**
104 * Sets the quartzPropertiesReference attribute value.
105 *
106 * @param quartzPropertiesReference The quartzPropertiesReference to set.
107 */
108 public void setQuartzPropertiesReference(Properties quartzPropertiesReference) {
109 this.quartzPropertiesReference = quartzPropertiesReference;
110 }
111
112 public DataSource getNonTransactionalDataSourceReference() {
113 return nonTransactionalDataSourceReference;
114 }
115
116 public void setNonTransactionalDataSourceReference(DataSource nonTransactionalDataSourceReference) {
117 this.nonTransactionalDataSourceReference = nonTransactionalDataSourceReference;
118 }
119 }