org/objectweb/proactive/ext/scilab/SciDeployEngine.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.util.HashMap;
00035 
00036 import org.apache.log4j.Logger;
00037 import org.objectweb.proactive.ActiveObjectCreationException;
00038 import org.objectweb.proactive.ProActive;
00039 import org.objectweb.proactive.core.ProActiveException;
00040 import org.objectweb.proactive.core.descriptor.data.ProActiveDescriptor;
00041 import org.objectweb.proactive.core.descriptor.data.VirtualNode;
00042 import org.objectweb.proactive.core.node.Node;
00043 import org.objectweb.proactive.core.node.NodeException;
00044 import org.objectweb.proactive.core.util.log.Loggers;
00045 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00046 
00053 public class SciDeployEngine {
00054         private static Logger logger = ProActiveLogger.getLogger(Loggers.SCILAB_DEPLOY);
00055         private static HashMap<String, Node> mapNode = new HashMap<String, Node>(); // List of deployed VNs 
00056         
00061         public static String[] getListVirtualNode(String pathDescriptor){
00062                 logger.debug("->SciDeployEngine In:getListVirtualNode:" + pathDescriptor);
00063                 
00064                 ProActiveDescriptor desc;
00065                 VirtualNode arrayVn[];
00066                 String arrayNameVn[] = null;
00067                 try {
00068                         desc = ProActive.getProactiveDescriptor("file:" + pathDescriptor);
00069                         arrayVn = desc.getVirtualNodes();
00070                         arrayNameVn = new String[arrayVn.length];
00071                         
00072                         for(int i=0; i<arrayVn.length; i++){
00073                                 arrayNameVn[i] = arrayVn[i].getName();
00074                         }
00075         
00076                 } catch (ProActiveException e) {
00077                         e.printStackTrace();
00078                 }
00079                 
00080                 return arrayNameVn;     
00081         }
00082         
00083         public static synchronized int getNbMappedNodes(String nameVirtualNode, String pathDescriptor){
00084                 ProActiveDescriptor desc;
00085                 VirtualNode vn;
00086                 try {
00087                         desc = ProActive.getProactiveDescriptor("file:" + pathDescriptor);
00088                         vn = desc.getVirtualNode(nameVirtualNode);
00089                         return vn.getNbMappedNodes();
00090                 }catch (ProActiveException e) {
00091                         e.printStackTrace();
00092                 }
00093                 return -1;
00094         }
00095         
00102         public synchronized static HashMap<String, SciEngine> deploy(String nameVirtualNode, String pathDescriptor, String[] arrayIdEngine){
00103                 logger.debug("->SciDeployEngine In:deploy:" + pathDescriptor);
00104                 ProActiveDescriptor desc;
00105                 VirtualNode vn;
00106                 Node nodes[];
00107                 SciEngine sciEngine;
00108                 HashMap<String, SciEngine> mapEngine = new HashMap<String, SciEngine>();
00109                 
00110                 try {
00111                         desc = ProActive.getProactiveDescriptor("file:" + pathDescriptor);
00112                         vn = desc.getVirtualNode(nameVirtualNode);
00113                         vn.activate();
00114                         nodes = vn.getNodes();
00115                         
00116                         int length = (nodes.length >arrayIdEngine.length)? arrayIdEngine.length:nodes.length;
00117                         
00118                         for(int i=0; i<length; i++){
00119                                 sciEngine = deploy(arrayIdEngine[i], nodes[i]);
00120                                 mapEngine.put(arrayIdEngine[i], sciEngine);
00121                         }
00122                 } catch (ProActiveException e) {
00123                         e.printStackTrace();
00124                 }
00125                 return mapEngine;
00126         }
00127         
00136         private synchronized static SciEngine deploy(String idEngine, Node currentNode) throws ActiveObjectCreationException, NodeException {
00137                 Object param[] = new Object[]{idEngine};
00138                 SciEngine sciEngine  = (SciEngine) ProActive.newActive(SciEngine.class.getName(), param, currentNode);
00139                 mapNode.put(idEngine, currentNode);
00140                 try{
00141                         ProActive.setImmediateService(sciEngine, "killWorker");
00142                         ProActive.setImmediateService(sciEngine, "exit");
00143                 }catch(IOException e){
00144                         e.printStackTrace();
00145                 }
00146                 return sciEngine;
00147         }
00148         
00149         
00158         public static SciEngine deploy(String idEngine) throws ActiveObjectCreationException, NodeException {
00159                 logger.debug("->SciDeployEngine In:deploy");
00160                 Object param[] = new Object[]{idEngine};
00161                 SciEngine sciEngine  =  (SciEngine) ProActive.newActive(SciEngine.class.getName(), param);
00162                 try{
00163                         ProActive.setImmediateService(sciEngine, "killWorker");
00164                         ProActive.setImmediateService(sciEngine, "exit");
00165                 }catch(IOException e){
00166                         e.printStackTrace();
00167                 }
00168                 return sciEngine;
00169         }
00170         
00171         public static Node getEngineNode(String idEngine){
00172                 return mapNode.get(idEngine);
00173         }
00174 }

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