|
|
|
@ -10,117 +10,104 @@ import com.allen_sauer.gwt.log.client.Log;
|
|
|
|
|
import com.google.gwt.user.client.Timer;
|
|
|
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @author "Giancarlo Panichi"
|
|
|
|
|
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
|
|
|
|
* @author Giancarlo Panichi
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public class MonitorUpdater extends Timer implements MonitorDialogEventUIListener {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ArrayList<MonitorUpdaterListener> listeners = new ArrayList<MonitorUpdaterListener>();
|
|
|
|
|
private OperationMonitorSession operationMonitorSession;
|
|
|
|
|
|
|
|
|
|
public MonitorUpdater(OperationMonitorSession operationMonitorSession){
|
|
|
|
|
this.operationMonitorSession=operationMonitorSession;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public MonitorUpdater(OperationMonitorSession operationMonitorSession) {
|
|
|
|
|
this.operationMonitorSession = operationMonitorSession;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* {@inheritDoc}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
Log.debug("requesting operation progress");
|
|
|
|
|
TDGWTServiceAsync.INSTANCE
|
|
|
|
|
.getOperationMonitor(operationMonitorSession,new AsyncCallback<OperationMonitor>() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
|
cancel();
|
|
|
|
|
|
|
|
|
|
Log.error("Error retrieving the operation state",
|
|
|
|
|
caught);
|
|
|
|
|
String message = getStack(caught);
|
|
|
|
|
fireMonitorFailed(caught,
|
|
|
|
|
"Failed getting operation updates", message, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onSuccess(OperationMonitor result) {
|
|
|
|
|
Log.debug("retrieved OperationMonitor: "
|
|
|
|
|
+ result);
|
|
|
|
|
|
|
|
|
|
if(result==null){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(result.isInBackground()){
|
|
|
|
|
Log.debug("Operation is in background");
|
|
|
|
|
cancel();
|
|
|
|
|
fireMonitorPutInBackground();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(result.isAbort()){
|
|
|
|
|
Log.debug("Operation is aborted");
|
|
|
|
|
cancel();
|
|
|
|
|
fireMonitorAborted();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(result.getTask()==null|| result.getTask().getState()==null){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (result.getTask().getState()) {
|
|
|
|
|
case INITIALIZING:
|
|
|
|
|
Log.info("Initializing...");
|
|
|
|
|
fireMonitorInitializing(result);
|
|
|
|
|
break;
|
|
|
|
|
case ABORTED:
|
|
|
|
|
cancel();
|
|
|
|
|
fireMonitorAborted();
|
|
|
|
|
Log.info("Aborted");
|
|
|
|
|
break;
|
|
|
|
|
case IN_PROGRESS:
|
|
|
|
|
fireMonitorUpdate(result);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case VALIDATING_RULES:
|
|
|
|
|
fireMonitorValidate(result);
|
|
|
|
|
break;
|
|
|
|
|
case GENERATING_VIEW:
|
|
|
|
|
Log.info("Generating View...");
|
|
|
|
|
fireMonitorGeneratingView(result);
|
|
|
|
|
break;
|
|
|
|
|
case STOPPED:
|
|
|
|
|
cancel();
|
|
|
|
|
stopMessage(result);
|
|
|
|
|
break;
|
|
|
|
|
case FAILED:
|
|
|
|
|
cancel();
|
|
|
|
|
errorMessage(result);
|
|
|
|
|
break;
|
|
|
|
|
case SUCCEDED:
|
|
|
|
|
cancel();
|
|
|
|
|
Log.info("Fisnish :"
|
|
|
|
|
+ result.getTrId());
|
|
|
|
|
fireMonitorComplete(result);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
Log.info("Unknow State");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TDGWTServiceAsync.INSTANCE.getOperationMonitor(operationMonitorSession, new AsyncCallback<OperationMonitor>() {
|
|
|
|
|
|
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
|
cancel();
|
|
|
|
|
|
|
|
|
|
Log.error("Error retrieving the operation state", caught);
|
|
|
|
|
String message = getStack(caught);
|
|
|
|
|
fireMonitorFailed(caught, "Failed getting operation updates", message, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onSuccess(OperationMonitor result) {
|
|
|
|
|
Log.debug("retrieved OperationMonitor: " + result);
|
|
|
|
|
|
|
|
|
|
if (result == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (result.isInBackground()) {
|
|
|
|
|
Log.debug("Operation is in background");
|
|
|
|
|
cancel();
|
|
|
|
|
fireMonitorPutInBackground();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.isAbort()) {
|
|
|
|
|
Log.debug("Operation is aborted");
|
|
|
|
|
cancel();
|
|
|
|
|
fireMonitorAborted();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.getTask() == null || result.getTask().getState() == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (result.getTask().getState()) {
|
|
|
|
|
case INITIALIZING:
|
|
|
|
|
Log.info("Initializing...");
|
|
|
|
|
fireMonitorInitializing(result);
|
|
|
|
|
break;
|
|
|
|
|
case ABORTED:
|
|
|
|
|
cancel();
|
|
|
|
|
fireMonitorAborted();
|
|
|
|
|
Log.info("Aborted");
|
|
|
|
|
break;
|
|
|
|
|
case IN_PROGRESS:
|
|
|
|
|
fireMonitorUpdate(result);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case VALIDATING_RULES:
|
|
|
|
|
fireMonitorValidate(result);
|
|
|
|
|
break;
|
|
|
|
|
case GENERATING_VIEW:
|
|
|
|
|
Log.info("Generating View...");
|
|
|
|
|
fireMonitorGeneratingView(result);
|
|
|
|
|
break;
|
|
|
|
|
case STOPPED:
|
|
|
|
|
cancel();
|
|
|
|
|
stopMessage(result);
|
|
|
|
|
break;
|
|
|
|
|
case FAILED:
|
|
|
|
|
cancel();
|
|
|
|
|
errorMessage(result);
|
|
|
|
|
break;
|
|
|
|
|
case SUCCEDED:
|
|
|
|
|
cancel();
|
|
|
|
|
Log.info("Fisnish :" + result.getTrId());
|
|
|
|
|
fireMonitorComplete(result);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
Log.info("Unknow State");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void errorMessage(OperationMonitor result) {
|
|
|
|
|
Log.info("Operation Failed");
|
|
|
|
|
Throwable th;
|
|
|
|
@ -135,25 +122,24 @@ public class MonitorUpdater extends Timer implements MonitorDialogEventUIListene
|
|
|
|
|
reason = "Error on Service";
|
|
|
|
|
details = "Operation failed";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fireMonitorFailed(th, reason, details,result);
|
|
|
|
|
|
|
|
|
|
fireMonitorFailed(th, reason, details, result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void stopMessage(OperationMonitor result) {
|
|
|
|
|
Log.info("Operation Stopped");
|
|
|
|
|
String reason = null;
|
|
|
|
|
String details = null;
|
|
|
|
|
if (result.getTask().getErrorCause() != null) {
|
|
|
|
|
if (result.getTask().getErrorCause() != null) {
|
|
|
|
|
reason = "Validations failed";
|
|
|
|
|
details = result.getTask().getErrorCause().getLocalizedMessage();
|
|
|
|
|
} else {
|
|
|
|
|
reason = "Validations failed";
|
|
|
|
|
details = "Operation stopped";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fireMonitorStopped(reason, details,result);
|
|
|
|
|
|
|
|
|
|
fireMonitorStopped(reason, details, result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected String getStack(Throwable e) {
|
|
|
|
|
String message = e.getLocalizedMessage() + " -> <br>";
|
|
|
|
@ -167,7 +153,7 @@ public class MonitorUpdater extends Timer implements MonitorDialogEventUIListene
|
|
|
|
|
for (MonitorUpdaterListener listener : listeners)
|
|
|
|
|
listener.monitorInitializing(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void fireMonitorGeneratingView(OperationMonitor result) {
|
|
|
|
|
for (MonitorUpdaterListener listener : listeners)
|
|
|
|
|
listener.monitorGeneratingView(result);
|
|
|
|
@ -177,7 +163,7 @@ public class MonitorUpdater extends Timer implements MonitorDialogEventUIListene
|
|
|
|
|
for (MonitorUpdaterListener listener : listeners)
|
|
|
|
|
listener.monitorUpdate(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void fireMonitorValidate(OperationMonitor result) {
|
|
|
|
|
for (MonitorUpdaterListener listener : listeners)
|
|
|
|
|
listener.monitorValidate(result);
|
|
|
|
@ -188,8 +174,8 @@ public class MonitorUpdater extends Timer implements MonitorDialogEventUIListene
|
|
|
|
|
listener.monitorComplete(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void fireMonitorFailed(Throwable caught, String failure,
|
|
|
|
|
String failureDetails, OperationMonitor operationMonitor) {
|
|
|
|
|
protected void fireMonitorFailed(Throwable caught, String failure, String failureDetails,
|
|
|
|
|
OperationMonitor operationMonitor) {
|
|
|
|
|
for (MonitorUpdaterListener listener : listeners)
|
|
|
|
|
listener.monitorFailed(caught, failure, failureDetails, operationMonitor);
|
|
|
|
|
}
|
|
|
|
@ -198,21 +184,19 @@ public class MonitorUpdater extends Timer implements MonitorDialogEventUIListene
|
|
|
|
|
for (MonitorUpdaterListener listener : listeners)
|
|
|
|
|
listener.monitorStopped(reason, details, operationMonitor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void fireMonitorAborted() {
|
|
|
|
|
for (MonitorUpdaterListener listener : listeners)
|
|
|
|
|
listener.monitorAborted();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void fireMonitorPutInBackground() {
|
|
|
|
|
for (MonitorUpdaterListener listener : listeners)
|
|
|
|
|
listener.monitorPutInBackground();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a new {@link MonitorUpdaterListener} to this
|
|
|
|
|
* {@link AddColumnProgressUpdater}.
|
|
|
|
|
* Add a new MonitorUpdaterListener to this
|
|
|
|
|
*
|
|
|
|
|
* @param listener
|
|
|
|
|
* the listener to add.
|
|
|
|
@ -222,8 +206,8 @@ public class MonitorUpdater extends Timer implements MonitorDialogEventUIListene
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Removes the specified {@link MonitorUpdaterListener} from this
|
|
|
|
|
* {@link AddColumnProgressUpdater}.
|
|
|
|
|
* Removes the specified MonitorUpdaterListener from this
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param listener
|
|
|
|
|
* the listener to remove.
|
|
|
|
@ -232,19 +216,15 @@ public class MonitorUpdater extends Timer implements MonitorDialogEventUIListene
|
|
|
|
|
listeners.remove(listener);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void requestAborted() {
|
|
|
|
|
operationMonitorSession.setAbort(true);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void requestPutInBackground() {
|
|
|
|
|
operationMonitorSession.setInBackground(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|