1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kcb.config; |
17 | |
|
18 | |
import org.kuali.rice.kcb.service.GlobalKCBServiceLocator; |
19 | |
import org.kuali.rice.ksb.service.KSBServiceLocator; |
20 | |
import org.quartz.JobDetail; |
21 | |
import org.quartz.ObjectAlreadyExistsException; |
22 | |
import org.quartz.Scheduler; |
23 | |
import org.quartz.SchedulerException; |
24 | |
import org.quartz.Trigger; |
25 | |
import org.springframework.beans.BeansException; |
26 | |
import org.springframework.beans.factory.BeanFactory; |
27 | |
import org.springframework.beans.factory.BeanFactoryAware; |
28 | |
import org.springframework.beans.factory.DisposableBean; |
29 | |
import org.springframework.beans.factory.InitializingBean; |
30 | |
import org.springframework.beans.factory.annotation.Required; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | 0 | public class KCBInitializer implements BeanFactoryAware, InitializingBean, DisposableBean { |
39 | |
private BeanFactory beanFactory; |
40 | |
private Trigger messageProcessingTrigger; |
41 | |
private JobDetail messageProcessingJobDetail; |
42 | |
protected Scheduler scheduler; |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
public void setBeanFactory(BeanFactory beanFactory) throws BeansException { |
48 | 0 | this.beanFactory = beanFactory; |
49 | 0 | } |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
@Required |
56 | |
public void setMessageProcessingTrigger(Trigger messageProcessingTrigger) { |
57 | 0 | this.messageProcessingTrigger = messageProcessingTrigger; |
58 | 0 | } |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
@Required |
65 | |
public void setMessageProcessingJobDetail(JobDetail messageProcessingJobDetail) { |
66 | 0 | this.messageProcessingJobDetail = messageProcessingJobDetail; |
67 | 0 | } |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
public void afterPropertiesSet() throws Exception { |
73 | 0 | GlobalKCBServiceLocator.init(beanFactory); |
74 | |
|
75 | 0 | beanFactory = null; |
76 | |
|
77 | 0 | Scheduler scheduler = getScheduler()==null?KSBServiceLocator.getScheduler():getScheduler(); |
78 | 0 | scheduler.addJob(messageProcessingJobDetail, true); |
79 | |
|
80 | 0 | addTriggerToScheduler(messageProcessingTrigger); |
81 | 0 | } |
82 | |
|
83 | |
private void addTriggerToScheduler(Trigger trigger) throws SchedulerException { |
84 | 0 | boolean triggerExists = (getScheduler().getTrigger(trigger.getName(), trigger.getGroup()) != null); |
85 | 0 | if (!triggerExists) { |
86 | |
try { |
87 | 0 | getScheduler().scheduleJob(trigger); |
88 | 0 | } catch (ObjectAlreadyExistsException ex) { |
89 | 0 | getScheduler().rescheduleJob(trigger.getName(), trigger.getGroup(), trigger); |
90 | 0 | } |
91 | |
} else { |
92 | 0 | getScheduler().rescheduleJob(trigger.getName(), trigger.getGroup(), trigger); |
93 | |
} |
94 | 0 | } |
95 | |
|
96 | |
public void destroy() throws Exception { |
97 | |
|
98 | |
|
99 | 0 | GlobalKCBServiceLocator.destroy(); |
100 | 0 | } |
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
public Scheduler getScheduler() { |
106 | 0 | return this.scheduler; |
107 | |
} |
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
public void setScheduler(Scheduler scheduler) { |
113 | 0 | this.scheduler = scheduler; |
114 | 0 | } |
115 | |
|
116 | |
} |