00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 package org.objectweb.proactive.ext.scilab.util;
00032
00033 import javasci.SciDoubleMatrix;
00034
00035 import org.objectweb.proactive.ext.scilab.SciResult;
00036 import org.objectweb.proactive.ext.scilab.monitor.SciEvent;
00037 import org.objectweb.proactive.ext.scilab.monitor.SciEventListener;
00038 import org.objectweb.proactive.ext.scilab.monitor.SciTaskInfo;
00039 import org.objectweb.proactive.ext.scilab.monitor.ScilabService;
00040
00041
00045 public class PiEventListener implements SciEventListener{
00046 private FutureDoubleMatrix res;
00047 private int nbBloc;
00048 private int count;
00049 private double pi;
00050 private ScilabService service;
00051
00052 public PiEventListener(ScilabService service, int nbBloc, FutureDoubleMatrix res){
00053 this.service = service;
00054 this.res = res;
00055 this.nbBloc = nbBloc;
00056 }
00057
00058 public void actionPerformed(SciEvent evt){
00059 SciTaskInfo sciTaskInfo = (SciTaskInfo) evt.getSource();
00060
00061 if(sciTaskInfo.getState() != SciTaskInfo.SUCCEEDED){
00062
00063
00064
00065 return;
00066 }
00067
00068 System.out.println("IDTASK: " + sciTaskInfo.getIdTask() + " IDRES: " + res.getName());
00069 if(!sciTaskInfo.getIdTask().startsWith(res.getName())){
00070 return;
00071 }
00072
00073 service.removeTask(sciTaskInfo.getIdTask());
00074
00075 System.out.println("---------------- Task:" + sciTaskInfo.getIdTask() + " " + sciTaskInfo.getIdEngine() + " " + service.getMapTaskRun().size() +" SUCCESS -----------------");
00076
00077 SciResult sciResult = sciTaskInfo.getSciResult();
00078
00079
00080 if(!sciResult.getId().startsWith(res.getName())){
00081 return;
00082 }
00083
00084 SciDoubleMatrix sciData = (SciDoubleMatrix) sciResult.getList().get(0);
00085 pi += sciData.getData()[0];
00086
00087 count++;
00088
00089
00090 if(count == nbBloc){
00091 res.set(new double[]{pi});
00092 service.removeEventListenerEngine(this);
00093 }
00094 }
00095 }