tabular-data-monitor-widget/src/main/java/org/gcube/portlets/user/td/monitorwidget/client/background/MonitorBackgroundUpdater.java

115 lines
2.9 KiB
Java

package org.gcube.portlets.user.td.monitorwidget.client.background;
import java.util.ArrayList;
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
import org.gcube.portlets.user.td.gwtservice.shared.monitor.BackgroundOperationMonitorSession;
import org.gcube.portlets.user.td.gwtservice.shared.monitor.OperationMonitor;
import org.gcube.portlets.user.td.gwtservice.shared.monitor.OperationMonitorSession;
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>
*
*/
public class MonitorBackgroundUpdater extends Timer implements MonitorBackgroundEventUIListener {
protected ArrayList<MonitorBackgroundUpdaterListener> listeners = new ArrayList<MonitorBackgroundUpdaterListener>();
protected BackgroundOperationMonitorSession backgroundOperationMonitorSession;
public MonitorBackgroundUpdater(){
backgroundOperationMonitorSession=new BackgroundOperationMonitorSession();
}
/**
* {@inheritDoc}
*/
@Override
public void run() {
Log.debug("requesting list of operation in background ");
TDGWTServiceAsync.INSTANCE
.getBackgroundOperationMonitor(backgroundOperationMonitorSession, new AsyncCallback<ArrayList<OperationMonitor>>() {
public void onFailure(Throwable caught) {
cancel();
Log.error("Error retrieving operation monitor list",
caught);
fireRetrieveOperationMonitorListFailed(caught);
}
public void onSuccess(ArrayList<OperationMonitor> result) {
Log.debug("retrieved Operation Monitor List: "
+ result.size());
fireOperationMonitorListUpdated(result);
}
});
}
protected void fireOperationMonitorListUpdated(ArrayList<OperationMonitor> operationMonitorList){
for (MonitorBackgroundUpdaterListener listener : listeners)
listener.operationMonitorListUpdated(operationMonitorList);
}
protected void fireRetrieveOperationMonitorListFailed(Throwable throwable){
for (MonitorBackgroundUpdaterListener listener : listeners)
listener.retrieveOperationMonitorListFailed(throwable);
}
/**
*
*
* @param listener
*/
public void addListener(MonitorBackgroundUpdaterListener listener) {
listeners.add(listener);
}
/**
*
* @param listener
*/
public void removeListener(MonitorBackgroundUpdaterListener listener) {
listeners.remove(listener);
}
@Override
public void requestAborted(String taskId) {
OperationMonitorSession operationMonitorSession=new OperationMonitorSession(taskId);
operationMonitorSession.setAbort(true);
backgroundOperationMonitorSession.addToOperationMonitorSessionList(operationMonitorSession);
}
@Override
public void requestResume(String taskId) {
// TODO Auto-generated method stub
}
}