Revision cc7c531b
Added by Cherian Mathew about 8 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/CdmProgressMonitorAdapter.java | ||
---|---|---|
3 | 3 |
*/ |
4 | 4 |
package eu.etaxonomy.taxeditor.model; |
5 | 5 |
|
6 |
import java.io.Serializable; |
|
7 |
|
|
6 | 8 |
import org.eclipse.core.runtime.IProgressMonitor; |
7 | 9 |
import org.eclipse.core.runtime.NullProgressMonitor; |
8 | 10 |
|
... | ... | |
108 | 110 |
progressMonitor.internalWorked(arg0); |
109 | 111 |
} |
110 | 112 |
|
113 |
/** |
|
114 |
* {@inheritDoc} |
|
115 |
*/ |
|
116 |
@Override |
|
117 |
public Serializable getFeedback() { |
|
118 |
return null; |
|
119 |
} |
|
120 |
|
|
121 |
/** |
|
122 |
* {@inheritDoc} |
|
123 |
*/ |
|
124 |
@Override |
|
125 |
public boolean getIsWaitingForFeedback() { |
|
126 |
return false; |
|
127 |
} |
|
128 |
|
|
129 |
/** |
|
130 |
* {@inheritDoc} |
|
131 |
*/ |
|
132 |
@Override |
|
133 |
public void setFeedback(Serializable arg0) { |
|
134 |
|
|
135 |
} |
|
136 |
|
|
111 | 137 |
/** |
112 | 138 |
* {@inheritDoc} |
113 | 139 |
*/ |
114 | 140 |
@Override |
115 | 141 |
public void waitForFeedback() { |
116 |
// TODO Auto-generated method stub |
|
117 | 142 |
|
118 | 143 |
} |
144 |
|
|
145 |
/** |
|
146 |
* {@inheritDoc} |
|
147 |
*/ |
|
148 |
@Override |
|
149 |
public String getOwner() { |
|
150 |
return null; |
|
151 |
} |
|
152 |
|
|
153 |
/** |
|
154 |
* {@inheritDoc} |
|
155 |
*/ |
|
156 |
@Override |
|
157 |
public boolean hasFeedbackWaitTimedOut() { |
|
158 |
return false; |
|
159 |
} |
|
160 |
|
|
161 |
/** |
|
162 |
* {@inheritDoc} |
|
163 |
*/ |
|
164 |
@Override |
|
165 |
public void interrupt() { |
|
166 |
|
|
167 |
|
|
168 |
} |
|
169 |
|
|
170 |
/** |
|
171 |
* {@inheritDoc} |
|
172 |
*/ |
|
173 |
@Override |
|
174 |
public void setOwner(String arg0) { |
|
175 |
|
|
176 |
|
|
177 |
} |
|
178 |
|
|
179 |
/** |
|
180 |
* {@inheritDoc} |
|
181 |
*/ |
|
182 |
@Override |
|
183 |
public void waitForFeedback(long arg0) { |
|
184 |
|
|
185 |
} |
|
186 |
|
|
119 | 187 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/operation/FeedbackGenerator.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2015 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
package eu.etaxonomy.taxeditor.operation; |
|
11 |
|
|
12 |
import java.io.Serializable; |
|
13 |
import java.util.UUID; |
|
14 |
|
|
15 |
import org.eclipse.swt.widgets.Display; |
|
16 |
|
|
17 |
import eu.etaxonomy.cdm.api.application.CdmApplicationState; |
|
18 |
|
|
19 |
/** |
|
20 |
* Default implementation of the {@link IFeedbackGenerator} interface. |
|
21 |
* |
|
22 |
* @author cmathew |
|
23 |
* @date 29 Oct 2015 |
|
24 |
* |
|
25 |
*/ |
|
26 |
public abstract class FeedbackGenerator implements IFeedbackGenerator { |
|
27 |
|
|
28 |
|
|
29 |
/** |
|
30 |
* Generates feedback for a waiting remoting progress monitor |
|
31 |
* |
|
32 |
* @return feedback object |
|
33 |
*/ |
|
34 |
public abstract Serializable generateFeedback(); |
|
35 |
|
|
36 |
/** |
|
37 |
* {@inheritDoc} |
|
38 |
*/ |
|
39 |
@Override |
|
40 |
public void setFeedbackForMonitor(final UUID uuid) { |
|
41 |
Display.getDefault().syncExec(new Runnable() { |
|
42 |
@Override |
|
43 |
public void run() { |
|
44 |
CdmApplicationState.getCurrentAppConfig().getProgressMonitorService().setFeedback(uuid, generateFeedback()); |
|
45 |
} |
|
46 |
}); |
|
47 |
} |
|
48 |
|
|
49 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/operation/IFeedbackGenerator.java | ||
---|---|---|
9 | 9 |
*/ |
10 | 10 |
package eu.etaxonomy.taxeditor.operation; |
11 | 11 |
|
12 |
import java.io.Serializable;
|
|
12 |
import java.util.UUID;
|
|
13 | 13 |
|
14 | 14 |
/** |
15 |
* Generates feeback for waiting remoting progress monitors. |
|
16 |
* The default implementation of this interface is {@link FeedbackGenerator} |
|
17 |
* |
|
15 | 18 |
* @author cmathew |
16 | 19 |
* @date 28 Oct 2015 |
17 | 20 |
* |
18 | 21 |
*/ |
19 | 22 |
public interface IFeedbackGenerator { |
20 | 23 |
|
21 |
public Serializable generateFeedback(); |
|
24 |
/** |
|
25 |
* Generates and sets feedback for a waiting remoting progress |
|
26 |
* monitor corresponding to the given uuid. |
|
27 |
* |
|
28 |
* @param uuid of target waiting remoting progress monitor |
|
29 |
*/ |
|
30 |
public void setFeedbackForMonitor(UUID uuid); |
|
22 | 31 |
|
23 | 32 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/FeedbackMessageBox.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2015 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
package eu.etaxonomy.taxeditor.ui.dialog; |
|
11 |
|
|
12 |
import java.io.Serializable; |
|
13 |
|
|
14 |
import org.eclipse.swt.SWT; |
|
15 |
import org.eclipse.swt.widgets.MessageBox; |
|
16 |
import org.eclipse.swt.widgets.Shell; |
|
17 |
|
|
18 |
import eu.etaxonomy.taxeditor.operation.FeedbackGenerator; |
|
19 |
|
|
20 |
/** |
|
21 |
* Feedback Generator corresponding to a {@link MessageBox} |
|
22 |
* |
|
23 |
* @author cmathew |
|
24 |
* @date 29 Oct 2015 |
|
25 |
* |
|
26 |
*/ |
|
27 |
public class FeedbackMessageBox extends FeedbackGenerator { |
|
28 |
|
|
29 |
private Shell shell; |
|
30 |
/** |
|
31 |
* @param parent |
|
32 |
*/ |
|
33 |
public FeedbackMessageBox(Shell parent) { |
|
34 |
this.shell = parent; |
|
35 |
} |
|
36 |
|
|
37 |
/** |
|
38 |
* {@inheritDoc} |
|
39 |
*/ |
|
40 |
@Override |
|
41 |
public Serializable generateFeedback() { |
|
42 |
|
|
43 |
// create a dialog with ok and cancel buttons and a question icon |
|
44 |
MessageBox dialog = |
|
45 |
new MessageBox(shell, SWT.ICON_QUESTION | SWT.OK| SWT.CANCEL); |
|
46 |
dialog.setText("Monitor Feedback"); |
|
47 |
dialog.setMessage("Do you really want to continue?"); |
|
48 |
|
|
49 |
// open dialog and await user selection |
|
50 |
return dialog.open(); |
|
51 |
} |
|
52 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/util/ProgressMonitorClientManager.java | ||
---|---|---|
113 | 113 |
Thread.sleep(pollInterval); |
114 | 114 |
remotingMonitor = progressMonitorService.getRemotingMonitor(uuid); |
115 | 115 |
// check if remoting monitor is waiting for feedback |
116 |
if(remotingMonitor.isWaitingForFeedback()) {
|
|
116 |
if(remotingMonitor.getIsWaitingForFeedback()) {
|
|
117 | 117 |
if(feedbackGenerators != null) { |
118 | 118 |
// if we have run out of feedback generators while |
119 | 119 |
// the remoting monitor is waiting on feedback |
... | ... | |
121 | 121 |
if(feedbackCount + 1 > feedbackGenerators.size()) { |
122 | 122 |
throw new IllegalStateException("Remoting monitor waiting on feedback that does not exist"); |
123 | 123 |
} |
124 |
progressMonitorService.setFeedback(uuid, feedbackGenerators.get(feedbackCount).generateFeedback());
|
|
124 |
feedbackGenerators.get(feedbackCount).setFeedbackForMonitor(uuid);
|
|
125 | 125 |
feedbackCount++; |
126 | 126 |
} |
127 | 127 |
} |
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/service/ProgressMonitorServiceTest.java | ||
---|---|---|
9 | 9 |
*/ |
10 | 10 |
package eu.etaxonomy.taxeditor.service; |
11 | 11 |
|
12 |
import java.io.Serializable; |
|
13 | 12 |
import java.util.ArrayList; |
14 | 13 |
import java.util.Arrays; |
15 | 14 |
import java.util.List; |
... | ... | |
21 | 20 |
import org.junit.Assert; |
22 | 21 |
import org.junit.Test; |
23 | 22 |
|
23 |
import eu.etaxonomy.cdm.api.application.CdmApplicationState; |
|
24 | 24 |
import eu.etaxonomy.cdm.api.service.IProgressMonitorService; |
25 | 25 |
import eu.etaxonomy.cdm.api.service.ITestService; |
26 | 26 |
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor; |
... | ... | |
52 | 52 |
|
53 | 53 |
@Test |
54 | 54 |
public void testMonitLongRunningMethod() throws InterruptedException { |
55 |
UUID uuid = testService.monitLongRunningMethod(null, null); |
|
55 |
UUID uuid = testService.monitLongRunningMethod(null, null, 0);
|
|
56 | 56 |
int pollInterval = 1000; |
57 | 57 |
RemotingProgressMonitor expectedMonitor = new RemotingProgressMonitor(); |
58 | 58 |
expectedMonitor.setResult("Success"); |
... | ... | |
70 | 70 |
public void testMonitLongRunningMethodByChangingUser() throws InterruptedException { |
71 | 71 |
|
72 | 72 |
IllegalStateException ise = new IllegalStateException("IllegalStateException"); |
73 |
UUID uuid = testService.monitLongRunningMethod(ise, null); |
|
73 |
UUID uuid = testService.monitLongRunningMethod(ise, null, 0);
|
|
74 | 74 |
authenticateExtraUser(); |
75 | 75 |
IRemotingProgressMonitor monitor = progressMonitorService.getRemotingMonitor(uuid); |
76 | 76 |
Assert.assertNull(monitor); |
... | ... | |
80 | 80 |
@Test |
81 | 81 |
public void testMonitLongRunningMethodWithException() throws InterruptedException { |
82 | 82 |
IllegalStateException ise = new IllegalStateException("IllegalStateException"); |
83 |
UUID uuid = testService.monitLongRunningMethod(ise, null); |
|
83 |
UUID uuid = testService.monitLongRunningMethod(ise, null, 0);
|
|
84 | 84 |
int pollInterval = 1000; |
85 | 85 |
RemotingProgressMonitor expectedMonitor = new RemotingProgressMonitor(); |
86 | 86 |
expectedMonitor.setResult(ise); |
... | ... | |
102 | 102 |
@Test |
103 | 103 |
public void testMonitLongRunningMethodWithInterrupt() { |
104 | 104 |
IllegalStateException ise = new IllegalStateException("Interrupted Exception"); |
105 |
final UUID uuid = testService.monitLongRunningMethod(ise, null); |
|
105 |
final UUID uuid = testService.monitLongRunningMethod(ise, null, 0);
|
|
106 | 106 |
final int pollInterval = 1000; |
107 | 107 |
final RemotingProgressMonitor expectedMonitor = new RemotingProgressMonitor(); |
108 | 108 |
expectedMonitor.setResult(ise); |
... | ... | |
120 | 120 |
null, |
121 | 121 |
(IFeedbackGenerator)null, |
122 | 122 |
new NullProgressMonitor()); |
123 |
Assert.fail("InterruptedException wrapped in an IllegalStateException should be thrown"); |
|
123 | 124 |
} catch (InterruptedException e) { |
124 | 125 |
|
126 |
} catch (IllegalStateException e) { |
|
127 |
|
|
125 | 128 |
} |
126 | 129 |
} |
127 | 130 |
}; |
... | ... | |
140 | 143 |
@Test |
141 | 144 |
public void testMonitLongRunningMethodWithCancellation() throws InterruptedException { |
142 | 145 |
|
143 |
final UUID uuid = testService.monitLongRunningMethod(null, null); |
|
146 |
final UUID uuid = testService.monitLongRunningMethod(null, null, 0);
|
|
144 | 147 |
final int pollInterval = 1000; |
145 | 148 |
final RemotingProgressMonitor expectedMonitor = new RemotingProgressMonitor(); |
146 | 149 |
expectedMonitor.setResult("Cancelled"); |
... | ... | |
180 | 183 |
final RemotingProgressMonitor expectedMonitor = new RemotingProgressMonitor(); |
181 | 184 |
expectedMonitor.setResult("Success"); |
182 | 185 |
for(String feedback : feedbacks) { |
183 |
feebackGenerators.add(new MockFeedbackGenerator(feedback)); |
|
186 |
feebackGenerators.add(new MockFeedbackGenerator(feedback, 0));
|
|
184 | 187 |
expectedMonitor.addReport(feedback); |
185 | 188 |
} |
186 | 189 |
expectedMonitor.addReport("Report"); |
187 | 190 |
expectedMonitor.done(); |
188 | 191 |
|
189 |
final UUID uuid = testService.monitLongRunningMethod(null, feedbacks); |
|
192 |
final UUID uuid = testService.monitLongRunningMethod(null, feedbacks, 0);
|
|
190 | 193 |
final int pollInterval = 1000; |
191 | 194 |
|
192 | 195 |
CdmStore.getProgressMonitorClientManager().pollMonitor("Testing Progress Monitor", |
... | ... | |
196 | 199 |
feebackGenerators, |
197 | 200 |
new NullProgressMonitor()); |
198 | 201 |
|
202 |
} |
|
203 |
|
|
204 |
@Test |
|
205 |
public void testMonitLongRunningMethodWithInconsistentWaitForFeedback() throws InterruptedException { |
|
206 |
|
|
207 |
List<String> feedbacks = Arrays.asList("feedback1", "feedback2"); |
|
208 |
List<IFeedbackGenerator> feebackGenerators = new ArrayList<IFeedbackGenerator>(); |
|
209 |
final RemotingProgressMonitor expectedMonitor = new RemotingProgressMonitor(); |
|
210 |
expectedMonitor.setResult("Success"); |
|
211 |
for(String feedback : feedbacks) { |
|
212 |
feebackGenerators.add(new MockFeedbackGenerator(feedback, 0)); |
|
213 |
expectedMonitor.addReport(feedback); |
|
214 |
} |
|
215 |
expectedMonitor.addReport("Report"); |
|
216 |
expectedMonitor.done(); |
|
217 |
|
|
218 |
final UUID uuid = testService.monitLongRunningMethod(null, feedbacks, 0); |
|
219 |
final int pollInterval = 1000; |
|
220 |
|
|
199 | 221 |
feebackGenerators.remove(1); |
200 | 222 |
|
201 |
final UUID newUuid = testService.monitLongRunningMethod(null, feedbacks); |
|
223 |
final UUID newUuid = testService.monitLongRunningMethod(null, feedbacks, 0);
|
|
202 | 224 |
|
203 | 225 |
try { |
204 | 226 |
CdmStore.getProgressMonitorClientManager().pollMonitor("Testing Progress Monitor", |
... | ... | |
211 | 233 |
} catch(IllegalStateException ise) { |
212 | 234 |
|
213 | 235 |
} |
236 |
} |
|
237 |
|
|
238 |
@Test |
|
239 |
public void testMonitLongRunningMethodWithWaitForFeedbackTimeout() throws InterruptedException { |
|
214 | 240 |
|
241 |
List<String> feedbacks = Arrays.asList("feedback1"); |
|
242 |
List<IFeedbackGenerator> feebackGenerators = new ArrayList<IFeedbackGenerator>(); |
|
243 |
final RemotingProgressMonitor expectedMonitor = new RemotingProgressMonitor(); |
|
244 |
expectedMonitor.setResult(new IllegalStateException(new InterruptedException())); |
|
245 |
for(String feedback : feedbacks) { |
|
246 |
feebackGenerators.add(new MockFeedbackGenerator(feedback, 1000 * 15)); |
|
215 | 247 |
|
248 |
} |
|
249 |
expectedMonitor.setCanceled(true); |
|
250 |
expectedMonitor.setIsFailed(true); |
|
251 |
expectedMonitor.done(); |
|
252 |
|
|
253 |
expectedMonitor.done(); |
|
254 |
|
|
255 |
final UUID uuid = testService.monitLongRunningMethod(null, feedbacks, 1000 * 5); |
|
256 |
final int pollInterval = 1000; |
|
257 |
|
|
258 |
|
|
259 |
try { |
|
260 |
CdmStore.getProgressMonitorClientManager().pollMonitor("Testing Progress Monitor", |
|
261 |
uuid, |
|
262 |
pollInterval, |
|
263 |
new MockPostMoniteredOperationEnabled(expectedMonitor, uuid), |
|
264 |
feebackGenerators, |
|
265 |
new NullProgressMonitor()); |
|
266 |
Assert.fail("Exception due to inconsistent number of feedback generators not thrown"); |
|
267 |
} catch(IllegalStateException ise) { |
|
268 |
|
|
269 |
} |
|
216 | 270 |
} |
217 | 271 |
|
218 | 272 |
|
... | ... | |
249 | 303 |
class MockFeedbackGenerator implements IFeedbackGenerator { |
250 | 304 |
|
251 | 305 |
private String feedback; |
306 |
private long waitTime; |
|
252 | 307 |
|
253 |
public MockFeedbackGenerator(String feedback) { |
|
308 |
public MockFeedbackGenerator(String feedback, long waitTime) {
|
|
254 | 309 |
this.feedback = feedback; |
310 |
this.waitTime = waitTime; |
|
255 | 311 |
} |
312 |
|
|
256 | 313 |
/** |
257 | 314 |
* {@inheritDoc} |
258 | 315 |
*/ |
259 | 316 |
@Override |
260 |
public Serializable generateFeedback() { |
|
261 |
return feedback; |
|
317 |
public void setFeedbackForMonitor(UUID uuid) { |
|
318 |
if(waitTime > 0) { |
|
319 |
try { |
|
320 |
Thread.sleep(waitTime); |
|
321 |
} catch (InterruptedException e) { |
|
322 |
e.printStackTrace(); |
|
323 |
} |
|
324 |
} |
|
325 |
CdmApplicationState.getCurrentAppConfig().getProgressMonitorService().setFeedback(uuid, feedback); |
|
262 | 326 |
} |
263 | 327 |
|
264 | 328 |
} |
Also available in: Unified diff
#5297 Implement client side remoting progress monitor feedback mechanism, Add test for monitor feedback timeout
#5297 Add test for monitor feedback timeout