KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > ic2d > IC2D


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.ic2d;
32 import org.objectweb.proactive.core.ProActiveException;
33 import org.objectweb.proactive.core.runtime.RuntimeFactory;
34 import org.objectweb.proactive.ic2d.data.IC2DObject;
35 import org.objectweb.proactive.ic2d.data.WorldObject;
36 import org.objectweb.proactive.ic2d.gui.IC2DFrame;
37
38 /**
39  * <p>
40  * This class is the main entry to the application IC2D allowing to start it with
41  * a new JVM.
42  * </p><p>
43  * This class has a main method and can be used directly from the java command.<br>
44  * &nbsp;&nbsp;&nbsp;java org.objectweb.proactive.ic2d.IC2D
45  * </p>
46  *
47  * @author ProActive Team
48  * @version 1.0, 2002/03/21
49  * @since ProActive 0.9
50  *
51  */

52 public class IC2D {
53
54   public final static int NOTHING = 0;
55   public final static int GLOBUS = 1;
56   public final static int RSH = 2;
57   
58   
59   /**
60    * Main startup.
61    */

62   public static void main(String JavaDoc args[]) {
63     String JavaDoc[] hosts = null;
64     if (args.length > 0) {
65       hosts = readPropertiesFile(args[0]);
66     }
67     int options = NOTHING;
68     /*
69     try {
70       Class.forName("org.globus.gram.Gram");
71       System.out.println("Globus installed !");
72       options = GLOBUS;
73     } catch (ClassNotFoundException e) {
74       System.out.println("Globus not installed !");
75     }
76     */

77     try {
78         //Not sure following line is useful !
79
Class.forName("org.objectweb.proactive.core.runtime.RuntimeFactory");
80         RuntimeFactory.getDefaultRuntime();
81     } catch (ProActiveException e1) {
82         e1.printStackTrace();
83     }
84    catch (ClassNotFoundException JavaDoc e) {
85       e.printStackTrace();
86       System.exit(1);
87     }
88     IC2DObject ic2dObject = new IC2DObject();
89     new IC2DFrame(ic2dObject, options);
90     if (hosts != null) {
91       WorldObject worldObject = ic2dObject.getWorldObject();
92       for (int i = 0; i<hosts.length; i++) {
93         try {
94             // to do : should decide wether we want rmi as default protocol
95
worldObject.addHostObject(hosts[i], System.getProperty("proactive.communication.protocol"));
96         } catch (java.rmi.RemoteException JavaDoc e) {
97           System.out.println("Can't create the host "+hosts[i]+", e="+e);
98         }
99       }
100     }
101   }
102
103
104   //
105
// -- CONSTRUCTORS -----------------------------------------------
106
//
107

108
109   //
110
// -- PUBLIC METHODS -----------------------------------------------
111
//
112

113
114
115   //
116
// -- PRIVATE METHODS -----------------------------------------------
117
//
118

119   /**
120    * go
121    */

122   private static String JavaDoc[] readPropertiesFile(String JavaDoc filename) {
123     try {
124       java.io.File JavaDoc f = new java.io.File JavaDoc(filename);
125       if (! f.canRead()) return null;
126       byte[] b = getBytesFromInputStream(new java.io.FileInputStream JavaDoc(f));
127       java.util.StringTokenizer JavaDoc tokenizer = new java.util.StringTokenizer JavaDoc(new String JavaDoc(b));
128       int n = tokenizer.countTokens();
129       if (n == 0) return null;
130       String JavaDoc[] result = new String JavaDoc[n];
131       int i=0;
132       while (tokenizer.hasMoreTokens()) {
133         result[i++] = tokenizer.nextToken();
134       }
135       return result;
136     } catch (java.io.IOException JavaDoc e) {
137       return null;
138     }
139   }
140
141
142   /**
143    * Returns an array of bytes containing the bytecodes for
144    * the class represented by the InputStream
145    * @param in the inputstream of the class file
146    * @return the bytecodes for the class
147    * @exception java.io.IOException if the class cannot be read
148    */

149   private static byte[] getBytesFromInputStream(java.io.InputStream JavaDoc in) throws java.io.IOException JavaDoc {
150     java.io.DataInputStream JavaDoc din = new java.io.DataInputStream JavaDoc(in);
151     byte[] bytecodes = new byte[in.available()];
152     try {
153       din.readFully(bytecodes);
154     } finally {
155       if (din != null) din.close();
156     }
157     return bytecodes;
158   }
159
160
161   //
162
// -- INNER CLASSES -----------------------------------------------
163
//
164

165 }
166
Popular Tags