com.isti.trinetwatch.station
Class StationTable

java.lang.Object
  extended by com.isti.trinetwatch.station.StationTable
Direct Known Subclasses:
AgentInfo

public class StationTable
extends java.lang.Object

Class StationTable manages a table of Station objects (each object is associated with one station).


Nested Class Summary
protected  class StationTable.PurgeLevelsCacheThread
          Class PurgeLevelsCacheThread defines a thread that manages the clearing of old entries from the station-levels cache.
 
Field Summary
static java.lang.String LAT_LON_PREFIX_TEXT
          Extended lat/lon prefix text:
 
Constructor Summary
StationTable()
           
 
Method Summary
 boolean add(Station stationObj)
          Adds the given station object to the table.
 boolean addAll(StationTable srcTableObj)
          Adds the station objects from the given table to this table.
 boolean containsKey(java.lang.String name)
          Tests if a station with the specified short name exists in the table.
 boolean containsValue(Station stationObj)
          Tests if the given station object exists in the table.
 java.util.Enumeration elements()
          Returns an enumeration of station hash table values.
 void enterTableData(StationTable srcTableObj)
          Enters the data from the given table into this table.
 void enterTableData(StationTable srcTableObj, boolean closeRemFlag)
          Enters the data from the given table into this table.
 Station get(java.lang.String name)
          Returns the Station object in the table with the given short name.
static java.lang.Integer getDefaultSameStatusPercent()
          Get the default same status percent.
 java.lang.String getDisplayString()
          Returns a display string containing basic information about all the stations in the table (and their fields), with each station on a separate line.
 java.lang.String getDisplayString(boolean cfgParamsFlag)
          Returns a display string containing information about all the stations in the table (and their fields), with each station on a separate line.
 java.util.Vector getKeysVector()
          Returns a new Vector containing the keys in the station hashtable.
 StatusLevelTag getSameStatusLevel()
          If all stations in the table have the same status level then it is returned; otherwise 'null' is returned.
static CfgPropValidator getSameStatusPerecentValidator()
          Get the same status percent validator.
 long getSameStatusTime()
          Returns the time associated with the last change to the value returned by 'getSameStatusLevel()', or zero if no changes have occurred.
 java.lang.String getSnapshotStrFromCache(long dataTimeVal)
          Returns an snapshot string of entries for all stations at the given historical time value, fetched from the levels cache for each station.
 java.lang.String getSnapshotString(long dataTimeVal, long prefetchTimeVal, StatusLevelTable sLevelTableObj, UsageLevelTable uLevelTableObj)
          Returns an snapshot string of entries for all stations at the given historical time value.
 Station getStationForDParam(DynamicParamHolder dParam)
          Returns the station object that holds the given dynamic parameter object, or null if none could be found.
 java.lang.Object getThreadSyncObj()
          Returns the thread-synchronization object for this table.
 java.lang.String getUpdateString(long timeVal)
          Returns an update string of entries for all stations that have changed status or usage since the given time value.
 java.lang.String getUpdateString(java.lang.String agentName, long timeVal)
          Returns an update string of entries for all stations that have changed status or usage since the given time value.
 java.lang.String getUpdateString(java.lang.String agentName, long timeVal, boolean extendedFlag)
          Returns an update string of entries for all stations that have changed status or usage since the given time value.
 java.util.Vector getValuesVector()
          Returns a new Vector containing the values in the hashtable.
 java.util.Enumeration keys()
          Returns an enumeration of station hash table keys.
 void loadDynParamsFromArchive(ParamValues paramValuesObj, StatusLevelTable sLevelTableObj, UsageLevelTable uLevelTableObj, GroupTable agentsTable, long minTimeVal)
          Loads the status level, usage level and dynamic parameters from the newest items in the history archive.
 void preloadAndEnableLevelsCaches(ParamValues paramValuesObj, long baseTimeVal, StatusLevelTable sLevelTableObj, UsageLevelTable uLevelTableObj)
          Preloads the station-levels cache from the history archive and enables it for each station in table.
 void procSameStatusLevel()
          Tracks the status levels of the stations.
 Station remove(java.lang.String name)
          Removes the Station object in the table with the given short name.
 boolean removeAll(StationTable srcTableObj)
          Removes the station objects in the given table from this table.
static void setSameStatusPercent(int value)
          Set the same status percent.
 void startLevelsCachesPurgeThread(long levelsCacheSecs)
          Starts the station-levels cache purge thread.
 int stationCount()
          Returns a count of the number of station name keys in the table.
 void stopLevelsCachesPurgeThread()
          Starts the station-levels cache purge thread.
 java.lang.String toString()
          Returns a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LAT_LON_PREFIX_TEXT

public static final java.lang.String LAT_LON_PREFIX_TEXT
Extended lat/lon prefix text:

See Also:
Constant Field Values
Constructor Detail

StationTable

public StationTable()
Method Detail

getDefaultSameStatusPercent

public static java.lang.Integer getDefaultSameStatusPercent()
Get the default same status percent.

Returns:
the default same status percent.

getSameStatusPerecentValidator

public static CfgPropValidator getSameStatusPerecentValidator()
Get the same status percent validator.

Returns:
the same status percent validator.

setSameStatusPercent

public static void setSameStatusPercent(int value)
Set the same status percent.

Parameters:
percent - the same status percent.

add

public boolean add(Station stationObj)
Adds the given station object to the table.

Parameters:
stationObj - the station object.
Returns:
true if successful, false if a station with the same short name already exists in table or if the short name is invalid.

get

public Station get(java.lang.String name)
Returns the Station object in the table with the given short name.

Parameters:
name - the short name of the station.
Returns:
The handle of the Station object or null if no matching object was found.

remove

public Station remove(java.lang.String name)
Removes the Station object in the table with the given short name.

Parameters:
name - the short name of the station.
Returns:
The handle of the Station object that was removed or null if no matching object was found.

getThreadSyncObj

public java.lang.Object getThreadSyncObj()
Returns the thread-synchronization object for this table.

Returns:
The thread-synchronization object for this table.

addAll

public boolean addAll(StationTable srcTableObj)
Adds the station objects from the given table to this table.

Parameters:
srcTableObj - source table to read from.
Returns:
true if successful; false if any station objects failed to be added.

removeAll

public boolean removeAll(StationTable srcTableObj)
Removes the station objects in the given table from this table.

Parameters:
srcTableObj - source table.
Returns:
true if successful; false if any station objects failed to be removed.

enterTableData

public void enterTableData(StationTable srcTableObj,
                           boolean closeRemFlag)
Enters the data from the given table into this table. Existing station objects not in the given 'srcTableObj' are removed and matching station objects are updated.

Parameters:
srcTableObj - source table to read from.
closeRemFlag - true to invoke 'closeParamHistories()' on station objects that are removed.

enterTableData

public void enterTableData(StationTable srcTableObj)
Enters the data from the given table into this table. Existing station objects not in the given 'srcTableObj' are removed and matching station objects are updated.

Parameters:
srcTableObj - source table to read from.

containsKey

public boolean containsKey(java.lang.String name)
Tests if a station with the specified short name exists in the table.

Parameters:
name - the short name of the station.
Returns:
true if the station-name exists in the table, false if not.

containsValue

public boolean containsValue(Station stationObj)
Tests if the given station object exists in the table.

Parameters:
stationObj - the station object.
Returns:
true if the station object exists in the table, false if not.

keys

public java.util.Enumeration keys()
Returns an enumeration of station hash table keys. Each key will be the short name of a station.

Returns:
an enumeration of station hash table keys.

elements

public java.util.Enumeration elements()
Returns an enumeration of station hash table values. Each value will be a Station object. The data referenced by the returned enumeration will not be affected by later modifications to the table.

Returns:
an enumeration of station hash table values.

stationCount

public int stationCount()
Returns a count of the number of station name keys in the table.

Returns:
a count of the number of station name keys in the table.

getKeysVector

public java.util.Vector getKeysVector()
Returns a new Vector containing the keys in the station hashtable. Each key will be the short name of a station. The data in the the returned Vector will not be affected by later modifications to the hashtable, and the hashtable will not be affected by modifications to the returned Vector.

Returns:
a new Vector containing the keys in the station hashtable.

getValuesVector

public java.util.Vector getValuesVector()
Returns a new Vector containing the values in the hashtable. Each value will be a Station object. The data in the the returned Vector will not be affected by later modifications to the hashtable, and the hashtable will not be affected by modifications to the returned Vector.

Returns:
a new Vector containing the values in the hashtable.

getUpdateString

public java.lang.String getUpdateString(java.lang.String agentName,
                                        long timeVal)
Returns an update string of entries for all stations that have changed status or usage since the given time value.

Parameters:
agentName - the name of the agent to use in determining status, or null for no agent.
timeVal - a server epoch time value (seconds since 1/1/1970).
Returns:
An ASCII string formatted as follows: ;NNNN:SSSSS,UUUUU... where NNNN is a station name, SSSSS is a status level tag name, and UUUUU is a usage level tag name. Any number of station/status/usage groups may be passed.

getUpdateString

public java.lang.String getUpdateString(java.lang.String agentName,
                                        long timeVal,
                                        boolean extendedFlag)
Returns an update string of entries for all stations that have changed status or usage since the given time value.

Parameters:
agentName - the name of the agent to use in determining status, or null for no agent.
timeVal - a server epoch time value (seconds since 1/1/1970).
extendedFlag - true for extended information, false otherwise.
Returns:
An ASCII string formatted as follows: ;NNNN:SSSSS,UUUUU... or ;NNNN:SSSSS,UUUUU:LL=LAT,LON... if extended information is requested and it is available (all extended information is optional), where NNNN is a station name, SSSSS is a status level tag name, UUUUU is a usage level tag name, LAT is the station latitude and LON is the station longitude. For the final string in the information a termination of end of string, semi-colon (';') or colon (':') should be used. For example the usage level (UUUUU) text may be terminated by the end of the string, the semi-colon (';') for the next station or the colon (':') for the next extended information entry. The same is true for the last value of any extended extries such as the longitude (LON) entry if it is supplied. Any number of station/status/usage groups may be passed.

getUpdateString

public java.lang.String getUpdateString(long timeVal)
Returns an update string of entries for all stations that have changed status or usage since the given time value.

Parameters:
timeVal - a server epoch time value (seconds since 1/1/1970).
Returns:
An ASCII string formatted as follows: ;NNNN:SSSSS,UUUUU... where NNNN is a station name, SSSSS is a status level tag name, and UUUUU is a usage level tag name. Any number of station/status/usage groups may be passed.

getSnapshotString

public java.lang.String getSnapshotString(long dataTimeVal,
                                          long prefetchTimeVal,
                                          StatusLevelTable sLevelTableObj,
                                          UsageLevelTable uLevelTableObj)
Returns an snapshot string of entries for all stations at the given historical time value.

Parameters:
dataTimeVal - desired time value for data, in seconds since 1/1/1970.
prefetchTimeVal - time value for which archive data should be prefetched in search of the last entry before the 'dataTimeVal' time value (seconds since 1/1/1970).
sLevelTableObj - status-level table to use for translating status-level names to objects.
uLevelTableObj - usage-level table to use for translating usage-level names to objects.
Returns:
An ASCII string formatted as follows: NNNN:SSSSS,UUUUU:LL=LAT,LON;... where NNNN is a station name, SSSSS is a status level tag name, UUUUU is a usage level tag name, LAT is the station latitude and LON is the station longitude. For the final string in the information a termination of end of string, semi-colon (';') or colon (':') should be used. For example the usage level (UUUUU) text may be terminated by the end of the string, the semi-colon (';') for the next station or the colon (':') for the next extended information entry. The same is true for the last value of any extended extries such as the longitude (LON) entry if it is supplied. Any number of station/status/usage groups may be passed.

loadDynParamsFromArchive

public void loadDynParamsFromArchive(ParamValues paramValuesObj,
                                     StatusLevelTable sLevelTableObj,
                                     UsageLevelTable uLevelTableObj,
                                     GroupTable agentsTable,
                                     long minTimeVal)
Loads the status level, usage level and dynamic parameters from the newest items in the history archive.

Parameters:
paramValuesObj - object that implements the parameter-values interface.
sLevelTableObj - status-level table to use.
uLevelTableObj - usage-level table to use.
agentsTable - table of agent objects to use.
minTimeVal - minimum-acceptable time value for loaded parameters (in seconds since 1/1/1970).

preloadAndEnableLevelsCaches

public void preloadAndEnableLevelsCaches(ParamValues paramValuesObj,
                                         long baseTimeVal,
                                         StatusLevelTable sLevelTableObj,
                                         UsageLevelTable uLevelTableObj)
Preloads the station-levels cache from the history archive and enables it for each station in table.

Parameters:
paramValuesObj - object that implements the parameter-values interface.
baseTimeVal - base time value for cache (seconds since 1/1/1970).
sLevelTableObj - status-level table for cache.
uLevelTableObj - usage-level table for cache.

startLevelsCachesPurgeThread

public void startLevelsCachesPurgeThread(long levelsCacheSecs)
Starts the station-levels cache purge thread.

Parameters:
levelsCacheSecs - maximum age for entries in cache, in seconds.

stopLevelsCachesPurgeThread

public void stopLevelsCachesPurgeThread()
Starts the station-levels cache purge thread.


getSnapshotStrFromCache

public java.lang.String getSnapshotStrFromCache(long dataTimeVal)
Returns an snapshot string of entries for all stations at the given historical time value, fetched from the levels cache for each station.

Parameters:
dataTimeVal - desired time value for data, in seconds since 1/1/1970.
Returns:
An ASCII string formatted as follows: NNNN:SSSSS,UUUUU:LL=LAT,LON;... where NNNN is a station name, SSSSS is a status level tag name, UUUUU is a usage level tag name, LAT is the station latitude and LON is the station longitude. For the final string in the information a termination of end of string, semi-colon (';') or colon (':') should be used. For example the usage level (UUUUU) text may be terminated by the end of the string, the semi-colon (';') for the next station or the colon (':') for the next extended information entry. The same is true for the last value of any extended extries such as the longitude (LON) entry if it is supplied. Any number of station/status/usage groups may be passed.

getStationForDParam

public Station getStationForDParam(DynamicParamHolder dParam)
Returns the station object that holds the given dynamic parameter object, or null if none could be found.

Parameters:
dParam - the dynamic parameter object.
Returns:
the station object that holds the given dynamic parameter object, or null if none could be found.

procSameStatusLevel

public void procSameStatusLevel()
Tracks the status levels of the stations. This method should be called on a regular basis to keep track of when all of the stations have the same status level, thus allowing the 'getSameStatusLevel()' method to report the current status.


getSameStatusLevel

public StatusLevelTag getSameStatusLevel()
If all stations in the table have the same status level then it is returned; otherwise 'null' is returned. For this to work, the 'procSameStatusLevel()' method must be called on a regular basis.

Returns:
the status level if all stations in the table have the same status level, otherwise null.

getSameStatusTime

public long getSameStatusTime()
Returns the time associated with the last change to the value returned by 'getSameStatusLevel()', or zero if no changes have occurred.

Returns:
the time associated with the last change to the value returned by 'getSameStatusLevel()', or zero if no changes have occurred.

toString

public java.lang.String toString()
Returns a string representation of this object. The string contains the name of each station in the table.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of this object. The string contains the name of each station in the table.

getDisplayString

public java.lang.String getDisplayString(boolean cfgParamsFlag)
Returns a display string containing information about all the stations in the table (and their fields), with each station on a separate line.

Parameters:
cfgParamsFlag - if true then each station's information from its table of configuration file parameters is also included.
Returns:
a display string containing information about all the stations in the table (and their fields), with each station on a separate line.

getDisplayString

public java.lang.String getDisplayString()
Returns a display string containing basic information about all the stations in the table (and their fields), with each station on a separate line. Information from each station's table of configuration file parameters is not included.

Returns:
a display string containing basic information about all the stations in the table (and their fields), with each station on a separate line. Information from each station's table of configuration file parameters is not included.