01: /*
02: * Copyright 2007 The Kuali Foundation
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License"); you may not use this file except in
05: * compliance with the License. You may obtain a copy of the License at
06: *
07: * http://www.opensource.org/licenses/ecl1.php
08: *
09: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS
10: * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
11: * language governing permissions and limitations under the License.
12: */
13: package edu.iu.uis.eden.messaging.quartz;
14:
15: import org.kuali.bus.services.KSBServiceLocator;
16: import org.kuali.rice.RiceConstants;
17: import org.kuali.rice.config.ConfigurationException;
18: import org.kuali.rice.core.Core;
19: import org.quartz.Scheduler;
20: import org.quartz.SchedulerException;
21: import org.quartz.SchedulerFactory;
22: import org.springframework.scheduling.quartz.SchedulerFactoryBean;
23: import org.springframework.transaction.PlatformTransactionManager;
24:
25: /**
26: * An implementation of the Quartz SchedulerFactoryBean which uses a database-backed quartz if the useQuartzDatabase property
27: * is set.
28: *
29: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
30: */
31: public class KSBSchedulerFactoryBean extends SchedulerFactoryBean {
32:
33: private PlatformTransactionManager jtaTransactionManager;
34:
35: @Override
36: protected Scheduler createScheduler(
37: SchedulerFactory schedulerFactory, String schedulerName)
38: throws SchedulerException {
39: if (Core.getCurrentContextConfig().getObject(
40: RiceConstants.INJECTED_EXCEPTION_MESSAGE_SCHEDULER_KEY) != null) {
41: try {
42: Scheduler scheduler = (Scheduler) Core
43: .getCurrentContextConfig()
44: .getObject(
45: RiceConstants.INJECTED_EXCEPTION_MESSAGE_SCHEDULER_KEY);
46: scheduler
47: .addJobListener(new MessageServiceExecutorJobListener());
48: return scheduler;
49: } catch (Exception e) {
50: throw new ConfigurationException(e);
51: }
52: }
53: return super .createScheduler(schedulerFactory, schedulerName);
54: }
55:
56: @Override
57: public void afterPropertiesSet() throws Exception {
58:
59: boolean useQuartzDatabase = new Boolean(Core
60: .getCurrentContextConfig().getProperty(
61: RiceConstants.USE_QUARTZ_DATABASE));
62: if (useQuartzDatabase) {
63: if (jtaTransactionManager == null) {
64: throw new ConfigurationException(
65: "No jta transaction manager was configured for the KSB Quartz Scheduler");
66: }
67: setTransactionManager(jtaTransactionManager);
68: setDataSource(KSBServiceLocator.getMessageDataSource());
69: }
70: super .afterPropertiesSet();
71: }
72:
73: /**
74: * This is to work around an issue with the GRL when you've got more than one module with a bean named
75: * "transactionManager".
76: *
77: * @param jtaTransactionManager
78: */
79: public void setJtaTransactionManager(
80: PlatformTransactionManager jtaTransactionManager) {
81: this.jtaTransactionManager = jtaTransactionManager;
82: }
83: }
|