seda.sandStorm.main
Class SandstormConfig

java.lang.Object
  extended by seda.sandStorm.main.SandstormConfig
All Implemented Interfaces:
java.lang.Cloneable

public class SandstormConfig
extends java.lang.Object
implements java.lang.Cloneable

This class is used to pass configuration parameters into Sandstorm at startup time. It reads initial configuration parameters from a file, using an XML-like format. Various operations can be performed upon this class to modify the configuration of the Sandstorm runtime.

See Also:
Sandstorm, Main

Nested Class Summary
(package private)  class SandstormConfig.configSection
           
(package private)  class SandstormConfig.directiveReader
          Internal class to preprocess special directives in the config file.
 
Field Summary
private  java.util.Hashtable cmdLineArgs
           
static java.lang.String CONFIG_FALSE
          String value for setting boolean configuration entries to false.
static java.lang.String CONFIG_TRUE
          String value for setting boolean configuration entries to true.
private static boolean DEBUG
           
 java.util.Hashtable defaultInitArgs
          Default initialization arguments passed to every stage.
static java.lang.String[] defaults
          The set of default values for the Sandstorm configuration.
private static java.lang.String DELIM_CHAR
           
static java.lang.String LIST_ELEMENT_DELIMITER
           
private static int MAX_DIRECTIVE_LENGTH
           
private  SandstormConfig.configSection root
           
private  java.util.Hashtable stages
           
static java.lang.String THREADMGR_AggTPSTM
          Value for defaultThreadMgr to use the aggregating TPSTM.
static java.lang.String THREADMGR_TPPTM
          Value for defaultThreadMgr to use the thread-per-CPU thread manager.
static java.lang.String THREADMGR_TPSTM
          Value for defaultThreadMgr to use the thread-per-stage thread manager.
 
Constructor Summary
SandstormConfig()
          Create a new SandstormConfig with the default settings.
SandstormConfig(java.lang.String fname)
          Create a new SandstormConfig, reading the configration from the given file.
SandstormConfig(java.lang.String[] defaultArgs)
          Create a new SandstormConfig with the default settings, with the given default init args, which will be passed to every stage.
SandstormConfig(java.lang.String fname, java.lang.String[] defaultArgs)
          Create a new SandstormConfig, reading the configration from the given file.
 
Method Summary
 void addStage(java.lang.String stageName, java.lang.String className, java.lang.String[] initargs)
          Add a stage to this SandstormConfig.
 boolean getBoolean(java.lang.String key)
          Return the configuration option associated with the given key as a boolean.
 boolean getBoolean(java.lang.String key, boolean defaultval)
          Return the configuration option associated with the given key as a boolean.
 SandstormConfig getCopy()
          Return a copy of this object.
 double getDouble(java.lang.String key)
          Return the configuration option associated with the given key as a double.
 double getDouble(java.lang.String key, double defaultval)
          Return the configuration option associated with the given key as a double.
 int getInt(java.lang.String key)
          Return the configuration option associated with the given key as an int.
 int getInt(java.lang.String key, int defaultval)
          Return the configuration option associated with the given key as an int.
 java.util.Enumeration getKeys()
          Return an enumeration of the top-level keys in this configuration.
private  java.util.Enumeration getKeys(SandstormConfig.configSection cs, java.lang.String prefix)
           
 java.util.Enumeration getKeys(java.lang.String prefix)
          Return an enumeration of the keys matching the given prefix.
 java.util.Enumeration getStages()
          Return an Enumeration of the stages specified by this SandstormConfig.
 java.lang.String getString(java.lang.String key)
          Return the configuration option associated with the given key as a String.
 java.lang.String getString(java.lang.String key, java.lang.String defaultval)
          Return the configuration option associated with the given key as a String.
 java.lang.String[] getStringList(java.lang.String key)
          Get the string list value corresponding to the given key.
private  java.lang.String getVal(SandstormConfig.configSection cs, java.lang.String key)
           
 void putBoolean(java.lang.String key, boolean val)
          Set the given configuration option specified as a boolean.
 void putDouble(java.lang.String key, double val)
          Set the given configuration option specified as an int.
 void putInt(java.lang.String key, int val)
          Set the given configuration option specified as an int.
 void putString(java.lang.String key, java.lang.String val)
          Set the given configuration option specified as a String.
 void puttStringList(java.lang.String key, java.lang.String[] valarr)
          Set the given key to the given string list value.
private  void putVal(SandstormConfig.configSection cs, java.lang.String key, java.lang.String val)
           
 void readFile(java.lang.String fname)
          Read the configuration from the given file.
private  java.util.Hashtable stringArrayToHT(java.lang.String[] arr)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

private static final boolean DEBUG
See Also:
Constant Field Values

DELIM_CHAR

private static final java.lang.String DELIM_CHAR
See Also:
Constant Field Values

MAX_DIRECTIVE_LENGTH

private static final int MAX_DIRECTIVE_LENGTH
See Also:
Constant Field Values

LIST_ELEMENT_DELIMITER

public static final java.lang.String LIST_ELEMENT_DELIMITER
See Also:
Constant Field Values

root

private SandstormConfig.configSection root

stages

private java.util.Hashtable stages

THREADMGR_TPPTM

public static final java.lang.String THREADMGR_TPPTM
Value for defaultThreadMgr to use the thread-per-CPU thread manager.

See Also:
Constant Field Values

THREADMGR_TPSTM

public static final java.lang.String THREADMGR_TPSTM
Value for defaultThreadMgr to use the thread-per-stage thread manager.

See Also:
Constant Field Values

THREADMGR_AggTPSTM

public static final java.lang.String THREADMGR_AggTPSTM
Value for defaultThreadMgr to use the aggregating TPSTM.

See Also:
Constant Field Values

CONFIG_TRUE

public static final java.lang.String CONFIG_TRUE
String value for setting boolean configuration entries to true.

See Also:
Constant Field Values

CONFIG_FALSE

public static final java.lang.String CONFIG_FALSE
String value for setting boolean configuration entries to false.

See Also:
Constant Field Values

defaults

public static final java.lang.String[] defaults
The set of default values for the Sandstorm configuration. In order to modify the default configuration used by Sandstorm, edit SandstormConfig.java and recompile.


cmdLineArgs

private java.util.Hashtable cmdLineArgs

defaultInitArgs

public java.util.Hashtable defaultInitArgs
Default initialization arguments passed to every stage.

Constructor Detail

SandstormConfig

public SandstormConfig()
Create a new SandstormConfig with the default settings.


SandstormConfig

public SandstormConfig(java.lang.String[] defaultArgs)
                throws java.io.IOException
Create a new SandstormConfig with the default settings, with the given default init args, which will be passed to every stage. Each element of defaultArgs[] is a String in the format "key=value". If "key" contains a dot ("."), then it will be treated as a key to be added to the Sandstorm configuration's global parameters. Otherwise, the key-value pair will be added to the "initargs" section for each stage.

Throws:
java.io.IOException

SandstormConfig

public SandstormConfig(java.lang.String fname)
                throws java.io.IOException
Create a new SandstormConfig, reading the configration from the given file. The configuration file uses an XML-like structure; see the Sandstorm documentation for more information on its format.

Throws:
java.io.IOException

SandstormConfig

public SandstormConfig(java.lang.String fname,
                       java.lang.String[] defaultArgs)
                throws java.io.IOException
Create a new SandstormConfig, reading the configration from the given file. The configuration file uses an XML-like structure; see the Sandstorm documentation for more information on its format.

Parameters:
defaultInitArgs - Default initialization arguments passed to every stage. These override any arguments found in the config file. Each element of this array must be a string with the format "key=value".
Throws:
java.io.IOException
Method Detail

getVal

private java.lang.String getVal(SandstormConfig.configSection cs,
                                java.lang.String key)

putVal

private void putVal(SandstormConfig.configSection cs,
                    java.lang.String key,
                    java.lang.String val)

getString

public java.lang.String getString(java.lang.String key)
Return the configuration option associated with the given key as a String. Returns null if not set.


getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.String defaultval)
Return the configuration option associated with the given key as a String. Returns default if not set.


putString

public void putString(java.lang.String key,
                      java.lang.String val)
Set the given configuration option specified as a String.


getBoolean

public boolean getBoolean(java.lang.String key)
Return the configuration option associated with the given key as a boolean. Returns false if not set.


getBoolean

public boolean getBoolean(java.lang.String key,
                          boolean defaultval)
Return the configuration option associated with the given key as a boolean. Returns default if not set.


putBoolean

public void putBoolean(java.lang.String key,
                       boolean val)
Set the given configuration option specified as a boolean.


getInt

public int getInt(java.lang.String key)
Return the configuration option associated with the given key as an int. Returns -1 if not set or if the value of the key cannot be expressed as an int.


getInt

public int getInt(java.lang.String key,
                  int defaultval)
Return the configuration option associated with the given key as an int. Returns default if not set or if the value of the key cannot be expressed as an int.


putInt

public void putInt(java.lang.String key,
                   int val)
Set the given configuration option specified as an int.


getDouble

public double getDouble(java.lang.String key)
Return the configuration option associated with the given key as a double. Returns -1 if not set or if the value of the key cannot be expressed as a double.


getDouble

public double getDouble(java.lang.String key,
                        double defaultval)
Return the configuration option associated with the given key as a double. Returns default if not set or if the value of the key cannot be expressed as a double.


getStringList

public java.lang.String[] getStringList(java.lang.String key)
Get the string list value corresponding to the given key. Returns null if not set.


putDouble

public void putDouble(java.lang.String key,
                      double val)
Set the given configuration option specified as an int.


puttStringList

public void puttStringList(java.lang.String key,
                           java.lang.String[] valarr)
Set the given key to the given string list value.


getKeys

private java.util.Enumeration getKeys(SandstormConfig.configSection cs,
                                      java.lang.String prefix)

getKeys

public java.util.Enumeration getKeys(java.lang.String prefix)
Return an enumeration of the keys matching the given prefix. A given key maps onto a set of child keys if it ends in a "." character (that is, it is an internal node within the tree). A key not ending in "." is a terminal node and maps onto a value that may be obtained using getString, getInt, or getDouble.


getKeys

public java.util.Enumeration getKeys()
Return an enumeration of the top-level keys in this configuration.


getCopy

public SandstormConfig getCopy()
Return a copy of this object.


addStage

public void addStage(java.lang.String stageName,
                     java.lang.String className,
                     java.lang.String[] initargs)
              throws StageNameAlreadyBoundException,
                     java.io.IOException
Add a stage to this SandstormConfig.

Parameters:
stageName - The name of the stage as it should be registered.
className - The fully-qualified class name of the stage event handler.
initargs - The initial arguments to pass into the stage.
Throws:
StageNameAlreadyBoundException
java.io.IOException

getStages

public java.util.Enumeration getStages()
Return an Enumeration of the stages specified by this SandstormConfig.


readFile

public void readFile(java.lang.String fname)
              throws java.io.IOException
Read the configuration from the given file.

Throws:
java.io.IOException

stringArrayToHT

private java.util.Hashtable stringArrayToHT(java.lang.String[] arr)
                                     throws java.io.IOException
Throws:
java.io.IOException