Revision 6548ea8a
Added by Cherian Mathew almost 9 years ago
- corrected recursive autowiring
- changed application context loading to be more performant
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/RemotingMonitoredGenericApplicationContext.java | ||
---|---|---|
9 | 9 |
*/ |
10 | 10 |
package eu.etaxonomy.cdm.api.application; |
11 | 11 |
|
12 |
import java.util.concurrent.CancellationException;
|
|
12 |
import java.io.Serializable;
|
|
13 | 13 |
|
14 | 14 |
import org.apache.log4j.Logger; |
15 |
import org.springframework.beans.BeansException; |
|
16 | 15 |
import org.springframework.beans.factory.annotation.QualifierAnnotationAutowireCandidateResolver; |
17 |
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
|
16 |
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
|
18 | 17 |
import org.springframework.context.support.GenericApplicationContext; |
19 | 18 |
import org.springframework.core.LocalVariableTableParameterNameDiscoverer; |
20 | 19 |
|
21 |
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor; |
|
22 |
import eu.etaxonomy.cdm.common.monitor.SubProgressMonitor; |
|
23 |
|
|
24 | 20 |
/** |
25 | 21 |
* {@link GenericApplicationContext Generic application context} which allows progress monitoring. |
26 | 22 |
* @author a.mueller |
27 | 23 |
* @date 29.09.2011 |
28 | 24 |
* |
29 | 25 |
*/ |
30 |
public class RemotingMonitoredGenericApplicationContext extends GenericApplicationContext{ |
|
26 |
public class RemotingMonitoredGenericApplicationContext extends GenericApplicationContext implements Serializable {
|
|
31 | 27 |
@SuppressWarnings("unused") |
32 |
private static final Logger logger = Logger.getLogger(CdmApplicationController.class);
|
|
28 |
private static final Logger logger = Logger.getLogger(RemotingMonitoredGenericApplicationContext.class);
|
|
33 | 29 |
|
34 | 30 |
final int countInvokeBeanFactoryPostProcessors = 10; |
35 | 31 |
final int countFinishBeanFactoryInitialization = 90; |
36 | 32 |
private final int countTasks = countInvokeBeanFactoryPostProcessors + countFinishBeanFactoryInitialization; |
37 |
private IProgressMonitor currentMonitor; |
|
33 |
// private IProgressMonitor currentMonitor;
|
|
38 | 34 |
|
39 | 35 |
|
40 | 36 |
|
... | ... | |
42 | 38 |
* Constructor. |
43 | 39 |
* @param progressMonitor |
44 | 40 |
*/ |
41 |
// public RemotingMonitoredGenericApplicationContext() { |
|
42 |
//// MonitoredListableBeanFactory beanFactory = |
|
43 |
// super(new RemotingMonitoredListableBeanFactory()); |
|
44 |
// //taken from empty constructor of GenericApplicationContext |
|
45 |
// ((RemotingMonitoredListableBeanFactory)getBeanFactory()).setSerializationId(getId()); |
|
46 |
// ((RemotingMonitoredListableBeanFactory)getBeanFactory()).setParameterNameDiscoverer(new LocalVariableTableParameterNameDiscoverer()); |
|
47 |
// ((RemotingMonitoredListableBeanFactory)getBeanFactory()).setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver()); |
|
48 |
// } |
|
49 |
|
|
45 | 50 |
public RemotingMonitoredGenericApplicationContext() { |
46 |
// MonitoredListableBeanFactory beanFactory =
|
|
47 |
super(new RemotingMonitoredListableBeanFactory());
|
|
51 |
// MonitoredListableBeanFactory beanFactory =
|
|
52 |
super(); |
|
48 | 53 |
//taken from empty constructor of GenericApplicationContext |
49 |
((RemotingMonitoredListableBeanFactory)getBeanFactory()).setSerializationId(getId());
|
|
50 |
((RemotingMonitoredListableBeanFactory)getBeanFactory()).setParameterNameDiscoverer(new LocalVariableTableParameterNameDiscoverer());
|
|
51 |
((RemotingMonitoredListableBeanFactory)getBeanFactory()).setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver());
|
|
54 |
((DefaultListableBeanFactory)getBeanFactory()).setSerializationId(getId());
|
|
55 |
((DefaultListableBeanFactory)getBeanFactory()).setParameterNameDiscoverer(new LocalVariableTableParameterNameDiscoverer());
|
|
56 |
((DefaultListableBeanFactory)getBeanFactory()).setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver());
|
|
52 | 57 |
} |
53 | 58 |
|
54 | 59 |
|
55 |
public int countTasks(){ |
|
56 |
return countTasks; |
|
57 |
} |
|
58 |
|
|
59 |
protected void invokeBeanFactoryPostProcessors(ConfigurableListableBeanFactory beanFactory){ |
|
60 |
String task = "Invoke bean factory post processors"; |
|
61 |
checkMonitorCancelled(currentMonitor); |
|
62 |
currentMonitor.subTask(task); |
|
63 |
super.invokeBeanFactoryPostProcessors(beanFactory); |
|
64 |
currentMonitor.worked(countInvokeBeanFactoryPostProcessors); |
|
65 |
checkMonitorCancelled(currentMonitor); |
|
66 |
} |
|
60 |
// public int countTasks(){ |
|
61 |
// return countTasks; |
|
62 |
// } |
|
63 |
// |
|
64 |
// @Override |
|
65 |
// protected void invokeBeanFactoryPostProcessors(ConfigurableListableBeanFactory beanFactory){ |
|
66 |
// String task = "Invoke bean factory post processors"; |
|
67 |
//// checkMonitorCancelled(currentMonitor); |
|
68 |
//// currentMonitor.subTask(task); |
|
69 |
// super.invokeBeanFactoryPostProcessors(beanFactory); |
|
70 |
//// currentMonitor.worked(countInvokeBeanFactoryPostProcessors); |
|
71 |
//// checkMonitorCancelled(currentMonitor); |
|
72 |
// } |
|
73 |
// |
|
74 |
// @Override |
|
75 |
// protected void finishBeanFactoryInitialization(ConfigurableListableBeanFactory beanFactory){ |
|
76 |
//// checkMonitorCancelled(currentMonitor); |
|
77 |
// String task = "Finish bean factory initialization"; |
|
78 |
//// currentMonitor.subTask(task); |
|
79 |
//// IProgressMonitor subMonitor = new SubProgressMonitor(currentMonitor, countFinishBeanFactoryInitialization); |
|
80 |
//// getMyBeanFactory().setCurrentMonitor(subMonitor); |
|
81 |
// super.finishBeanFactoryInitialization(beanFactory); |
|
82 |
//// checkMonitorCancelled(currentMonitor); |
|
83 |
// |
|
84 |
// } |
|
85 |
|
|
86 |
// /** |
|
87 |
// * @param progressMonitor the progressMonitor to set |
|
88 |
// */ |
|
89 |
// public void setCurrentMonitor(IProgressMonitor monitor) { |
|
90 |
//// this.currentMonitor = monitor; |
|
91 |
// } |
|
92 |
// |
|
93 |
// /** |
|
94 |
// * |
|
95 |
// */ |
|
96 |
// public IProgressMonitor getCurrentMonitor() { |
|
97 |
//// return currentMonitor; |
|
98 |
// return null; |
|
99 |
// } |
|
100 |
|
|
101 |
|
|
102 |
// /* (non-Javadoc) |
|
103 |
// * @see org.springframework.context.support.AbstractApplicationContext#refresh() |
|
104 |
// */ |
|
105 |
// @Override |
|
106 |
// public void refresh() throws BeansException, IllegalStateException { |
|
107 |
// //checkMonitorCancelled(monitor); |
|
108 |
// String message = "Refresh application context. This might take a while ..."; |
|
109 |
//// currentMonitor = monitor; |
|
110 |
// beginTask(message, countTasks); |
|
111 |
// super.refresh(); |
|
112 |
// taskDone(); |
|
113 |
// //checkMonitorCancelled(monitor); |
|
114 |
// } |
|
67 | 115 |
|
68 |
protected void finishBeanFactoryInitialization(ConfigurableListableBeanFactory beanFactory){ |
|
69 |
checkMonitorCancelled(currentMonitor); |
|
70 |
String task = "Finish bean factory initialization"; |
|
71 |
currentMonitor.subTask(task); |
|
72 |
IProgressMonitor subMonitor = new SubProgressMonitor(currentMonitor, countFinishBeanFactoryInitialization); |
|
73 |
getMyBeanFactory().setCurrentMonitor(subMonitor); |
|
74 |
super.finishBeanFactoryInitialization(beanFactory); |
|
75 |
checkMonitorCancelled(currentMonitor); |
|
76 |
|
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* @param progressMonitor the progressMonitor to set |
|
81 |
*/ |
|
82 |
public void setCurrentMonitor(IProgressMonitor monitor) { |
|
83 |
this.currentMonitor = monitor; |
|
84 |
} |
|
85 | 116 |
|
86 | 117 |
/** |
87 | 118 |
* |
88 | 119 |
*/ |
89 |
public IProgressMonitor getCurrentMonitor() { |
|
90 |
return currentMonitor; |
|
91 |
} |
|
92 |
|
|
93 |
|
|
94 |
/* (non-Javadoc) |
|
95 |
* @see org.springframework.context.support.AbstractApplicationContext#refresh() |
|
96 |
*/ |
|
97 |
public void refresh(IProgressMonitor monitor) throws BeansException, IllegalStateException { |
|
98 |
checkMonitorCancelled(monitor); |
|
99 |
String message = "Refresh application context. This might take a while ..."; |
|
100 |
currentMonitor = monitor; |
|
101 |
beginTask(message, countTasks); |
|
102 |
super.refresh(); |
|
103 |
taskDone(); |
|
104 |
checkMonitorCancelled(monitor); |
|
105 |
} |
|
106 |
|
|
107 |
|
|
108 |
/** |
|
109 |
* |
|
110 |
*/ |
|
111 |
private void taskDone() { |
|
112 |
if (currentMonitor != null){ |
|
113 |
currentMonitor.done(); |
|
114 |
} |
|
115 |
} |
|
116 |
|
|
117 |
|
|
118 |
/** |
|
119 |
* @param monitor |
|
120 |
* @param message |
|
121 |
*/ |
|
122 |
private void beginTask(String message, int countTasks) { |
|
123 |
if (currentMonitor != null){ |
|
124 |
currentMonitor.beginTask(message, countTasks); |
|
125 |
} |
|
126 |
} |
|
127 |
|
|
128 |
|
|
129 |
private RemotingMonitoredListableBeanFactory getMyBeanFactory(){ |
|
130 |
return (RemotingMonitoredListableBeanFactory)getBeanFactory(); |
|
131 |
} |
|
132 |
|
|
133 |
|
|
134 |
private void checkMonitorCancelled(IProgressMonitor monitor) { |
|
135 |
if (monitor != null && monitor.isCanceled()){ |
|
136 |
throw new CancellationException(); |
|
137 |
} |
|
138 |
} |
|
120 |
// private void taskDone() { |
|
121 |
//// if (currentMonitor != null){ |
|
122 |
//// currentMonitor.done(); |
|
123 |
//// } |
|
124 |
// } |
|
125 |
|
|
126 |
|
|
127 |
// /** |
|
128 |
// * @param monitor |
|
129 |
// * @param message |
|
130 |
// */ |
|
131 |
// private void beginTask(String message, int countTasks) { |
|
132 |
//// if (currentMonitor != null){ |
|
133 |
//// currentMonitor.beginTask(message, countTasks); |
|
134 |
//// } |
|
135 |
// } |
|
136 |
|
|
137 |
|
|
138 |
// private RemotingMonitoredListableBeanFactory getMyBeanFactory(){ |
|
139 |
// return (RemotingMonitoredListableBeanFactory)getBeanFactory(); |
|
140 |
// } |
|
141 |
// |
|
142 |
// |
|
143 |
// private void checkMonitorCancelled(IProgressMonitor monitor) { |
|
144 |
// if (monitor != null && monitor.isCanceled()){ |
|
145 |
// throw new CancellationException(); |
|
146 |
// } |
|
147 |
// } |
|
139 | 148 |
} |
Also available in: Unified diff