JPPF, java, parallel computing, distributed computing, grid computing, parallel, distributed, cluster, grid, cloud, open source, android, .net
JPPF, java, parallel computing, distributed computing, grid computing, parallel, distributed, cluster, grid, cloud, open source, android, .net
JPPF

The open source
grid computing
solution

 Home   About   Features   Download   Documentation   On Github   Forums 

The JPPF configuration API

From JPPF 3.3 Documentation

Jump to: navigation, search
Main Page > Development guide > The JPPF configuration API


The JPPF configuration properties are accessible at runtime, via a static method call: JPPFConfiguration.getProperties(). This method returns an object of type TypedProperties, which is an extension of java.util.Properties with additional methods to handle properties with primitive values: boolean, int, long, float and double.

Here is a summary of the API provided by TypedProperties:

 public class TypedProperties extends Properties {
   // constructors
   public TypedProperties()
   // initialize with existing key/value pairs from a map
   public TypedProperties(Map<Object, Object> map)
   // string properties
   public String getString(String key)
   public String getString(String key, String defValue)
   // int properties
   public int getInt(String key)
   public int getInt(String key, int defValue)
   // long properties
   public long getLong(String key)
   public long getLong(String key, long defValue)
   // float properties
   public float getFloat(String key)
   public float getFloat(String key, float defValue)
   // double properties
   public double getDouble(String key)
   public double getDouble(String key, double defValue)
   // boolean properties
   public boolean getBoolean(String key)
   public boolean getBoolean(String key, boolean defValue)
   // properties that are the path to another properties file
   public TypedProperties getProperties(String key)
   public TypedProperties getProperties(String key, TypedProperties defValue)
 }

As you can see, each getXXX() method has a corresponding method that takes a default value, to be returned if the property is not defined for the specified key.


You will also notice the last two methods getProperties(...), which are special in the sense that they do not handle simple value types, but rather specify the path to another properties file, whose content is returned as a TypedProperties instance. They are convenience methods that allow an easy navigation into a hierarchy of configuration files. The lookup mechanism for the specified properties file is described in the Javadoc for TypedProperties.getProperties(java.lang.String).


It is possible to alter the JPPF configuration, via a call to the method setProperty(String, String) of java.util.Properties. Notes that in this case, the value must be specfied as a string. If you wish to programatically change one or more JPPF configuration properties, then it should be done before they are used. For instance, in a client application, it should be done before the JPPF client is initialized, as in this sample code:

 // get the configuration
 TypedProperties props = JPPFConfiguration.getProperties();
 
 // set the connection properties programatically
 props.setProperty("jppf.discovery.enabled", "false");
 props.setProperty("jppf.drivers", "driver1");
 props.setProperty("driver1.jppf.server.host", "www.myhost.com");
 props.setProperty("driver1.jppf.server.port", "11111");
 
 // now our configuration will be used
 JPPFClient client = new JPPFClient();
Main Page > Development guide > The JPPF configuration API

JPPF Copyright © 2005-2020 JPPF.org Powered by MediaWiki