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
00044 public class MandelbrotEventListener implements SciEventListener{
00045 private FutureDoubleMatrix res;
00046 private ScilabService service;
00047 private int nbBloc;
00048 private int sizeBloc;
00049 private int count;
00050 private double matrixResult[];
00051
00052 public MandelbrotEventListener(ScilabService service, int nbBloc, FutureDoubleMatrix res){
00053 this.service = service;
00054 this.res = res;
00055 this.nbBloc = nbBloc;
00056 this.sizeBloc = (res.getNbRow()/nbBloc) * res.getNbCol();
00057 matrixResult = new double[res.getNbRow() * res.getNbCol()];
00058 }
00059
00060 public void actionPerformed(SciEvent evt){
00061 SciTaskInfo sciTaskInfo = (SciTaskInfo) evt.getSource();
00062
00063 if(sciTaskInfo.getState() != SciTaskInfo.SUCCEEDED){
00064 if(sciTaskInfo.getState() == SciTaskInfo.ABORTED){
00065 System.out.println("---------------- Task:" + sciTaskInfo.getIdTask() + " ABORT -----------------");
00066 }
00067 return;
00068 }
00069
00070 System.out.println("IDTASK: " + sciTaskInfo.getIdTask() + " IDRES: " + res.getName());
00071 if(!sciTaskInfo.getIdTask().startsWith(res.getName())){
00072 return;
00073 }
00074
00075 service.removeTask(sciTaskInfo.getIdTask());
00076
00077 System.out.println("---------------- Task:" + sciTaskInfo.getIdTask() +" SUCCESS -----------------");
00078
00079 SciResult sciResult = sciTaskInfo.getSciResult();
00080
00081
00082 SciDoubleMatrix sciMatrix = (SciDoubleMatrix) sciResult.getList().get(0);
00083 int iBloc = Integer.parseInt(sciMatrix.getName().substring(res.getName().length()));
00084
00085 double array[] = sciMatrix.getData();
00086 int pos = iBloc * sizeBloc;
00087
00088
00089 for(int i= 0; i< sizeBloc; i++){
00090 matrixResult[pos + i] = array[i];
00091 }
00092
00093 count++;
00094
00095 if(count == nbBloc){
00096 res.set(matrixResult);
00097 service.removeEventListenerEngine(this);
00098 }
00099 }
00100
00101 }