org/objectweb/proactive/core/runtime/StartRuntime.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.core.ProActiveException;
00040 import org.objectweb.proactive.core.config.ProActiveConfiguration;
00041 import org.objectweb.proactive.core.util.UrlBuilder;
00042 import org.objectweb.proactive.core.util.log.Loggers;
00043 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00044 
00045 
00060 public class StartRuntime {
00061     //Name of the runtime that launched this class reading the ProActiveDescriptor
00062     //private static final String DefaultRuntimeName = "PART_DEFAULT";
00063     //Name of the runtime's host that launched this class reading the ProActiveDescriptor
00064     static Logger logger = ProActiveLogger.getLogger(Loggers.RUNTIME);
00065     protected String defaultRuntimeURL;
00066     protected String nodeURL;
00067     protected String creatorID;
00068     protected ProActiveRuntime proActiveRuntime;
00069 
00070     //protected String acquisitionMethod;
00071     protected String nodeNumber;
00072     protected String vmName;
00073     protected int nodenumber; //it is only the int value of nodeNumber
00074     protected String protocolId;
00075 
00076     protected StartRuntime() {
00077     }
00078 
00079     private StartRuntime(String[] args) {
00080         if (args.length != 0) {
00081             this.nodeURL = args[0];
00082             this.creatorID = args[0].trim();
00083 
00084             //System.out.println(creatorID);
00085             this.defaultRuntimeURL = UrlBuilder.removeUsername(args[1]);
00086 
00087             //this.acquisitionMethod = args[2];
00088             this.nodeNumber = args[2];
00089 
00090             //   this.portNumber = Integer.parseInt(args[4]);
00091             this.nodenumber = (new Integer(nodeNumber)).intValue();
00092             this.protocolId = args[3];
00093             this.vmName = args[4];
00094         }
00095     }
00096 
00097     public static void main(String[] args) {
00098         if ("true".equals(System.getProperty("log4j.defaultInitOverride")) &&
00099                 (System.getProperty("log4j.configuration") != null)) {
00100             // configure log4j here to avoid classloading problems with log4j classes
00101             try {
00102                 String log4jConfiguration = System.getProperty(
00103                         "log4j.configuration");
00104                 File f = new File(log4jConfiguration);
00105                 PropertyConfigurator.configure(new URL(f.getPath()));
00106             } catch (IOException e) {
00107                 System.out.println(
00108                     "Error : incorrect path for log4j configuration : " +
00109                     System.getProperty("log4j.configuration"));
00110             }
00111         }
00112 
00113         ProActiveConfiguration.load();
00114 
00115         try {
00116             logger.info("**** Starting jvm on " +
00117                 UrlBuilder.getHostNameorIP(java.net.InetAddress.getLocalHost()));
00118 
00119             if (logger.isDebugEnabled()) {
00120                 logger.debug("**** Starting jvm with classpath " +
00121                     System.getProperty("java.class.path"));
00122                 logger.debug("****              with bootclasspath " +
00123                     System.getProperty("sun.boot.class.path"));
00124             }
00125         } catch (java.net.UnknownHostException e) {
00126             e.printStackTrace();
00127         }
00128 
00129         new StartRuntime(args).run();
00130     }
00131 
00137     private void run() {
00138         ProActiveRuntimeImpl impl = (ProActiveRuntimeImpl) ProActiveRuntimeImpl.getProActiveRuntime();
00139         impl.getVMInformation().setCreationProtocolID(protocolId);
00140 
00141         if (defaultRuntimeURL != null) {
00142             ProActiveRuntime PART;
00143             try {
00144                 PART = RuntimeFactory.getRuntime(defaultRuntimeURL,
00145                         UrlBuilder.getProtocol(defaultRuntimeURL));
00146                 register(PART);
00147                 impl.setParent(PART);
00148             } catch (ProActiveException e) {
00149                 e.printStackTrace();
00150                 //                               if we cannot get the parent, this jvm is useless
00151                 System.exit(0);
00152             }
00153         }
00154     }
00155 
00161     private void register(ProActiveRuntime PART) {
00162         try {
00163             proActiveRuntime = RuntimeFactory.getProtocolSpecificRuntime(System.getProperty(
00164                         "proactive.communication.protocol") + ":");
00165 
00166             PART.register(proActiveRuntime, proActiveRuntime.getURL(),
00167                 creatorID,
00168                 System.getProperty("proactive.communication.protocol") + ":",
00169                 vmName);
00170         } catch (ProActiveException e) {
00171             e.printStackTrace();
00172 
00173             // if we cannot register, this jvm is useless
00174             System.exit(0);
00175         }
00176     }
00177 }

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