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

The open source
grid computing

 Home   About   Features   Download   Documentation   On Github   Forums 

The JPPF configuration API

From JPPF 5.1 Documentation

Jump to: navigation, search
Main Page > Configuration 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)
  public TypedProperties setString(String key, String value)
  // int properties
  public int getInt(String key)
  public int getInt(String key, int defValue)
  public TypedProperties setInt(String key, int value)
  // long properties
  public long getLong(String key)
  public long getLong(String key, long defValue)
  public TypedProperties setLong(String key, long value)
  // float properties
  public float getFloat(String key)
  public float getFloat(String key, float defValue)
  public TypedProperties setFloat(String key, float value)
  // double properties
  public double getDouble(String key)
  public double getDouble(String key, double defValue)
  public TypedProperties setDouble(String key, double value)
  // char properties
  public TypedProperties getChar(String key)
  public TypedProperties getChar(String key, char defValue)
  public TypedProperties setChar(String key, char value)
  // boolean properties
  public boolean getBoolean(String key)
  public boolean getBoolean(String key, boolean defValue)
  public TypedProperties setBoolean(String key, boolean value)
  // File properties
  public File getFile(String key)
  public File getFile(String key, File defValue)
  public TypedProperties setFile(String key, File value)

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. Most of them also have a corresponding fluent setter method, which allows setting multiple properties of diffferent types in a call chain.

It is possible to alter the JPPF configuration, via calls to the setXXX(String, XXX) methods of TypedProperties. If you wish to programmatically 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 config = JPPFConfiguration.getProperties();
// set the connection properties programmatically
config.setBoolean("jppf.discovery.enabled", false)
  .setString("jppf.drivers", "driver1")
  .setString("", "")
  .setInt("driver1.jppf.server.port", 11111);

// now our configuration will be used
JPPFClient client = new JPPFClient();
Main Page > Configuration guide > The JPPF configuration API

JPPF Copyright © 2005-2020 Powered by MediaWiki