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