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

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