KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > core > runtime > StartRuntime


1 /*
2  * ################################################################
3  *
4  * ProActive: The Java(TM) library for Parallel, Distributed,
5  * Concurrent computing with Security and Mobility
6  *
7  * Copyright (C) 1997-2002 INRIA/University of Nice-Sophia Antipolis
8  * Contact: proactive-support@inria.fr
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23  * USA
24  *
25  * Initial developer(s): The ProActive Team
26  * http://www.inria.fr/oasis/ProActive/contacts.html
27  * Contributor(s):
28  *
29  * ################################################################
30  */

31 package org.objectweb.proactive.core.runtime;
32
33 import org.apache.log4j.Logger;
34 import org.objectweb.proactive.core.ProActiveException;
35 import org.objectweb.proactive.core.config.ProActiveConfiguration;
36 import org.objectweb.proactive.core.util.UrlBuilder;
37
38
39 /**
40  * <i><font size="-1" color="#FF0000">**For internal use only** </font></i><br>
41  * <p>
42  * This class is a utility class allowing to start a ProActiveRuntime with a JVM.
43  * </p><p>
44  * This class is mainly used with ProActiveDescriptor to start a ProActiveRuntime
45  * on a local or remote JVM.
46  * </p>
47  *
48  * @author ProActive Team
49  * @version 1.0, 2002/08/29
50  * @since ProActive 0.9
51  *
52  */

53 public class StartRuntime {
54     //Name of the runtime that launched this class reading the ProActiveDescriptor
55
//private static final String DefaultRuntimeName = "PART_DEFAULT";
56
//Name of the runtime's host that launched this class reading the ProActiveDescriptor
57
static Logger logger = Logger.getLogger(StartRuntime.class.getName());
58     protected String JavaDoc DefaultRuntimeURL;
59     protected String JavaDoc nodeURL;
60     protected String JavaDoc creatorID;
61     protected ProActiveRuntime proActiveRuntime;
62     //protected String acquisitionMethod;
63
protected String JavaDoc nodeNumber;
64     protected String JavaDoc vmName;
65     protected int nodenumber; //it is only the int value of nodeNumber
66

67     protected String JavaDoc protocolId;
68
69
70     protected StartRuntime() {
71     }
72
73     private StartRuntime(String JavaDoc[] args) {
74         this.nodeURL = args[0];
75         this.creatorID = args[0].trim();
76         //System.out.println(creatorID);
77
this.DefaultRuntimeURL = args[1];
78         //this.acquisitionMethod = args[2];
79
this.nodeNumber = args[2];
80      // this.portNumber = Integer.parseInt(args[4]);
81
this.nodenumber = (new Integer JavaDoc(nodeNumber)).intValue();
82         this.protocolId = args[3];
83         this.vmName = args[4];
84     }
85
86     public static void main(String JavaDoc[] args) {
87         if (args.length < 3) {
88             logger.error(
89                 "Usage: java org.objectweb.proactive.core.runtime.StartRuntime <nodeURL> <DefaultRuntimeURL> <acquisitionMethod> <portNumber>");
90             System.exit(1);
91         }
92         ProActiveConfiguration.load();
93
94 // System.out.println("StartRunTime.main() " + args[0] + " " + args[1] +
95
// " " + args[2] + " " + args[3]);
96

97         try {
98             logger.info("**** Starting jvm on " +
99                 java.net.InetAddress.getLocalHost().getCanonicalHostName());
100             if (logger.isDebugEnabled()) {
101                 logger.debug("**** Starting jvm with classpath " +
102                     System.getProperty("java.class.path"));
103                 logger.debug("**** with bootclasspath " +
104                     System.getProperty("sun.boot.class.path"));
105             }
106         } catch (java.net.UnknownHostException JavaDoc e) {
107             e.printStackTrace();
108         }
109         new StartRuntime(args).run();
110     }
111
112     /**
113      * <i><font size="-1" color="#FF0000">**For internal use only** </font></i>
114      * Runs the complete creation and registration of a ProActiveRuntime and creates a
115      * node once the creation is completed.
116      */

117     private void run() {
118         try {
119
120             //proActiveRuntime = RuntimeFactory.getProtocolSpecificRuntime(acquisitionMethod);
121
proActiveRuntime = RuntimeFactory.getProtocolSpecificRuntime(System.getProperty("proactive.communication.protocol")+":");
122             
123             proActiveRuntime.getVMInformation().setCreationProtocolID(protocolId);
124             
125 /*
126             for (int i = 1; i <= nodenumber; i++) {
127                 proActiveRuntime.createLocalNode(nodeURL +
128                     Integer.toString(
129                         new java.util.Random(System.currentTimeMillis()).nextInt()),
130                     false);
131                 //Thread.sleep(2000); for windows
132             }
133
134             //System.out.println("creation OK");
135             //System.out.println(DefaultRuntimeURL);
136 */

137             register(DefaultRuntimeURL);
138         } catch (ProActiveException e) {
139             e.printStackTrace();
140         }
141
142         // catch(Exception e){
143
// e.printStackTrace();
144
// }
145
}
146
147     /**
148      * <i><font size="-1" color="#FF0000">**For internal use only** </font></i>
149      * Performs the registration of a ProActiveRuntime on the runtime that initiated the creation
150      * of ProActiveDescriptor.
151      */

152     private void register(String JavaDoc hostName) {
153         try {
154             
155             ProActiveRuntime PART = RuntimeFactory.getRuntime(DefaultRuntimeURL,
156                                 UrlBuilder.getProtocol(DefaultRuntimeURL));
157             PART.register(proActiveRuntime, proActiveRuntime.getURL(),
158                 creatorID, System.getProperty("proactive.communication.protocol")+":",vmName);
159             
160         } catch (ProActiveException e) {
161             e.printStackTrace();
162         }
163     }
164 }
165
Popular Tags