Revision eeedb131
Added by Cherian Mathew over 8 years ago
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/monitor/IRemotingProgressMonitor.java | ||
---|---|---|
9 | 9 |
*/ |
10 | 10 |
package eu.etaxonomy.cdm.common.monitor; |
11 | 11 |
|
12 |
import java.io.Serializable; |
|
12 | 13 |
import java.util.List; |
13 | 14 |
|
14 | 15 |
/** |
... | ... | |
31 | 32 |
* Sets the result of the monitored job |
32 | 33 |
* @param result of the monitored job |
33 | 34 |
*/ |
34 |
public void setResult(Object result);
|
|
35 |
public void setResult(Serializable result);
|
|
35 | 36 |
|
36 | 37 |
/** |
37 | 38 |
* Returns the reports generated by the monitored job |
... | ... | |
57 | 58 |
*/ |
58 | 59 |
public void setOwner(String owner); |
59 | 60 |
|
60 |
public void setFeedback(Object feedback); |
|
61 |
/** |
|
62 |
* Sets the feedback object the monitor is currently waiting for. |
|
63 |
* |
|
64 |
* @param feedback |
|
65 |
*/ |
|
66 |
public void setFeedback(Serializable feedback); |
|
67 |
|
|
68 |
/** |
|
69 |
* Returns the most recently set feedback object |
|
70 |
* |
|
71 |
* @return most recently set feedback object |
|
72 |
*/ |
|
73 |
public Serializable getFeedback(); |
|
74 |
|
|
61 | 75 |
|
76 |
/** |
|
77 |
* Boolean flag to indicate whether the monitor is |
|
78 |
* waiting for feedback |
|
79 |
* |
|
80 |
* @return true if monitor is waiting for feedback, o/w false |
|
81 |
*/ |
|
62 | 82 |
public boolean isWaitingForFeedback(); |
63 | 83 |
|
64 | 84 |
} |
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/monitor/RemotingProgressMonitor.java | ||
---|---|---|
9 | 9 |
*/ |
10 | 10 |
package eu.etaxonomy.cdm.common.monitor; |
11 | 11 |
|
12 |
import java.io.Serializable; |
|
12 | 13 |
import java.util.ArrayList; |
13 | 14 |
import java.util.List; |
14 | 15 |
|
... | ... | |
20 | 21 |
*/ |
21 | 22 |
public class RemotingProgressMonitor extends RestServiceProgressMonitor implements IRemotingProgressMonitor { |
22 | 23 |
|
23 |
private Object result;
|
|
24 |
private Serializable result;
|
|
24 | 25 |
private List<String> reports = new ArrayList<String>(); |
25 | 26 |
private String owner; |
26 |
private Object feedback; |
|
27 |
private Serializable feedback; |
|
28 |
private transient Object feedbackLock; |
|
27 | 29 |
private boolean isWaitingForFeedback = false; |
28 | 30 |
|
29 | 31 |
|
... | ... | |
40 | 42 |
* {@inheritDoc} |
41 | 43 |
*/ |
42 | 44 |
@Override |
43 |
public void setResult(Object result) {
|
|
45 |
public void setResult(Serializable result) {
|
|
44 | 46 |
this.result = result; |
45 | 47 |
} |
46 | 48 |
|
... | ... | |
63 | 65 |
} |
64 | 66 |
|
65 | 67 |
|
66 |
|
|
67 | 68 |
/** |
68 | 69 |
* {@inheritDoc} |
69 | 70 |
*/ |
... | ... | |
86 | 87 |
*/ |
87 | 88 |
@Override |
88 | 89 |
public void waitForFeedback() { |
89 |
synchronized (feedback) { |
|
90 |
if(feedbackLock == null) { |
|
91 |
feedbackLock = new Object(); |
|
92 |
} |
|
93 |
synchronized (feedbackLock) { |
|
90 | 94 |
feedback = null; |
91 | 95 |
while(feedback == null) { |
92 | 96 |
isWaitingForFeedback = true; |
93 | 97 |
try { |
94 |
feedback.wait(); |
|
98 |
feedbackLock.wait();
|
|
95 | 99 |
} catch (InterruptedException ie) { |
96 | 100 |
throw new IllegalStateException(ie); |
97 | 101 |
} |
... | ... | |
99 | 103 |
} |
100 | 104 |
} |
101 | 105 |
|
102 |
|
|
103 |
|
|
104 | 106 |
/** |
105 | 107 |
* {@inheritDoc} |
106 | 108 |
*/ |
107 | 109 |
@Override |
108 |
public void setFeedback(Object feedback) {
|
|
109 |
synchronized (feedback) { |
|
110 |
public void setFeedback(Serializable feedback) {
|
|
111 |
synchronized (feedbackLock) {
|
|
110 | 112 |
this.feedback = feedback; |
111 |
this.feedback.notifyAll(); |
|
113 |
this.feedbackLock.notifyAll();
|
|
112 | 114 |
isWaitingForFeedback = false; |
113 |
} |
|
115 |
} |
|
116 |
} |
|
114 | 117 |
|
118 |
|
|
119 |
/** |
|
120 |
* {@inheritDoc} |
|
121 |
*/ |
|
122 |
@Override |
|
123 |
public Serializable getFeedback() { |
|
124 |
return feedback; |
|
115 | 125 |
} |
116 | 126 |
|
117 | 127 |
/** |
... | ... | |
122 | 132 |
return isWaitingForFeedback; |
123 | 133 |
} |
124 | 134 |
|
125 |
|
|
126 | 135 |
} |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/service/IOServiceImpl.java | ||
---|---|---|
12 | 12 |
import java.io.ByteArrayInputStream; |
13 | 13 |
import java.io.FileOutputStream; |
14 | 14 |
import java.io.IOException; |
15 |
import java.io.Serializable; |
|
15 | 16 |
import java.nio.file.Files; |
16 | 17 |
import java.nio.file.Path; |
17 | 18 |
import java.util.UUID; |
... | ... | |
71 | 72 |
final IRemotingProgressMonitor monitor = new RemotingProgressMonitor(); |
72 | 73 |
RemotingProgressMonitorThread monitThread = new RemotingProgressMonitorThread(monitor) { |
73 | 74 |
@Override |
74 |
public Object doRun(IRemotingProgressMonitor monitor) {
|
|
75 |
public Serializable doRun(IRemotingProgressMonitor monitor) {
|
|
75 | 76 |
configurator.setProgressMonitor(monitor); |
76 | 77 |
ImportResult result = importData(configurator, importData, type); |
77 | 78 |
for(byte[] report : result.getReports()) { |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IProgressMonitorService.java | ||
---|---|---|
9 | 9 |
*/ |
10 | 10 |
package eu.etaxonomy.cdm.api.service; |
11 | 11 |
|
12 |
import java.io.Serializable; |
|
12 | 13 |
import java.util.UUID; |
13 | 14 |
|
14 | 15 |
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor; |
... | ... | |
63 | 64 |
*/ |
64 | 65 |
public boolean isMonitorThreadRunning(UUID uuid); |
65 | 66 |
|
67 |
public void setFeedback(UUID uuid, Serializable feedback); |
|
68 |
|
|
66 | 69 |
} |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/ITestService.java | ||
---|---|---|
9 | 9 |
*/ |
10 | 10 |
package eu.etaxonomy.cdm.api.service; |
11 | 11 |
|
12 |
import java.util.List; |
|
12 | 13 |
import java.util.UUID; |
13 | 14 |
|
14 | 15 |
import eu.etaxonomy.cdm.api.service.dto.CdmEntityIdentifier; |
... | ... | |
38 | 39 |
* @param monitor |
39 | 40 |
* @return |
40 | 41 |
*/ |
41 |
public String longRunningMethod(IRemotingProgressMonitor monitor, RuntimeException ex); |
|
42 |
public String longRunningMethod(IRemotingProgressMonitor monitor, RuntimeException ex, List<String> feedbacks);
|
|
42 | 43 |
|
43 | 44 |
|
44 | 45 |
/** |
45 | 46 |
* @return |
46 | 47 |
*/ |
47 |
public UUID monitLongRunningMethod(RuntimeException ex); |
|
48 |
public UUID monitLongRunningMethod(RuntimeException ex, List<String> feedbacks);
|
|
48 | 49 |
|
49 | 50 |
|
50 | 51 |
|
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/ProgressMonitorServiceImpl.java | ||
---|---|---|
9 | 9 |
*/ |
10 | 10 |
package eu.etaxonomy.cdm.api.service; |
11 | 11 |
|
12 |
import java.io.Serializable; |
|
12 | 13 |
import java.util.UUID; |
13 | 14 |
|
14 | 15 |
import org.springframework.beans.factory.annotation.Autowired; |
... | ... | |
100 | 101 |
} |
101 | 102 |
} |
102 | 103 |
|
104 |
/** |
|
105 |
* {@inheritDoc} |
|
106 |
*/ |
|
107 |
@Override |
|
108 |
public void setFeedback(UUID uuid, Serializable feedback) { |
|
109 |
IRemotingProgressMonitor remotingMonitor = getRemotingMonitor(uuid); |
|
110 |
if(remotingMonitor != null) { |
|
111 |
remotingMonitor.setFeedback(feedback); |
|
112 |
} |
|
113 |
} |
|
114 |
|
|
115 |
|
|
116 |
|
|
103 | 117 |
} |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TestServiceImpl.java | ||
---|---|---|
9 | 9 |
*/ |
10 | 10 |
package eu.etaxonomy.cdm.api.service; |
11 | 11 |
|
12 |
import java.io.Serializable; |
|
13 |
import java.util.List; |
|
12 | 14 |
import java.util.UUID; |
13 | 15 |
|
16 |
import org.apache.log4j.Logger; |
|
14 | 17 |
import org.springframework.beans.factory.annotation.Autowired; |
15 | 18 |
import org.springframework.security.access.prepost.PreAuthorize; |
16 | 19 |
import org.springframework.stereotype.Service; |
... | ... | |
32 | 35 |
@Service |
33 | 36 |
public class TestServiceImpl implements ITestService { |
34 | 37 |
|
38 |
private static final Logger logger = Logger.getLogger(TestServiceImpl.class); |
|
39 |
|
|
35 | 40 |
@Autowired |
36 | 41 |
ITaxonNodeService taxonNodeService; |
37 | 42 |
|
... | ... | |
79 | 84 |
|
80 | 85 |
|
81 | 86 |
@Override |
82 |
public UUID monitLongRunningMethod(final RuntimeException ex) { |
|
87 |
public UUID monitLongRunningMethod(final RuntimeException ex, final List<String> feedbacks) {
|
|
83 | 88 |
RemotingProgressMonitor monitor = new RemotingProgressMonitor(); |
84 | 89 |
RemotingProgressMonitorThread monitThread = new RemotingProgressMonitorThread(monitor) { |
85 | 90 |
@Override |
86 |
public Object doRun(IRemotingProgressMonitor monitor) {
|
|
87 |
Object result = longRunningMethod(monitor, ex);
|
|
91 |
public Serializable doRun(IRemotingProgressMonitor monitor) {
|
|
92 |
Serializable result = longRunningMethod(monitor, ex, feedbacks);
|
|
88 | 93 |
if(!monitor.isCanceled()) { |
89 | 94 |
monitor.addReport("Report"); |
90 | 95 |
} |
... | ... | |
99 | 104 |
} |
100 | 105 |
|
101 | 106 |
@Override |
102 |
public String longRunningMethod(IRemotingProgressMonitor monitor, RuntimeException ex) { |
|
107 |
public String longRunningMethod(IRemotingProgressMonitor monitor, RuntimeException ex, List<String> feedbacks) {
|
|
103 | 108 |
int noOfSteps = 10; |
104 | 109 |
int stepToThrowException = noOfSteps / 2; |
110 |
int stepToWaitForFeedback = noOfSteps / 2; |
|
105 | 111 |
monitor.beginTask("Long Running Task", noOfSteps); |
106 | 112 |
for(int i=0; i<noOfSteps; i++) { |
107 | 113 |
try { |
... | ... | |
109 | 115 |
if(i == stepToThrowException && ex != null) { |
110 | 116 |
throw ex; |
111 | 117 |
} |
118 |
if(feedbacks != null && feedbacks.size() > 0 && i == stepToWaitForFeedback) { |
|
119 |
for(String feedback : feedbacks) { |
|
120 |
logger.warn("Monitor waiting for feedback"); |
|
121 |
monitor.waitForFeedback(); |
|
122 |
logger.warn(" .. feedback received : " + monitor.getFeedback()); |
|
123 |
monitor.addReport(feedback); |
|
124 |
} |
|
125 |
} |
|
112 | 126 |
if(monitor.isCanceled()) { |
113 | 127 |
return "Cancelled"; |
114 | 128 |
} |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/util/RemotingProgressMonitorThread.java | ||
---|---|---|
9 | 9 |
*/ |
10 | 10 |
package eu.etaxonomy.cdm.api.service.util; |
11 | 11 |
|
12 |
import java.io.Serializable; |
|
12 | 13 |
import java.util.concurrent.ConcurrentHashMap; |
13 | 14 |
|
14 | 15 |
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor; |
... | ... | |
68 | 69 |
* @param monitor to be updated by the monitored job |
69 | 70 |
* @return result object |
70 | 71 |
*/ |
71 |
public abstract Object doRun(IRemotingProgressMonitor monitor);
|
|
72 |
public abstract Serializable doRun(IRemotingProgressMonitor monitor);
|
|
72 | 73 |
|
73 | 74 |
/** |
74 | 75 |
* Returns a currently running monitor thread corresponding to the |
Also available in: Unified diff
#5297 Make result, feedback objects in remoting monitor serializable, Update test service with monitor feedback