-// $Id$
/**
* Copyright (C) 2015 EDIT
* European Distributed Institute of Taxonomy
import java.util.UUID;
import org.apache.log4j.Logger;
-import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
import eu.etaxonomy.cdm.api.service.IProgressMonitorService;
+import eu.etaxonomy.cdm.api.service.UpdateResult;
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
import eu.etaxonomy.taxeditor.operation.IFeedbackGenerator;
import eu.etaxonomy.taxeditor.operation.IPostMoniteredOperationEnabled;
final int pollInterval,
final IPostMoniteredOperationEnabled postOp,
IFeedbackGenerator feedbackGenerator,
- IProgressMonitor monitor) throws InterruptedException {
+ SubMonitor monitor) throws InterruptedException {
return pollMonitor(label, uuid, pollInterval, postOp, Arrays.asList(feedbackGenerator), monitor);
}
/**
final int pollInterval,
final IPostMoniteredOperationEnabled postOp,
List<IFeedbackGenerator> feedbackGenerators,
- IProgressMonitor monitor) throws InterruptedException {
+ SubMonitor monitor) throws InterruptedException {
IProgressMonitorService progressMonitorService = CdmApplicationState.getCurrentAppConfig().getProgressMonitorService();
IRemotingProgressMonitor remotingMonitor = progressMonitorService.getRemotingMonitor(uuid);
try {
final int START_DELAY=10;
// wait about 10 seconds for the remoting monitor to be initialised
// (i.e. for the begin task method to be called ON THE REMOTING MONITOR)
+ if ( remotingMonitor.isDone()){
+ return remotingMonitor;
+ }
for(int i=0;i<START_DELAY;i++) {
- Thread.sleep(1000);
+ Thread.sleep(10);
logger.info("Waiting for monitered work to start ..");
remotingMonitor = progressMonitorService.getRemotingMonitor(uuid);
- if(remotingMonitor.getTotalWork() > 0) {
+ if (remotingMonitor != null){
+ if(remotingMonitor.getTotalWork() > 0) {
+ break;
+ }
break;
}
}
+
+ if (remotingMonitor == null){
+ return null;
+ }
// if the total work is still not been set then we assume that the
// operation has zero work units
- if(remotingMonitor.getTotalWork() == 0) {
- throw new InterruptedException("Monitor has zero work units");
+
+ if(remotingMonitor.getTotalWork() == 0 && remotingMonitor.isDone()) {
+ return remotingMonitor;
+
+ }else if (remotingMonitor.getTotalWork() == 0 ){
+ Object result = remotingMonitor.getResult();
+ InterruptedException exception = new InterruptedException("Monitor has zero work units");
+ if (result instanceof UpdateResult){
+ ((UpdateResult)result).addException(exception);
+ }else if (result == null){
+ result = new UpdateResult();
+ }
+
}
// start the client monitor
- monitor.beginTask(label, remotingMonitor.getTotalWork());
+ // monitor.subTask(remotingMonitor.getTaskName());
+ monitor.beginTask(remotingMonitor.getTaskName(), remotingMonitor.getTotalWork());
logger.info("Work to be done: " + remotingMonitor.getTotalWork());
int editorTotalWorkDone = 0;
int serverTotalWorkDone = 0;
// the remoting monitor is waiting on feedback
// then throw exception
if(feedbackCount + 1 > feedbackGenerators.size()) {
- throw new IllegalStateException("Remoting monitor waiting on feedback that does not exist");
+ IllegalStateException exception = new IllegalStateException("Remoting monitor waiting on feedback that does not exist");
+ Object result = remotingMonitor.getResult();
+ if (result instanceof UpdateResult){
+ ((UpdateResult)result).addException(exception);
+ }
+ return remotingMonitor;
}
feedbackGenerators.get(feedbackCount).setFeedbackForMonitor(uuid);
feedbackCount++;
}
serverTotalWorkDone = (int) remotingMonitor.getWorkDone();
logger.info("Work done from start: " + serverTotalWorkDone);
- String percentage = new DecimalFormat("#.##").format(remotingMonitor.getPercentage());
+ String percentage = "100";
+ if (remotingMonitor.getTotalWork() != 0){
+ percentage = new DecimalFormat("#.##").format(remotingMonitor.getPercentage());
+ }
+
+
// set dialog text
monitor.setTaskName(label + " " + percentage + "% done ");
monitor.subTask(remotingMonitor.getSubTask());
- int worked = serverTotalWorkDone - editorTotalWorkDone;
+// monitor.setWorkRemaining((int) (remotingMonitor.getTotalWork()-remotingMonitor.getWorkDone()));
+ // monitor.subTask(remotingMonitor.getSubTask(), remotingMonitor.getWorkDone());
+ int worked = 0;
+ if (serverTotalWorkDone > editorTotalWorkDone){
+ worked = serverTotalWorkDone - editorTotalWorkDone;
+ }
if(worked > 0) {
logger.info("Work done since last check: " + worked);
monitor.worked(worked);
}
+
+
editorTotalWorkDone = serverTotalWorkDone;
}
if(remotingMonitor.getResult() instanceof Exception) {
- throw new IllegalStateException((Exception)remotingMonitor.getResult());
+ UpdateResult result = new UpdateResult();
+ result.addException((Exception) remotingMonitor.getResult());
+// throw new IllegalStateException((Exception)remotingMonitor.getResult());
}
return remotingMonitor;
} finally {
- if(postOp != null && remotingMonitor.isDone()) {
+ if(postOp != null && remotingMonitor != null && remotingMonitor.isDone()) {
postOp.postOperation(remotingMonitor);
}
}