org/objectweb/proactive/ext/scilab/util/PiEventListener.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
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                         /*if(sciTaskInfo.getState() == SciTaskInfo.ABORT){
00063                                 System.out.println("***************** Task:" + sciTaskInfo.getIdTask() + " ABORT ********************");
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                 //System.out.println(sciTaskInfo.getTimeGlobal() +" " + sciResult.getTimeExecution());
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                 //System.out.println("COUNT = " + count + "  NBBLOC = " + nbBloc);
00090                 if(count == nbBloc){
00091                         res.set(new double[]{pi});
00092                         service.removeEventListenerEngine(this);
00093                 }
00094         }
00095 }

Generated on Mon Jan 22 15:16:10 2007 for ProActive by  doxygen 1.5.1