1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.ksb.messaging.quartz; |
17 | |
|
18 | |
import org.kuali.rice.core.api.config.ConfigurationException; |
19 | |
import org.kuali.rice.core.api.config.property.ConfigContext; |
20 | |
import org.kuali.rice.ksb.service.KSBServiceLocator; |
21 | |
import org.kuali.rice.ksb.util.KSBConstants; |
22 | |
import org.quartz.Scheduler; |
23 | |
import org.quartz.SchedulerException; |
24 | |
import org.quartz.SchedulerFactory; |
25 | |
import org.springframework.scheduling.quartz.SchedulerFactoryBean; |
26 | |
import org.springframework.transaction.PlatformTransactionManager; |
27 | |
|
28 | |
import javax.sql.DataSource; |
29 | |
import javax.transaction.TransactionManager; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | 0 | public class KSBSchedulerFactoryBean extends SchedulerFactoryBean { |
38 | |
|
39 | |
private PlatformTransactionManager jtaTransactionManager; |
40 | |
private TransactionManager transactionManager; |
41 | |
private DataSource dataSource; |
42 | |
private DataSource nonTransactionalDataSource; |
43 | 0 | private boolean transactionManagerSet = false; |
44 | 0 | private boolean nonTransactionalDataSourceSet = false; |
45 | 0 | private boolean nonTransactionalDataSourceNull = true; |
46 | 0 | private boolean dataSourceSet = false; |
47 | 0 | private boolean schedulerInjected = false; |
48 | |
|
49 | |
@Override |
50 | |
protected Scheduler createScheduler(SchedulerFactory schedulerFactory, String schedulerName) throws SchedulerException { |
51 | 0 | if (ConfigContext.getCurrentContextConfig().getObject(KSBConstants.Config.INJECTED_EXCEPTION_MESSAGE_SCHEDULER_KEY) != null) { |
52 | |
try { |
53 | 0 | schedulerInjected = true; |
54 | 0 | Scheduler scheduler = (Scheduler) ConfigContext.getCurrentContextConfig().getObject(KSBConstants.Config.INJECTED_EXCEPTION_MESSAGE_SCHEDULER_KEY); |
55 | 0 | scheduler.addJobListener(new MessageServiceExecutorJobListener()); |
56 | 0 | return scheduler; |
57 | 0 | } catch (Exception e) { |
58 | 0 | throw new ConfigurationException(e); |
59 | |
} |
60 | |
} |
61 | 0 | return super.createScheduler(schedulerFactory, schedulerName); |
62 | |
} |
63 | |
|
64 | |
@Override |
65 | |
public void afterPropertiesSet() throws Exception { |
66 | |
|
67 | 0 | boolean useQuartzDatabase = new Boolean(ConfigContext.getCurrentContextConfig().getProperty(KSBConstants.Config.USE_QUARTZ_DATABASE)); |
68 | 0 | if (useQuartzDatabase && !schedulerInjected) { |
69 | |
|
70 | 0 | if (jtaTransactionManager == null) { |
71 | 0 | throw new ConfigurationException("No jta transaction manager was configured for the KSB Quartz Scheduler"); |
72 | |
} |
73 | 0 | setTransactionManager(jtaTransactionManager); |
74 | 0 | if (!nonTransactionalDataSourceSet) { |
75 | |
|
76 | 0 | nonTransactionalDataSource = KSBServiceLocator.getMessageNonTransactionalDataSource(); |
77 | 0 | if (nonTransactionalDataSource == null) { |
78 | 0 | throw new ConfigurationException("No non-transactional data source was found but is required for the KSB Quartz Scheduler"); |
79 | |
} |
80 | 0 | super.setNonTransactionalDataSource(nonTransactionalDataSource); |
81 | |
} |
82 | 0 | if (!dataSourceSet) { |
83 | 0 | dataSource = KSBServiceLocator.getMessageDataSource(); |
84 | |
} |
85 | 0 | super.setDataSource(dataSource); |
86 | 0 | if (transactionManagerSet && nonTransactionalDataSourceNull) { |
87 | 0 | throw new ConfigurationException("A valid transaction manager was set but no non-transactional data source was found"); |
88 | |
} |
89 | |
} |
90 | 0 | super.afterPropertiesSet(); |
91 | 0 | } |
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
@Override |
99 | |
public void setTransactionManager(PlatformTransactionManager jtaTransactionManager) { |
100 | 0 | transactionManagerSet = jtaTransactionManager != null; |
101 | 0 | this.jtaTransactionManager = jtaTransactionManager; |
102 | 0 | } |
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
@Override |
110 | |
public void setNonTransactionalDataSource(DataSource nonTransactionalDataSource) { |
111 | 0 | nonTransactionalDataSourceSet = true; |
112 | 0 | nonTransactionalDataSourceNull = (nonTransactionalDataSource == null); |
113 | 0 | this.nonTransactionalDataSource = nonTransactionalDataSource; |
114 | 0 | } |
115 | |
|
116 | |
@Override |
117 | |
public void setDataSource(DataSource dataSource) { |
118 | 0 | dataSourceSet = true; |
119 | 0 | this.dataSource = dataSource; |
120 | 0 | } |
121 | |
} |