Revision 532683bd
Added by Patrick Plitzner over 11 years ago
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/application/MonitoredGenericApplicationContext.java | ||
---|---|---|
1 | 1 |
// $Id$ |
2 | 2 |
/** |
3 | 3 |
* Copyright (C) 2009 EDIT |
4 |
* European Distributed Institute of Taxonomy
|
|
4 |
* European Distributed Institute of Taxonomy |
|
5 | 5 |
* http://www.e-taxonomy.eu |
6 |
*
|
|
6 |
* |
|
7 | 7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
8 | 8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
9 | 9 |
*/ |
... | ... | |
28 | 28 |
* |
29 | 29 |
*/ |
30 | 30 |
public class MonitoredGenericApplicationContext extends GenericApplicationContext{ |
31 |
@SuppressWarnings("unused") |
|
32 |
private static final Logger logger = Logger.getLogger(CdmApplicationController.class); |
|
33 |
|
|
34 |
final int countInvokeBeanFactoryPostProcessors = 10; |
|
35 |
final int countFinishBeanFactoryInitialization = 90; |
|
36 |
private final int countTasks = countInvokeBeanFactoryPostProcessors + countFinishBeanFactoryInitialization; |
|
37 |
private IProgressMonitor currentMonitor; |
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
/** |
|
42 |
* Constructor. |
|
43 |
* @param progressMonitor |
|
44 |
*/ |
|
45 |
public MonitoredGenericApplicationContext() { |
|
46 |
// MonitoredListableBeanFactory beanFactory = |
|
47 |
super(new MonitoredListableBeanFactory()); |
|
48 |
//taken from empty constructor of GenericApplicationContext |
|
49 |
((MonitoredListableBeanFactory)getBeanFactory()).setSerializationId(getId()); |
|
50 |
((MonitoredListableBeanFactory)getBeanFactory()).setParameterNameDiscoverer(new LocalVariableTableParameterNameDiscoverer()); |
|
51 |
((MonitoredListableBeanFactory)getBeanFactory()).setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver()); |
|
52 |
} |
|
53 |
|
|
54 |
|
|
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 |
} |
|
67 |
|
|
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 |
|
|
86 |
|
|
87 |
/* (non-Javadoc) |
|
88 |
* @see org.springframework.context.support.AbstractApplicationContext#refresh() |
|
89 |
*/ |
|
90 |
public void refresh(IProgressMonitor monitor) throws BeansException, IllegalStateException { |
|
91 |
checkMonitorCancelled(monitor); |
|
92 |
String message = "Refresh application context. This might take a while ..."; |
|
93 |
currentMonitor = monitor; |
|
94 |
beginTask(message, countTasks); |
|
95 |
super.refresh(); |
|
96 |
taskDone(); |
|
97 |
checkMonitorCancelled(monitor); |
|
98 |
} |
|
99 |
|
|
100 |
|
|
101 |
/** |
|
102 |
* |
|
103 |
*/ |
|
104 |
private void taskDone() { |
|
105 |
if (currentMonitor != null){ |
|
106 |
currentMonitor.done(); |
|
107 |
} |
|
108 |
} |
|
109 |
|
|
110 |
|
|
111 |
/** |
|
112 |
* @param monitor |
|
113 |
* @param message |
|
114 |
*/ |
|
115 |
private void beginTask(String message, int countTasks) { |
|
116 |
if (currentMonitor != null){ |
|
117 |
currentMonitor.beginTask(message, countTasks); |
|
118 |
} |
|
119 |
} |
|
120 |
|
|
121 |
|
|
122 |
private MonitoredListableBeanFactory getMyBeanFactory(){ |
|
123 |
return (MonitoredListableBeanFactory)getBeanFactory(); |
|
124 |
} |
|
125 |
|
|
126 |
|
|
127 |
private void checkMonitorCancelled(IProgressMonitor monitor) { |
|
128 |
if (monitor != null && monitor.isCanceled()){ |
|
129 |
throw new CancellationException(); |
|
130 |
} |
|
131 |
} |
|
31 |
@SuppressWarnings("unused") |
|
32 |
private static final Logger logger = Logger.getLogger(CdmApplicationController.class); |
|
33 |
|
|
34 |
final int countInvokeBeanFactoryPostProcessors = 10; |
|
35 |
final int countFinishBeanFactoryInitialization = 90; |
|
36 |
private final int countTasks = countInvokeBeanFactoryPostProcessors + countFinishBeanFactoryInitialization; |
|
37 |
private IProgressMonitor currentMonitor; |
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
/** |
|
42 |
* Constructor. |
|
43 |
* @param progressMonitor |
|
44 |
*/ |
|
45 |
public MonitoredGenericApplicationContext() { |
|
46 |
// MonitoredListableBeanFactory beanFactory = |
|
47 |
super(new MonitoredListableBeanFactory()); |
|
48 |
//taken from empty constructor of GenericApplicationContext |
|
49 |
((MonitoredListableBeanFactory)getBeanFactory()).setSerializationId(getId()); |
|
50 |
((MonitoredListableBeanFactory)getBeanFactory()).setParameterNameDiscoverer(new LocalVariableTableParameterNameDiscoverer()); |
|
51 |
((MonitoredListableBeanFactory)getBeanFactory()).setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver()); |
|
52 |
} |
|
53 |
|
|
54 |
|
|
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 |
} |
|
67 |
|
|
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 |
|
|
86 |
/** |
|
87 |
* |
|
88 |
*/ |
|
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 MonitoredListableBeanFactory getMyBeanFactory(){ |
|
130 |
return (MonitoredListableBeanFactory)getBeanFactory(); |
|
131 |
} |
|
132 |
|
|
133 |
|
|
134 |
private void checkMonitorCancelled(IProgressMonitor monitor) { |
|
135 |
if (monitor != null && monitor.isCanceled()){ |
|
136 |
throw new CancellationException(); |
|
137 |
} |
|
138 |
} |
|
132 | 139 |
} |
Also available in: Unified diff
Merged latest trunk updates to branch