org/objectweb/proactive/ext/scilab/SciEngine.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;
00032 
00033 import java.io.IOException;
00034 import java.io.Serializable;
00035 import java.util.Date;
00036 
00037 import org.apache.log4j.Logger;
00038 import org.objectweb.proactive.ProActive;
00039 import org.objectweb.proactive.core.ProActiveException;
00040 import org.objectweb.proactive.core.process.JVMProcessImpl;
00041 import org.objectweb.proactive.core.util.log.Loggers;
00042 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00043 import org.objectweb.proactive.core.util.wrapper.BooleanWrapper;
00044 
00050 public class SciEngine implements Serializable  {
00051         private SciEngineWorker sciEngineWorker;
00052         private String idEngine; 
00053         private JVMProcessImpl process;
00054         private static Logger logger = ProActiveLogger.getLogger(Loggers.SCILAB_WORKER);
00055         
00059         public SciEngine() {
00060         }
00061         
00065         public SciEngine(String idEngine) {
00066                 this.idEngine = idEngine; 
00067         }
00068         
00069         
00070         public void exit(){
00071                 //logger.debug("->SciEngineWorker In:exit");
00072                 this.killWorker();
00073                 System.exit(0);
00074         }
00075         
00081         public SciResult execute(SciTask sciTask){
00082                 logger.debug("->SciEngineWorker In:execute:" + sciTask.getId());
00083                 SciResult sciResult = this.sciEngineWorker.execute(sciTask);
00084                 return sciResult;
00085         }
00086         
00091         public BooleanWrapper activate(){
00092                 logger.debug("->SciEngineWorker In:activate");
00093                 String url = "//localhost/" + idEngine + (new Date()).getTime();
00094                 try{
00095                         process = new JVMProcessImpl();
00096                         process.setClassname("org.objectweb.proactive.core.node.StartNode");
00097                         process.setParameters(url);
00098                         process.startProcess();
00099                 }catch(IOException e){
00100                         return new BooleanWrapper(false);
00101                 }
00102                 
00103                 for(int i=0; i<30; i++){
00104                         try{
00105                                 try{            
00106                                         sciEngineWorker  =  (SciEngineWorker) ProActive.newActive(SciEngineWorker.class.getName(), null, url);
00107                                         return new BooleanWrapper(true);
00108                                 }catch(ProActiveException e){
00109                                         
00110                                 }
00111                                 
00112                                 Thread.sleep(1000);
00113                         }catch(InterruptedException e){
00114                                 e.printStackTrace();
00115                         } 
00116                 }
00117                 return new BooleanWrapper(false);
00118         }
00119         
00124         public synchronized void killWorker(){
00125                 process.stopProcess();
00126         }
00127 }

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