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.closedworldlauncher; 00032 00033 import java.util.ArrayList; 00034 import java.util.StringTokenizer; 00035 00036 00037 public class WorldInfo { 00038 protected static final String TOTAL_HOSTS_NUMBER_PROPERTY = "total_hosts"; 00039 protected static final String HOST_NUMBER_PROPERTY = "host_number"; 00040 protected static final String HOST_LIST_PROPERTY = "host_names"; 00041 protected int totalHostsNumber; 00042 protected int currentHostNumber; 00043 protected String[] hostListAsArray; 00044 protected String hostList; 00045 00046 public WorldInfo() { 00047 } 00048 00049 public void init() { 00050 String tmp = null; 00051 tmp = System.getProperty(TOTAL_HOSTS_NUMBER_PROPERTY); 00052 totalHostsNumber = (tmp == null) ? 0 : Integer.parseInt(tmp); 00053 tmp = System.getProperty(HOST_NUMBER_PROPERTY); 00054 currentHostNumber = (tmp == null) ? 0 : Integer.parseInt(tmp); 00055 tmp = System.getProperty(HOST_LIST_PROPERTY); 00056 hostList = (tmp == null) ? new String() : tmp; 00057 hostListAsArray = (tmp == null) ? new String[] { "" } 00058 : this.stringToArray(tmp); 00059 } 00060 00061 public int getTotalHostNumber() { 00062 return this.totalHostsNumber; 00063 } 00064 00065 public int getCurrenHostNumber() { 00066 return this.currentHostNumber; 00067 } 00068 00069 public String getHostList() { 00070 return this.hostList; 00071 } 00072 00073 public String[] getHostListAsArray() { 00074 return this.hostListAsArray; 00075 } 00076 00080 protected String[] stringToArray(String string) { 00081 ArrayList<String> tmp = new ArrayList<String>(); 00082 StringTokenizer st = new StringTokenizer(string); 00083 while (st.hasMoreTokens()) { 00084 tmp.add(st.nextToken()); 00085 } 00086 return tmp.toArray(new String[] { "" }); 00087 } 00088 00089 public String toString() { 00090 StringBuffer tmp = new StringBuffer(); 00091 tmp.append(TOTAL_HOSTS_NUMBER_PROPERTY).append(" = ") 00092 .append(totalHostsNumber).append("\n"); 00093 tmp.append(HOST_NUMBER_PROPERTY).append(" = ").append(currentHostNumber) 00094 .append("\n"); 00095 tmp.append(HOST_LIST_PROPERTY).append(" = "); 00096 for (int i = 0; i < hostListAsArray.length; i++) { 00097 tmp.append(hostListAsArray[i]).append(" "); 00098 } 00099 return tmp.toString(); 00100 } 00101 00102 public static void main(String[] args) { 00103 WorldInfo info = new WorldInfo(); 00104 info.init(); 00105 System.out.println(info); 00106 } 00107 }