MOA 12.03
Real Time Analytics for Data Streams
StandardTaskMonitor.java
Go to the documentation of this file.
00001 /*
00002  *    StandardTaskMonitor.java
00003  *    Copyright (C) 2007 University of Waikato, Hamilton, New Zealand
00004  *    @author Richard Kirkby (rkirkby@cs.waikato.ac.nz)
00005  *
00006  *    This program is free software; you can redistribute it and/or modify
00007  *    it under the terms of the GNU General Public License as published by
00008  *    the Free Software Foundation; either version 3 of the License, or
00009  *    (at your option) any later version.
00010  *
00011  *    This program is distributed in the hope that it will be useful,
00012  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *    GNU General Public License for more details.
00015  *
00016  *    You should have received a copy of the GNU General Public License
00017  *    along with this program. If not, see <http://www.gnu.org/licenses/>.
00018  *    
00019  */
00020 package moa.tasks;
00021 
00028 public class StandardTaskMonitor implements TaskMonitor {
00029 
00030     protected String currentActivityDescription = "";
00031 
00032     protected double currentActivityFractionComplete = -1.0;
00033 
00034     protected volatile boolean cancelFlag = false;
00035 
00036     protected volatile boolean pauseFlag = false;
00037 
00038     protected volatile boolean isComplete = false;
00039 
00040     protected volatile boolean resultPreviewRequested = false;
00041 
00042     protected volatile Object latestResultPreview = null;
00043 
00044     protected volatile ResultPreviewListener resultPreviewer = null;
00045 
00046     @Override
00047     public void setCurrentActivity(String activityDescription,
00048             double fracComplete) {
00049         setCurrentActivityDescription(activityDescription);
00050         setCurrentActivityFractionComplete(fracComplete);
00051     }
00052 
00053     @Override
00054     public void setCurrentActivityDescription(String activity) {
00055         this.currentActivityDescription = activity;
00056     }
00057 
00058     @Override
00059     public void setCurrentActivityFractionComplete(double fracComplete) {
00060         this.currentActivityFractionComplete = fracComplete;
00061     }
00062 
00063     @Override
00064     public boolean taskShouldAbort() {
00065         if (this.pauseFlag) {
00066             try {
00067                 synchronized (this) {
00068                     while (this.pauseFlag && !this.cancelFlag) {
00069                         wait();
00070                     }
00071                 }
00072             } catch (InterruptedException e) {
00073             }
00074         }
00075         return this.cancelFlag;
00076     }
00077 
00078     @Override
00079     public String getCurrentActivityDescription() {
00080         return this.currentActivityDescription;
00081     }
00082 
00083     @Override
00084     public double getCurrentActivityFractionComplete() {
00085         return this.currentActivityFractionComplete;
00086     }
00087 
00088     @Override
00089     public boolean isCancelled() {
00090         return this.cancelFlag;
00091     }
00092 
00093     @Override
00094     public void requestCancel() {
00095         this.cancelFlag = true;
00096         requestResume();
00097     }
00098 
00099     @Override
00100     public void requestPause() {
00101         this.pauseFlag = true;
00102     }
00103 
00104     @Override
00105     public synchronized void requestResume() {
00106         this.pauseFlag = false;
00107         notify();
00108     }
00109 
00110     @Override
00111     public boolean isPaused() {
00112         return this.pauseFlag;
00113     }
00114 
00115     @Override
00116     public Object getLatestResultPreview() {
00117         return this.latestResultPreview;
00118     }
00119 
00120     @Override
00121     public void requestResultPreview() {
00122         this.resultPreviewRequested = true;
00123     }
00124 
00125     @Override
00126     public void requestResultPreview(ResultPreviewListener toInform) {
00127         this.resultPreviewer = toInform;
00128         this.resultPreviewRequested = true;
00129     }
00130 
00131     @Override
00132     public boolean resultPreviewRequested() {
00133         return this.resultPreviewRequested;
00134     }
00135 
00136     @Override
00137     public synchronized void setLatestResultPreview(Object latestPreview) {
00138         this.resultPreviewRequested = false;
00139         this.latestResultPreview = latestPreview;
00140         if (this.resultPreviewer != null) {
00141             this.resultPreviewer.latestPreviewChanged();
00142         }
00143         this.resultPreviewer = null;
00144     }
00145 }
 All Classes Namespaces Files Functions Variables Enumerations