|
WIDAR Classes | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.nrao.widar.util.SystemProperties
public class SystemProperties
General purpose utility class for working with the JVM's System Properites.
Java's JVM maintains a set of system properties that include the
platform's environment variables and information about the JVM itself.
Other properties may be added to this set at run time and these properties
will then be available for use by any process in the JVM simply by using
the java.lang.System.getProperty()
method.
CHANGE_CHECK_PERIOD_SECONDS
all
the files that have been loaded are checked to see if they changed.
Any file that has changed is reloaded into the System Properties so
that they dynamically reflect the state of the file (to the nearest
CHANGE_CHECK_PERIOD_SECONDS
).
If an application wants to ensure that it always has the latest value
for a property, it must reference the property using the
java.lang.System.getProperty()
method every time it uses it
instead of saving it one time to a local variable and using the
variable.
The WIDAR property files are located by default at
widar properties.
However it is possible to load properties at a different location
by setting the environment variable WIDAR_PROPERTIES_URL.
java.util.Properties.load(URL)
is used to load a property
file from the above URL. This can be done over the internet as long
the property files can be served by a web server.
An example of the property file used for the WIDAR On The Sky Prototype
testing is shown here:
ots.server.remoteFile = 192.139.21.151 ots.dir.main = /opt/widar/otsTesting/ ots.dir.stb.output.data = /opt/widar/otsTesting/stbOutput/data/ ots.dir.stb.output.data.golden = /opt/widar/otsTesting/stbOutput/data/golden/ ots.dir.stb.output.config = /opt/widar/otsTesting/stbOutput/config/ ots.file.stb.output.config.default = stbListenerConfigDefault.xml ots.dir.config = /opt/widar/otsTesting/configFiles/ ots.id.stationBoard.1 = 001-0-0 ots.id.stationBoard.2 = 001-0-1 ots.id.baselineBoard.1 = 101-0-0 ots.ip.stationBoard.1 = 10.64.97.25 ots.ip.stationBoard.2 = 10.64.97.26 ots.ip.stationBoard.3 = 10.64.97.22 ots.ip.stationBoard.4 = 192.139.21.48 ots.ip.stationBoard.5 = 192.139.21.151 ots.ip.baselineBoard.1 = 10.64.97.30These are similar to industry property files like Apple's .plist files and are recognized and readable as such by the Java language. The simple rules are:
name = value
per line'='
separates name and value
![]() |
![]() |
Field Summary | |
---|---|
static int |
CHANGE_CHECK_PERIOD_SECONDS
|
static java.lang.String |
DEFAULT_WIDAR_PROPERTIES_URL
This is the default URL for WIDAR system properties. |
static java.lang.String |
MAIN_PROPERTY_FILE
This is the name of the main property file that, among other things, specifies other property files to load. |
static java.lang.String |
WIDAR_PROPERTIES_URL
|
Constructor Summary | |
---|---|
SystemProperties()
|
Method Summary | |
---|---|
static java.lang.String |
get(java.lang.String propertyName)
Safe method for obtaining a System property value. |
static float |
get(java.lang.String propertyName,
float defaultValue)
Safe method for obtaining a specified System property value of a float type with a guaranteed value returned. |
static int |
get(java.lang.String propertyName,
int defaultValue)
Safe method for obtaining a specified System property value of an integer type with a guaranteed value returned. |
static java.lang.String |
get(java.lang.String propertyName,
java.lang.String defaultValue)
Safe method for obtaining a specified System property value with guaranteed value returned. |
static java.util.Properties |
getPropertySetCopy(java.lang.String propertySetName)
Returns a deep copy of a specified property set. |
static void |
load()
Loads the properties specified in the main properties file. |
static void |
load(java.lang.String filename)
Loads the properties from a specified file into the JVM's System Properties. |
static void |
reload(java.lang.String filename)
Reloads properties from a specified file. |
static java.lang.String[] |
startingWith(java.lang.String startString)
Convenience method to return an java.util.ArrayList<String>
of System Property names that begin with a specified String . |
static java.lang.String[] |
valuesForNamesStartingWith(java.lang.String startString)
Convenience method to return a String[] of property values whose property names start with a specified value. |
static java.lang.String[] |
withAValueOf(java.lang.String valueString)
Convenience method to return an String[]} of System Property names having a specified value. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String DEFAULT_WIDAR_PROPERTIES_URL
public static java.lang.String WIDAR_PROPERTIES_URL
public static final java.lang.String MAIN_PROPERTY_FILE
public static final int CHANGE_CHECK_PERIOD_SECONDS
Constructor Detail |
---|
public SystemProperties()
Method Detail |
---|
public static void load() throws java.io.IOException
java.io.IOException
- if problems ore encounterd during the
load.public static void reload(java.lang.String filename) throws java.io.IOException
java.io.IOException
public static void load(java.lang.String filename) throws java.io.IOException
java.io.IOException
- if problems are encountered loading the
properties.filename
- the name of the file in the main properties
directory.public static java.util.Properties getPropertySetCopy(java.lang.String propertySetName)
propertiesCopy
Hashtable.
But we will not limit this set name to the syntax of a
filename in case future requirements allow loading properties
from other sources. So the property set name is any String
that is used as a key into our Hashtable of copies of the
properties we loaded.
propertySetName
- the name of the properties to fetch
ex: 'system.properties' for the set of properties
that were loaded from the file of that name.
propertySetName
public static java.lang.String get(java.lang.String propertyName)
propertyName
- the name of the system property to fetch
public static java.lang.String get(java.lang.String propertyName, java.lang.String defaultValue)
propertyName
- the name of the system property to fetchdefaultValue
- the value to be returned if propertyName
does not exist or if an exception is experienced
public static int get(java.lang.String propertyName, int defaultValue)
propertyName
- the name of the system property to fetchdefaultValue
- the value to be returned if propertyName
does not exist or if an exception is experienced during
the property fetching or while converting it to an int
public static float get(java.lang.String propertyName, float defaultValue)
propertyName
- the name of the system property to fetchdefaultValue
- the value to be returned if propertyName
does not exist or if an exception is experienced during
the property fetching or while converting it to an int
public static java.lang.String[] startingWith(java.lang.String startString)
java.util.ArrayList<String>
of System Property names that begin with a specified String
.
for (String ip : SystemProperties.startingWith("ots.ip.station")) fldStbIpAddress.addItem(System.getProperty(ip));
startString
- the String
that is to be used by the
java.lang.String.startsWith()
method to find the
System Properties whos names start with it
startString
public static java.lang.String[] valuesForNamesStartingWith(java.lang.String startString)
for (String ip : SystemProperties.valuesForNamesstartingWith ("ots.ip.station")) fldStbIpAddress.addItem(ip);
startString
- the String
that is to be used by the
java.lang.String.startsWith()
method to find the
System Properties whos names start with it
startString
public static java.lang.String[] withAValueOf(java.lang.String valueString)
ots.id.baselineBoard.2 = BB-2002 ots.ip.baselineBoard.2 = 192.139.21.154It finds the property(s) whose value is 'BB-2002' and then replaces the 'id' in the property name with 'ip' to fetch the corresponding 'ip' property value ('192.139.21.154').
for(String prop : SystemProperties.withAValueOf(id)) { if (prop.startsWith("ots.id.")) { prop = prop.replaceFirst("id", "ip"); boardIp = System.getProperty(prop); } }
valueString
- the String
that is to be used by the
java.lang.String.equals()
method to find the
System Properties whos value equals it.
valueString
|
NRAO/DRAO | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |