org.objectweb.dsrg.sofa.deployment.zeroconf
Class Configuration

java.lang.Object
  extended by org.objectweb.dsrg.sofa.deployment.zeroconf.Configuration

public class Configuration
extends java.lang.Object

Configuration instance contains key-value pairs which are intended to represent configuration settings. You can query the configuration using its get() methods.

Configuration is supposed to be obtained from the Zero Configuration Server. The getFromServer() static methods serve as a client that tries to obtain the settings from the server.


Field Summary
static ValueParser<java.lang.Integer> INTEGER_PARSER
          A convenient ValueParser for parsing integer values.
static java.lang.String[] SofaProperties
           
static ValueParser<java.lang.String[]> STRING_ARRAY_PARSER
          A convenient ValueParser for parsing string arrays.
 
Method Summary
 java.lang.String get(java.lang.String key)
           
<T> T
get(java.lang.String key, ValueParser<T> parser)
          Searches for the key key and, if found, parses its value with parser.
static Configuration getFromServer()
          Obtains the configuration from server, using default values for port, timeout and number of tries.
static Configuration getFromServer(int port, int timeout, int tries)
          Obtains the configuration from server.
static java.util.Properties getSofaPropertiesFromServer(int zeroconfPort)
          Gets the SOFA configuration properties from the zeroconf server.
 java.util.Set<java.lang.String> keys()
          Returns a set of all keys in this Configuration.
static void loadSofaConfiguration()
          Gets the SOFA configuration from the zeroconf server and sets the appropriate java system properties.
static void loadSofaConfiguration(int zeroconfPort)
          Gets the SOFA configuration from the zeroconf server and sets the appropriate java system properties.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SofaProperties

public static final java.lang.String[] SofaProperties

INTEGER_PARSER

public static final ValueParser<java.lang.Integer> INTEGER_PARSER
A convenient ValueParser for parsing integer values.


STRING_ARRAY_PARSER

public static final ValueParser<java.lang.String[]> STRING_ARRAY_PARSER
A convenient ValueParser for parsing string arrays. For information on how an array or list of strings should be encoded into a string, see ListParser.

Method Detail

loadSofaConfiguration

public static void loadSofaConfiguration()
Gets the SOFA configuration from the zeroconf server and sets the appropriate java system properties.


loadSofaConfiguration

public static void loadSofaConfiguration(int zeroconfPort)
Gets the SOFA configuration from the zeroconf server and sets the appropriate java system properties.

Parameters:
zeroconfPort - The port of the zeroconf server to look up.

getSofaPropertiesFromServer

public static java.util.Properties getSofaPropertiesFromServer(int zeroconfPort)
Gets the SOFA configuration properties from the zeroconf server.

Parameters:
zeroconfPort - The port of the zeroconf server to look up.

getFromServer

public static Configuration getFromServer()
                                   throws java.net.SocketException,
                                          java.io.IOException
Obtains the configuration from server, using default values for port, timeout and number of tries.

Throws:
java.net.SocketException
java.io.IOException
See Also:
getFromServer(int, int, int)

getFromServer

public static Configuration getFromServer(int port,
                                          int timeout,
                                          int tries)
                                   throws java.net.SocketException,
                                          java.io.IOException
Obtains the configuration from server.

Parameters:
port - port on which the request is broadcasted. If -1, default port will be used.
timeout - time in milliseconds to wait for the response before retrying. If -1, default timeout will be used.
tries - number of requests sent before giving up. If -1, default value will be used.
Returns:
the configuration obtained from the server or null if no response was received within the given timeout and tries.
Throws:
java.net.SocketException
java.io.IOException

get

public java.lang.String get(java.lang.String key)
Returns:
the String value for the key key or null when there's no value with the given key.

get

public <T> T get(java.lang.String key,
                 ValueParser<T> parser)
      throws ParseException
Searches for the key key and, if found, parses its value with parser.

Returns:
the parsed value or null when there's no value with the given key.
Throws:
ParseException - propagates any exceptions thrown by parser.

keys

public java.util.Set<java.lang.String> keys()
Returns a set of all keys in this Configuration.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object