com.dracoware.module
Class RspModuleBackend

java.lang.Object
  extended by com.dracoware.module.RspModuleBackend

public class RspModuleBackend
extends java.lang.Object

The RspModuleBackend object handles all communications between an RSP module and an rspd.


Field Summary
static int ERROR
          Specifies a log message of highest priority.
static int NOTE
          Specifies a log message of lowest priority.
static int WARN
          Specifies a log message of normal priority.
 
Constructor Summary
RspModuleBackend(java.lang.String name)
          This function is called in a module before anything is done.
 
Method Summary
static java.lang.String bigSizeConvert(java.lang.String data)
          Convert sizes from a computer into megabytes.
static java.lang.String boolConvert(java.lang.String data)
          Convert strings which describe data with 2 values.
 java.lang.String[] getConfigData(java.lang.String name)
          Give an array of the data for config element "name", or null if there is no such config element with "name".
 java.lang.String[] getConfigNames()
          Give an array of all of the config element names, or null if there is no config data for this module.
 java.lang.String getConfigValue(java.lang.String name)
          Give the first piece of data associated with the config element with name "name", or null if there is no element with such a name.
 int getPolltime()
          Specifies how long to wait between posting data.
 java.lang.String[] getThresholds()
          Give an array of the thresholds, or null if there are no thresholds for this module.
 void giveData(java.lang.String data)
          Specify that the given piece of data should be sent to the rspd when the postMessage() function is called.
 void giveGraphData(RspGraphReturnData graphData)
          Specify that the given piece of graph data should be sent to the rspd when the postMessage() function is called.
 void log(int priority, java.lang.String message)
          Sends a message to the rspd app asking it to log a message.
static java.lang.String percentConvert(java.lang.String data)
          Convert strings of the form "2 %" or "0.4 %" or "204 percent" or "2" into a floating point number.
 boolean postMessage()
          Sends data to the RSP daemon as well as crossed thresholds.
 void setThreshold(java.lang.String thresholdToSet, boolean forceAlert)
          Specify that the given threshold is currently crossed.
static java.lang.String smallSizeConvert(java.lang.String data)
          Convert sizes from a computer into bytes.
static java.lang.String smallTimeConvert(java.lang.String data)
          Converts data in small time form, that is, seconds or less into the number of microseconds.
static java.lang.String timeConvert(java.lang.String data)
          Convert data in time form (such as "2 days, 5 hours, 6 minutes") into a String which is the time in seconds.
 boolean waitNextEvent(int secs)
          Waits specified amount of time for events from the rspd parent.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NOTE

public static final int NOTE
Specifies a log message of lowest priority.

See Also:
Constant Field Values

WARN

public static final int WARN
Specifies a log message of normal priority.

See Also:
Constant Field Values

ERROR

public static final int ERROR
Specifies a log message of highest priority.

See Also:
Constant Field Values
Constructor Detail

RspModuleBackend

public RspModuleBackend(java.lang.String name)
                 throws RspModuleException
This function is called in a module before anything is done. The server gives the module the correct port to use through the command line.

Parameters:
name - The name of this module.
Throws:
RspModuleException - If the module is unable to communicate with the RSPD.
Method Detail

log

public void log(int priority,
                java.lang.String message)
Sends a message to the rspd app asking it to log a message. Priorities are: NOTE, WARN, ERROR.

Parameters:
priority - The priority for this message.
message - The message to log.

waitNextEvent

public boolean waitNextEvent(int secs)
                      throws RspModuleException
Waits specified amount of time for events from the rspd parent.

Parameters:
secs - Number of seconds to wait for an event before returning.
Returns:
A true value is returned if the rspd has told us to quit.
Throws:
RspModuleException - If the module is unable to communicate with the RSPD.

getConfigValue

public java.lang.String getConfigValue(java.lang.String name)
Give the first piece of data associated with the config element with name "name", or null if there is no element with such a name.

Parameters:
name - The name of the config element.
Returns:
The first piece of data associated with this name.

getConfigNames

public java.lang.String[] getConfigNames()
Give an array of all of the config element names, or null if there is no config data for this module.

Returns:
A String array of all the config names which have values set.

getConfigData

public java.lang.String[] getConfigData(java.lang.String name)
Give an array of the data for config element "name", or null if there is no such config element with "name".

Returns:
A String array of all values associated with the given name.

getThresholds

public java.lang.String[] getThresholds()
Give an array of the thresholds, or null if there are no thresholds for this module.

Returns:
All thresholds set by the user which apply to this module.

giveData

public void giveData(java.lang.String data)
Specify that the given piece of data should be sent to the rspd when the postMessage() function is called.

Parameters:
data - The data to report to the rspd.

setThreshold

public void setThreshold(java.lang.String thresholdToSet,
                         boolean forceAlert)
                  throws RspModuleException
Specify that the given threshold is currently crossed. If true, forceAlert will cause RSPD to send alerts for this threshold even if it was already crossed.

Parameters:
thresholdToSet - The given threshold which is crossed.
forceAlert - Specifies that the RSPD should force an alert for this threshold.
Throws:
RspModuleException - If thresholdToSet is not a threshoold.

giveGraphData

public void giveGraphData(RspGraphReturnData graphData)
Specify that the given piece of graph data should be sent to the rspd when the postMessage() function is called.

Parameters:
graphData - The graph data to send to the rspd.

postMessage

public boolean postMessage()
                    throws RspModuleException
Sends data to the RSP daemon as well as crossed thresholds. The data must have been set with giveData() and giveGraphData().

Returns:
False if the RSPD is down and we should quit.
Throws:
RspModuleException - If the module is unable to communicate with the RSPD.

getPolltime

public int getPolltime()
Specifies how long to wait between posting data.

Returns:
The poll time for this module as set by RSPD configuration.

timeConvert

public static java.lang.String timeConvert(java.lang.String data)
                                    throws RspModuleException
Convert data in time form (such as "2 days, 5 hours, 6 minutes") into a String which is the time in seconds.

Parameters:
data - Data to convert.
Returns:
The converted data.
Throws:
RspModuleException - If the data given was invalid or could not be converted.

smallTimeConvert

public static java.lang.String smallTimeConvert(java.lang.String data)
                                         throws RspModuleException
Converts data in small time form, that is, seconds or less into the number of microseconds. Is in the form "2 msecs" or "2.56 milliseconds", etc.

Parameters:
data - The data to convert.
Returns:
The converted data.
Throws:
RspModuleException - If the data given was invalid or could not be converted.

bigSizeConvert

public static java.lang.String bigSizeConvert(java.lang.String data)
                                       throws RspModuleException
Convert sizes from a computer into megabytes. This is meant for larger sizes, from megabytes all the way to 2000 terabytes. Data may be of the form "2 MB", "1 gigabyte".

Parameters:
data - The data to convert.
Returns:
The converted data.
Throws:
RspModuleException - If the data given was invalid or could not be converted.

smallSizeConvert

public static java.lang.String smallSizeConvert(java.lang.String data)
                                         throws RspModuleException
Convert sizes from a computer into bytes. This is meant for small sizes, from bytes all the way up to 2000 megabytes. Data may be of the form "1 byte" or "50 kB".

Parameters:
data - The data to convert.
Returns:
The converted data.
Throws:
RspModuleException - If the data given was invalid or could not be converted.

percentConvert

public static java.lang.String percentConvert(java.lang.String data)
                                       throws RspModuleException
Convert strings of the form "2 %" or "0.4 %" or "204 percent" or "2" into a floating point number.

Parameters:
data - The data to convert.
Returns:
The converted data.
Throws:
RspModuleException - If the data given was invalid or could not be converted.

boolConvert

public static java.lang.String boolConvert(java.lang.String data)
                                    throws RspModuleException
Convert strings which describe data with 2 values. For true, supports: 1, up, on, true, enabled. For false, supports: 0, down, off, false, disabled.

Parameters:
data - The data to convert
Returns:
The converted data.
Throws:
RspModuleException - If the data given was invalid or could not be converted.