00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030  
00031 package org.objectweb.proactive.core.config;
00032 
00033 import java.util.ArrayList;
00034 import java.util.HashMap;
00035 import java.util.Iterator;
00036 import java.util.List;
00037 
00038 import org.apache.log4j.ConsoleAppender;
00039 import org.apache.log4j.Level;
00040 import org.apache.log4j.Logger;
00041 import org.apache.log4j.PatternLayout;
00042 import org.objectweb.proactive.core.UniqueID;
00043 import org.objectweb.proactive.core.config.xml.MasterFileHandler;
00044 import org.objectweb.proactive.core.util.log.Loggers;
00045 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00046 
00047 
00054 public class ProActiveConfiguration {
00055     protected HashMap<String, String> loadedProperties;
00056     protected HashMap addedProperties;
00057     protected static ProActiveConfiguration singleton;
00058     protected static boolean isLoaded = false;
00059     protected static boolean defaultConfigAlreadyLoaded = false;
00060     protected static List<String> jvmDefinedProperties = new ArrayList<String>();
00061 
00062     private ProActiveConfiguration() {
00063         this.loadedProperties = new HashMap<String, String>();
00064         this.addedProperties = new HashMap();
00065     }
00066 
00067     protected static synchronized void createConfiguration() {
00068         if (ProActiveConfiguration.singleton == null) {
00069             ProActiveConfiguration.singleton = new ProActiveConfiguration();
00070         }
00071     }
00072 
00081     public static void load() {
00082         if (!isLoaded) {
00083             loadDefaultConfig();
00084             isLoaded = true;
00085         }
00086     }
00087 
00088     private static void loadDefaultConfig() {
00089         String filename = null;
00090         filename = ProActiveConfiguration.class.getResource(
00091                 "ProActiveConfiguration.xml").toString();
00092         MasterFileHandler.createMasterFileHandler(filename,
00093             ProActiveConfiguration.getConfiguration());
00094         ProActiveConfiguration.getConfiguration().loadProperties();
00095         if (System.getProperty("log4j.configuration") == null) {
00096             loadDefaultLogger();
00097         }
00098         defaultConfigAlreadyLoaded = true;
00099     }
00100 
00105     public static void load(String filename) {
00106         if (!isLoaded) {
00107             if (!defaultConfigAlreadyLoaded) {
00108                 loadDefaultConfig();
00109             }
00110             MasterFileHandler.createMasterFileHandler(filename,
00111                 ProActiveConfiguration.getConfiguration());
00112             ProActiveConfiguration.getConfiguration().loadProperties();
00113             isLoaded = true;
00114         }
00115     }
00116 
00117     public synchronized static ProActiveConfiguration getConfiguration() {
00118         if (ProActiveConfiguration.singleton == null) {
00119             ProActiveConfiguration.createConfiguration();
00120         }
00121         return singleton;
00122     }
00123 
00129     public void propertyFound(String name, String value) {
00130         this.loadedProperties.put(name, value);
00131     }
00132 
00136     public void loadProperties() {
00137         Iterator<String> it = loadedProperties.keySet().iterator();
00138         String name = null;
00139         String value = null;
00140         while (it.hasNext()) {
00141             name = it.next();
00142             value = this.loadedProperties.get(name);
00143             if (!defaultConfigAlreadyLoaded) {
00144                 
00145                 if (System.getProperty(name) == null) {
00146                     System.setProperty(name, value);
00147                 } else {
00148                     jvmDefinedProperties.add(name);
00149                 }
00150             } else {
00151                 if (!jvmDefinedProperties.contains(name)) {
00152                     
00153                     System.setProperty(name, value);
00154                 }
00155             }
00156         }
00157     }
00158 
00159     
00160     
00161     
00162     
00163     
00164     
00165     
00166     
00167     
00168     
00169     
00170     
00171     
00172     
00173     
00174     
00175     
00176     
00177     
00178     
00179     
00180     
00181     
00182     
00183     
00184     
00185     public static String getLocationServerClass() {
00186         return System.getProperty("proactive.locationserver");
00187     }
00188 
00189     public static String getLocationServerRmi() {
00190         return System.getProperties().getProperty("proactive.locationserver.rmi");
00191     }
00192 
00193     public static String getACState() {
00194         return System.getProperty("proactive.future.ac");
00195     }
00196 
00197     public static String getSchemaValidationState() {
00198         return System.getProperty("schema.validation");
00199     }
00200 
00201     
00202     public static String getFTState() {
00203         return System.getProperty("proactive.ft");
00204     }
00205 
00206     public static String getCheckpointServer() {
00207         return System.getProperty("proactive.ft.server.checkpoint");
00208     }
00209 
00210     public static String getLocationServer() {
00211         return System.getProperty("proactive.ft.server.location");
00212     }
00213 
00214     public static String getRecoveryServer() {
00215         return System.getProperty("proactive.ft.server.recovery");
00216     }
00217 
00218     public static String getGlobalFTServer() {
00219         return System.getProperty("proactive.ft.server.global");
00220     }
00221 
00222     public static String getTTCValue() {
00223         return System.getProperty("proactive.ft.ttc");
00224     }
00225 
00226     public static String getAttachedResourceServer() {
00227         return System.getProperty("proactive.ft.server.resource");
00228     }
00229 
00230     public static String getFTProtocol() {
00231         return System.getProperty("proactive.ft.protocol");
00232     }
00233     
00234     public static boolean osgiServletEnabled() {
00235         return "enabled".equals(System.getProperty("proactive.http.servlet"));
00236     }
00237 
00238     
00239     private static boolean isForwarder;
00240 
00241     static {
00242         String prop = System.getProperty("proactive.hierarchicalRuntime");
00243         isForwarder = ((prop != null) &&
00244             (prop.equals("true") || prop.equals("root")));
00245     }
00246 
00247     public static boolean isForwarder() {
00248         return isForwarder;
00249     }
00250 
00251     public static String getGroupInformation() {
00252         return System.getProperty("proactive.groupInformation",
00253             UniqueID.getCurrentVMID().toString() + "~-1");
00254     }
00255 
00256     
00257     
00258     
00259     
00260     
00261     
00262     
00263     
00264     
00265     
00266     
00267     
00268     
00269     
00270     
00271     
00272     
00273     
00274     
00275 
00279     private static void loadDefaultLogger() {
00280         
00281         
00282         Logger logger = ProActiveLogger.getLogger(Loggers.CORE);
00283         logger.setAdditivity(false);
00284         logger.setLevel(Level.INFO);
00285         logger.addAppender(new ConsoleAppender(new PatternLayout()));
00286     }
00287 }