com.isti.quakewatch.alert
Class AlertRecipient

java.lang.Object
  extended by com.isti.quakewatch.alert.AlertRecipient
All Implemented Interfaces:
AlertRecipientInterface
Direct Known Subclasses:
AlertEmailRecipient

public abstract class AlertRecipient
extends java.lang.Object
implements AlertRecipientInterface

Class AlertRecipient defines an abstract alert recipient. NOTE: Every subclass must have a constructor with a 'QWProgramInformationInterface' and 'Element' parameter.


Nested Class Summary
static class AlertRecipient.RecipientSetupException
          Class RecipientSetupException defines an exception thrown while setting up a recipient.
 
Field Summary
protected  QWAlarmProperties alarmCfgProps
          Set of configuration property items for alarm settings.
protected static java.lang.String ALARMS_GROUP_STR
          Name string for "Email Alarms" group of configuration items.
 CfgPropItem alertRecipientClassNameProp
          Alert recipient class name.
 CfgProperties cfgProps
          Configuration properties object.
protected  java.lang.String classNameText
          The class name text to be used in the log prefix text.
static java.lang.String defaultClassName
          The default class name if one is not found in the properties.
protected static java.lang.String GENERAL_GROUP_STR
          Name string for "General" group of configuration items.
 CfgPropItem globalAlarmEnabledFlagProp
          Flag set true to enable sending of emails to recipient when global alarm is triggered.
protected  LogFile logObj
          Log file object.
static int MSG_CANCEL_TYPE
          Message type value for cancel-event alert messages.
static int MSG_NEWEVT_TYPE
          Message type value for new-event alert messages.
static int MSG_UPDATE_TYPE
          Message type value for update-event alert messages.
protected  QWProgramInformationInterface progInfoObj
          'QWProgramInformationInterface' object
protected  boolean recipDeletedFlag
          Flag set true after item deleted.
static java.lang.String RECIPIENT_CLASSNAME
          Class name for the 'AlertRecipient' class.
static java.lang.String RECIPIENT_NAMESTR
          Name string for "Recipient" XML elements.
 CfgPropItem recipientNameProp
          Name of recipient.
 
Constructor Summary
AlertRecipient(AlertRecipient sourceRecipientObj)
          Creates an new recipient, with all fields set equal to those in the given recipient.
AlertRecipient(QWProgramInformationInterface progInfoObj)
          Creates an "empty" recipient, with all fields set to default values.
AlertRecipient(QWProgramInformationInterface progInfoObj, org.jdom.Element recipientElementObj)
          Creates an new recipient, with fields filled via the given "Recipient" element object.
 
Method Summary
 void addToEventRecAlarmRecipList(QWEventMsgRecord recObj)
          Adds this 'AlertRecipient' object to the list of 'AlertRecipient' objects for which the given event has triggered one or more alarm-alerts.
 boolean checkAlarmEventRec(QWEventMsgRecord recObj)
          Determines if the given event-message record would trigger an alarm condition.
static void clearEventRecAlarmRecipList(QWEventMsgRecord recObj)
          Clears the list of 'AlertRecipient' objects for which the given event has triggered one or more alarm-alerts.
static AlertRecipient createAlertRecipient(QWProgramInformationInterface progInfoObj, org.jdom.Element recipientElementObj)
          Creates an new recipient, with fields filled via the given "Recipient" element object.
protected  void doSendAlertMessage(QWEventMsgRecord recObj, int messageType)
          Generates an alert message for the given event-message record.
 QWAlarmProperties getAlarmCfgProps()
          Get of configuration property items for alarm settings.
 java.lang.String[] getAlarmRegionStrings()
          Returns the alarm regions for this recipient, in string format.
abstract  NotifyEventQueue getAlertMessageQueue()
          Returns the alert-message-queue object for this recipient.
static java.util.List getEventRecAlarmRecipList(QWEventMsgRecord recObj)
          Fetches the 'List' object containing the list of 'AlertRecipient' objects for which the given event has triggered one or more alarm-alerts.
protected  java.lang.String getLogPrefixText()
          Gets the log prefix text.
 int getNumRegions()
          Gets the number of regions.
 boolean getRecipDeletedFlag()
          Returns the recipient-deleted flag (which indicates that this recipient has been removed).
 java.lang.String getRecipientName()
          Returns the name value for this recipient.
 boolean isGlobalAlarmEnabled()
          Returns the status of whether a message should be sent when a global alarm is triggered for this recipient.
abstract  boolean isSendEnabled()
          Returns the status of whether or not sending is enabled for this recipient.
 void loadFromElement(org.jdom.Element recipientElementObj)
          Loads this recipient's fields from the given "Recipient" element object.
static java.lang.String loadRecipients(QWProgramInformationInterface progInfoObj, org.jdom.Element configRootElement, java.util.List alertRecipientsListObj)
          Loads the recipients specified by the "Recipient" elements in the configuration file.
static java.lang.String loadRecipients(QWProgramInformationInterface progInfoObj, org.jdom.Element configRootElement, java.util.List alertRecipientsListObj, IstiRegionMgrIntf istiRegionMgrObj)
          Loads the recipients specified by the "Recipient" elements in the configuration file.
static java.lang.Object newInstance(java.lang.Class classObj, java.lang.Class[] parameterTypes, java.lang.Object[] initargs)
          Uses the constructor with the specified arguments to create and initialize a new instance of specified class.
static AlertRecipient popFirstEventRecAlarmRecip(QWEventMsgRecord recObj)
          Fetches the 'List' object containing the list of 'AlertRecipient' objects for which the given event has triggered one or more alarm-alerts and removes and returns the first 'AlertRecipient' item in the list.
static void saveRecipients(QWProgramInformationInterface progInfoObj, org.jdom.Element configRootElement, java.util.List alertRecipientsListObj)
          Saves the recipients specified to "Recipient" elements in the configuration file.
protected abstract  void sendAlertMessage(QWEventMsgRecord recObj, int messageType)
          Generates an alert message for the given event-message record.
 void sendCancelAlertMessage(QWEventMsgRecord recObj)
          Responds to the given deleted event-message record by generating and send a "cancelled" alert message.
 void sendNewAlertMessage(QWEventMsgRecord recObj)
          Generates an "new" alert message for the given event-message record.
 void sendUpdateAlertMessage(QWEventMsgRecord recObj)
          Generates an "update" alert message for the given event-message record.
 void setGlobalAlarmEnabled(boolean b)
          Sets the status of whether a message should be sent when a global alarm is triggered for this recipient.
 void setIstiRegionMgrObj(IstiRegionMgrIntf istiRegionMgrObj)
          Sets the region-manager object to be used by this recipient.
 void setRecipDeletedFlag()
          Sets the recipient-deleted flag to indicate that this recipient has been removed.
 void setRecipientName(java.lang.String nameStr)
          Sets the name value for this recipient.
abstract  void setSendEnabled(boolean b)
          Sets the status of whether or not sending is enabled for this recipient.
abstract  void terminateMsgQueueThread()
          Terminates the processing thread for the queue for transmitting alert messages.
 org.jdom.Element toElement()
          Converts this recipient's fields into entries within an XML element.
abstract  java.lang.String toString()
          Returns a string representation of this recipient.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.isti.quakewatch.alert.AlertRecipientInterface
getRecipID
 

Field Detail

classNameText

protected java.lang.String classNameText
The class name text to be used in the log prefix text.


defaultClassName

public static java.lang.String defaultClassName
The default class name if one is not found in the properties.


RECIPIENT_NAMESTR

public static final java.lang.String RECIPIENT_NAMESTR
Name string for "Recipient" XML elements.

See Also:
Constant Field Values

RECIPIENT_CLASSNAME

public static final java.lang.String RECIPIENT_CLASSNAME
Class name for the 'AlertRecipient' class.

See Also:
Constant Field Values

GENERAL_GROUP_STR

protected static final java.lang.String GENERAL_GROUP_STR
Name string for "General" group of configuration items.

See Also:
Constant Field Values

ALARMS_GROUP_STR

protected static final java.lang.String ALARMS_GROUP_STR
Name string for "Email Alarms" group of configuration items.

See Also:
Constant Field Values

MSG_NEWEVT_TYPE

public static final int MSG_NEWEVT_TYPE
Message type value for new-event alert messages.

See Also:
Constant Field Values

MSG_UPDATE_TYPE

public static final int MSG_UPDATE_TYPE
Message type value for update-event alert messages.

See Also:
Constant Field Values

MSG_CANCEL_TYPE

public static final int MSG_CANCEL_TYPE
Message type value for cancel-event alert messages.

See Also:
Constant Field Values

progInfoObj

protected final QWProgramInformationInterface progInfoObj
'QWProgramInformationInterface' object


logObj

protected final LogFile logObj
Log file object.


recipDeletedFlag

protected boolean recipDeletedFlag
Flag set true after item deleted.


cfgProps

public final CfgProperties cfgProps
Configuration properties object.


alertRecipientClassNameProp

public final CfgPropItem alertRecipientClassNameProp
Alert recipient class name.


recipientNameProp

public final CfgPropItem recipientNameProp
Name of recipient.


globalAlarmEnabledFlagProp

public final CfgPropItem globalAlarmEnabledFlagProp
Flag set true to enable sending of emails to recipient when global alarm is triggered.


alarmCfgProps

protected final QWAlarmProperties alarmCfgProps
Set of configuration property items for alarm settings.

Constructor Detail

AlertRecipient

public AlertRecipient(QWProgramInformationInterface progInfoObj,
                      org.jdom.Element recipientElementObj)
               throws AlertRecipient.RecipientSetupException
Creates an new recipient, with fields filled via the given "Recipient" element object.

Parameters:
progInfoObj - the 'QWProgramInformationInterface' object.
recipientElementObj - the recipient object to use.
Throws:
AlertRecipient.RecipientSetupException - if an error occurs while loading fields from the element object.

AlertRecipient

public AlertRecipient(QWProgramInformationInterface progInfoObj)
Creates an "empty" recipient, with all fields set to default values.

Parameters:
progInfoObj - the 'QWProgramInformationInterface' object.

AlertRecipient

public AlertRecipient(AlertRecipient sourceRecipientObj)
               throws AlertRecipient.RecipientSetupException
Creates an new recipient, with all fields set equal to those in the given recipient.

Parameters:
sourceRecipientObj - the recipient object to use.
Throws:
AlertRecipient.RecipientSetupException - if an error occurs.
Method Detail

getLogPrefixText

protected java.lang.String getLogPrefixText()
Gets the log prefix text.

Returns:
the log prefix text.

setIstiRegionMgrObj

public void setIstiRegionMgrObj(IstiRegionMgrIntf istiRegionMgrObj)
Sets the region-manager object to be used by this recipient.

Parameters:
istiRegionMgrObj - region-manger object to use.

newInstance

public static java.lang.Object newInstance(java.lang.Class classObj,
                                           java.lang.Class[] parameterTypes,
                                           java.lang.Object[] initargs)
                                    throws java.lang.NoSuchMethodException,
                                           java.lang.SecurityException,
                                           java.lang.InstantiationException,
                                           java.lang.IllegalAccessException,
                                           java.lang.IllegalArgumentException,
                                           java.lang.reflect.InvocationTargetException
Uses the constructor with the specified arguments to create and initialize a new instance of specified class.

If the required access and argument checks succeed and the instantiation will proceed, the constructor's declaring class is initialized if it has not already been initialized.

If the constructor completes normally, returns the newly created and initialized instance.

Parameters:
classObj - the class to instantiate.
parameterTypes - the parameter array.
initargs - array of objects to be passed as arguments to the constructor call; values of primitive types are wrapped in a wrapper object of the appropriate type (e.g. a float in a Float)
Returns:
a new object created by calling the constructor for the specified class.
Throws:
java.lang.NoSuchMethodException - if a matching constructor is not found.
java.lang.SecurityException - if access to the information is denied.
java.lang.IllegalAccessException - if this Constructor object enforces Java language access control and the underlying constructor is inaccessible.
java.lang.IllegalArgumentException - if the number of actual and formal parameters differ; if an unwrapping conversion for primitive arguments fails; or if, after possible unwrapping, a parameter value cannot be converted to the corresponding formal parameter type by a method invocation conversion.
java.lang.InstantiationException - if the class that declares the underlying constructor represents an abstract class.
java.lang.reflect.InvocationTargetException - if the underlying constructor throws an exception.
java.lang.ExceptionInInitializerError - if the initialization provoked by this method fails.

createAlertRecipient

public static AlertRecipient createAlertRecipient(QWProgramInformationInterface progInfoObj,
                                                  org.jdom.Element recipientElementObj)
                                           throws AlertRecipient.RecipientSetupException
Creates an new recipient, with fields filled via the given "Recipient" element object.

Parameters:
progInfoObj - the 'QWProgramInformationInterface' object.
recipientElementObj - the recipient object to use.
Returns:
the new recipient or null if error.
Throws:
AlertRecipient.RecipientSetupException - if an error occurs while loading fields from the element object.

getAlarmCfgProps

public final QWAlarmProperties getAlarmCfgProps()
Get of configuration property items for alarm settings.

Returns:
the configuration property items for alarm settings.

getAlertMessageQueue

public abstract NotifyEventQueue getAlertMessageQueue()
Returns the alert-message-queue object for this recipient.

Specified by:
getAlertMessageQueue in interface AlertRecipientInterface
Returns:
The alert-message-queue object for this recipient.

isGlobalAlarmEnabled

public boolean isGlobalAlarmEnabled()
Returns the status of whether a message should be sent when a global alarm is triggered for this recipient.

Specified by:
isGlobalAlarmEnabled in interface AlertRecipientInterface
Returns:
true if sending of emails to recipient when global alarm is triggered is enabled, false otherwise.

isSendEnabled

public abstract boolean isSendEnabled()
Returns the status of whether or not sending is enabled for this recipient.

Returns:
true if sending is enabled; false if not.

setGlobalAlarmEnabled

public void setGlobalAlarmEnabled(boolean b)
Sets the status of whether a message should be sent when a global alarm is triggered for this recipient.

Parameters:
b - true if sending of emails to recipient when global alarm is triggered is enabled, false otherwise.

setSendEnabled

public abstract void setSendEnabled(boolean b)
Sets the status of whether or not sending is enabled for this recipient.

Parameters:
b - true if sending is enabled; false if not.

toElement

public org.jdom.Element toElement()
Converts this recipient's fields into entries within an XML element.

Returns:
A new 'Element' object containing the entries, or null if an error occurred.

loadFromElement

public void loadFromElement(org.jdom.Element recipientElementObj)
                     throws AlertRecipient.RecipientSetupException
Loads this recipient's fields from the given "Recipient" element object.

Parameters:
recipientElementObj - the recipient object to use.
Throws:
AlertRecipient.RecipientSetupException - if an error occurs while loading fields from the element object.

loadRecipients

public static java.lang.String loadRecipients(QWProgramInformationInterface progInfoObj,
                                              org.jdom.Element configRootElement,
                                              java.util.List alertRecipientsListObj,
                                              IstiRegionMgrIntf istiRegionMgrObj)
Loads the recipients specified by the "Recipient" elements in the configuration file.

Parameters:
progInfoObj - the 'QWProgramInformationInterface' object.
configRootElement - the config root element object.
alertRecipientsListObj - the alert recipients list object.
istiRegionMgrObj - region manager object to use, or null for none.
Returns:
an error message if an error occurred or null if successful.

loadRecipients

public static java.lang.String loadRecipients(QWProgramInformationInterface progInfoObj,
                                              org.jdom.Element configRootElement,
                                              java.util.List alertRecipientsListObj)
Loads the recipients specified by the "Recipient" elements in the configuration file.

Parameters:
progInfoObj - the 'QWProgramInformationInterface' object.
configRootElement - the config root element object.
alertRecipientsListObj - the alert recipients list object.
Returns:
an error message if an error occurred or null if successful.

saveRecipients

public static void saveRecipients(QWProgramInformationInterface progInfoObj,
                                  org.jdom.Element configRootElement,
                                  java.util.List alertRecipientsListObj)
Saves the recipients specified to "Recipient" elements in the configuration file.

Parameters:
progInfoObj - the 'QWProgramInformationInterface' object.
configRootElement - the config root element object.
alertRecipientsListObj - the alert recipients list object.

setRecipientName

public void setRecipientName(java.lang.String nameStr)
Sets the name value for this recipient.

Parameters:
nameStr - the name value string to use.

getRecipientName

public java.lang.String getRecipientName()
Returns the name value for this recipient.


terminateMsgQueueThread

public abstract void terminateMsgQueueThread()
Terminates the processing thread for the queue for transmitting alert messages.


toString

public abstract java.lang.String toString()
Returns a string representation of this recipient.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of this recipient.

setRecipDeletedFlag

public void setRecipDeletedFlag()
Sets the recipient-deleted flag to indicate that this recipient has been removed. This method is needed because the recipient object may still be referenced in the list of alarm recipients held by an event-message-record object.


getNumRegions

public int getNumRegions()
Gets the number of regions.

Returns:
the number of regions.

getAlarmRegionStrings

public java.lang.String[] getAlarmRegionStrings()
Returns the alarm regions for this recipient, in string format.

Returns:
A new array containing the alarm-region-text strings for this recipient, or null if no regions exist for this recipient.

getRecipDeletedFlag

public boolean getRecipDeletedFlag()
Returns the recipient-deleted flag (which indicates that this recipient has been removed). This flag is needed because the recipient object may still be referenced in the list of alarm recipients held by an event-message-record object.

Returns:
true if this recipient has been deleted.

checkAlarmEventRec

public boolean checkAlarmEventRec(QWEventMsgRecord recObj)
Determines if the given event-message record would trigger an alarm condition.

Parameters:
recObj - the message-record object for the event.
Returns:
true if the event would trigger an alarm; false if not.

sendAlertMessage

protected abstract void sendAlertMessage(QWEventMsgRecord recObj,
                                         int messageType)
Generates an alert message for the given event-message record.

Parameters:
messageType - message type value for message.
recObj - the message-record object for the event.

doSendAlertMessage

protected void doSendAlertMessage(QWEventMsgRecord recObj,
                                  int messageType)
Generates an alert message for the given event-message record.

Parameters:
messageType - message type value for message.
recObj - the message-record object for the event.

sendNewAlertMessage

public void sendNewAlertMessage(QWEventMsgRecord recObj)
Generates an "new" alert message for the given event-message record.

Parameters:
recObj - the message-record object for the event.

sendUpdateAlertMessage

public void sendUpdateAlertMessage(QWEventMsgRecord recObj)
Generates an "update" alert message for the given event-message record.

Parameters:
recObj - the message-record object for the event.

sendCancelAlertMessage

public void sendCancelAlertMessage(QWEventMsgRecord recObj)
Responds to the given deleted event-message record by generating and send a "cancelled" alert message.

Parameters:
recObj - the message-record object for the deleted event.

addToEventRecAlarmRecipList

public void addToEventRecAlarmRecipList(QWEventMsgRecord recObj)
Adds this 'AlertRecipient' object to the list of 'AlertRecipient' objects for which the given event has triggered one or more alarm-alerts.

Parameters:
recObj - the message-record object for the given event.

getEventRecAlarmRecipList

public static java.util.List getEventRecAlarmRecipList(QWEventMsgRecord recObj)
Fetches the 'List' object containing the list of 'AlertRecipient' objects for which the given event has triggered one or more alarm-alerts.

Parameters:
recObj - the message-record object for the given event.
Returns:
The 'List' object, or null if none exists for the given event-message record.

popFirstEventRecAlarmRecip

public static AlertRecipient popFirstEventRecAlarmRecip(QWEventMsgRecord recObj)
Fetches the 'List' object containing the list of 'AlertRecipient' objects for which the given event has triggered one or more alarm-alerts and removes and returns the first 'AlertRecipient' item in the list.

Parameters:
recObj - the message-record object for the given event.
Returns:
The removed 'AlertRecipient' object, or null if none exist for the given event-message record.

clearEventRecAlarmRecipList

public static void clearEventRecAlarmRecipList(QWEventMsgRecord recObj)
Clears the list of 'AlertRecipient' objects for which the given event has triggered one or more alarm-alerts. The "utility object" for the given event is set to null.

Parameters:
recObj - the message-record object for the given event.