org/objectweb/proactive/core/runtime/StartHierarchical.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.core.runtime;
00032 
00033 import java.io.File;
00034 import java.io.IOException;
00035 import java.net.URL;
00036 
00037 import org.apache.log4j.Logger;
00038 import org.apache.log4j.PropertyConfigurator;
00039 import org.objectweb.proactive.ProActive;
00040 import org.objectweb.proactive.core.ProActiveException;
00041 import org.objectweb.proactive.core.config.ProActiveConfiguration;
00042 import org.objectweb.proactive.core.process.ExternalProcess;
00043 import org.objectweb.proactive.core.process.JVMProcess;
00044 import org.objectweb.proactive.core.util.UrlBuilder;
00045 import org.objectweb.proactive.core.util.log.Loggers;
00046 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00047 
00048 
00058 public class StartHierarchical {
00059     static Logger logger = ProActiveLogger.getLogger(Loggers.RUNTIME);
00060     protected String nodeURL;
00061     protected String creatorID;
00062     protected String defaultRuntimeURL;
00063     protected String sNodeNumber;
00064     protected int nodeNumber;
00065     protected String protocolId;
00066     protected String vmName;
00067     protected String padURL;
00068     protected ProActiveRuntime proActiveRuntime;
00069 
00070     protected StartHierarchical() {
00071     }
00072 
00073     private StartHierarchical(String[] args) {
00074         if (args.length != 0) {
00075             this.nodeURL = args[0];
00076             this.creatorID = args[0].trim();
00077             this.defaultRuntimeURL = UrlBuilder.removeUsername(args[1]);
00078             this.sNodeNumber = args[2];
00079             this.nodeNumber = (new Integer(sNodeNumber)).intValue();
00080             this.protocolId = args[3];
00081             this.vmName = args[4];
00082         }
00083     }
00084 
00085     public static void main(String[] args) {
00086         // It's hard to know if we are on a forwarder or not in some spots 
00087         // (serialization for example), so we set property to help us.
00088         System.setProperty("proactive.hierarchicalRuntime", "true");
00089 
00090         
00091         if ("true".equals(System.getProperty("log4j.defaultInitOverride")) &&
00092                 (System.getProperty("log4j.configuration") != null)) {
00093             // configure log4j here to avoid classloading problems with log4j classes
00094             try {
00095                 String log4jConfiguration = System.getProperty(
00096                         "log4j.configuration");
00097                 File f = new File(log4jConfiguration);
00098                 PropertyConfigurator.configure(new URL(f.getPath()));
00099             } catch (IOException e) {
00100                 System.out.println(
00101                     "Error : incorrect path for log4j configuration : " +
00102                     System.getProperty("log4j.configuration"));
00103             }
00104         }
00105 
00106         ProActiveConfiguration.load();
00107 
00108         try {
00109             logger.info("**** Starting hierarchical jvm on " +
00110                 UrlBuilder.getHostNameorIP(java.net.InetAddress.getLocalHost()));
00111 
00112             if (logger.isDebugEnabled()) {
00113                 logger.debug("**** Starting jvm with classpath " +
00114                     System.getProperty("java.class.path"));
00115                 logger.debug("****              with bootclasspath " +
00116                     System.getProperty("sun.boot.class.path"));
00117             }
00118         } catch (java.net.UnknownHostException e) {
00119             e.printStackTrace();
00120         }
00121 
00122         new StartHierarchical(args).run();
00123     }
00124 
00125     private void run() {
00126         padURL = System.getProperty("proactive.pad");
00127 
00128         ProActiveRuntimeImpl impl = (ProActiveRuntimeImpl) ProActiveRuntimeImpl.getProActiveRuntime();
00129         impl.getVMInformation().setCreationProtocolID(protocolId);
00130 
00131         try {
00132             proActiveRuntime = RuntimeFactory.getProtocolSpecificRuntime(System.getProperty(
00133                         "proactive.communication.protocol") + ":");
00134             proActiveRuntime.getVMInformation().setCreationProtocolID(protocolId);
00135 
00136             LocalProActiveRuntime localPart = (LocalProActiveRuntime) ProActiveRuntimeImpl.getProActiveRuntime();
00137 
00138             ProActiveRuntime PART = RuntimeFactory.getRuntime(defaultRuntimeURL,
00139                     UrlBuilder.getProtocol(defaultRuntimeURL));
00140             localPart.setParent(PART);
00141 
00142             // Retrieve the process to be deployed from the parent runtime
00143             ExternalProcess process = PART.getProcessToDeploy(proActiveRuntime,
00144                     creatorID, vmName, padURL);
00145 
00146             if (process == null) {
00147                 logger.info("getProcessToDeploy failed. Aborting");
00148                 System.exit(0);
00149             }
00150 
00151             ((ProActiveRuntimeForwarderImpl) ProActiveRuntimeImpl.getProActiveRuntime()).setProcessesToDeploy(padURL,
00152                 vmName, process);
00153 
00154             try {
00155                 setParameters(process);
00156                 process.startProcess();
00157             } catch (IOException e) {
00158                 logger.info("process starting failed: " + e.getMessage());
00159                 System.exit(0);
00160             }
00161         } catch (ProActiveException e) {
00162             e.printStackTrace();
00163 
00164             // if we cannot get runtimes to deploy this JVM is useless
00165             System.exit(0);
00166         }
00167     }
00168 
00169     private void setParameters(ExternalProcess process) {
00170         String localruntimeURL = null;
00171 
00172         try {
00173             localruntimeURL = RuntimeFactory.getDefaultRuntime().getURL();
00174         } catch (ProActiveException e) {
00175             e.printStackTrace();
00176         }
00177 
00178         JVMProcess jvmProcess = (JVMProcess) process.getFinalProcess();
00179 
00180         jvmProcess.setJvmOptions("-Dproactive.jobid=" + ProActive.getJobId());
00181         jvmProcess.setParameters(creatorID + " " + localruntimeURL + " " +
00182             nodeNumber + " " + protocolId + " " + vmName);
00183     }
00184 }

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