com.isti.quakewatch.alertemail
Class AlertEmailSender

java.lang.Object
  extended by com.isti.quakewatch.alertemail.AlertEmailSender
All Implemented Interfaces:
AlertSenderInterface, AlertEmailSenderInterface

public class AlertEmailSender
extends java.lang.Object
implements AlertEmailSenderInterface

Class AlertEmailSender defines an alert email sender.


Field Summary
protected  AlertMsgDateFormatterInterface alertMsgDateFormat
          The alert message date formatter.
protected  boolean alertSenderTestModeFlag
          Test mode flag.
 CfgPropItem dontCheckSMTPFlagProp
          Flag set true to not check SMTP email server.
 CfgPropItem emailFromAddressProp
          'From' email-address for messages.
 CfgPropItem emailFromNameProp
          'From' real-name for messages.
protected  java.lang.String emailPropsGroupStr
          The configuration group string.
protected  JavaMailUtil javaMailUtilObj
          JavaMail utility object.
protected  AlertEmailRecipientInterface lastSendMsgRecipObj
          Recipient tracking object for 'sendEmailMessage()' method.
protected  boolean lastSendSuccessfulFlag
          Send-result tracking flag for 'sendEmailMessage()' method.
 CfgPropItem localTimeZoneProp
          Local time zone for messages.
protected  LocationPlacesInterface locationPlacesObj
          The location places.
protected  int MAX_RESEND_WAITMS
          Maximum wait time between email-resend attempts (ms).
 CfgPropItem maxSendMailRetriesProp
          Maximum number of send-mail retries after failure.
protected  java.lang.String programRevisionText
          The program revision text.
protected  java.lang.Object sendEmailMsgSyncObj
          Thread-synchronization object for 'sendEmailMessage()' method.
protected  int sendMsgRetryWaitMs
          Send-message retry-wait-delay for 'sendEmailMessage()' method.
protected  CfgProperties settingsProps
          Configuration properties object.
 CfgPropItem smtpServerAddressProp
          Address of SMTP server for sending mail.
 CfgPropItem useGMTShortFlagProp
          Flag set true to use GMT for date/times in short messages.
 
Constructor Summary
AlertEmailSender(CfgProperties settingsProps, java.lang.String programRevisionText, AlertMsgDateFormatterInterface alertMsgDateFormat, LocationPlacesInterface locationPlacesObj, boolean alertSenderTestModeFlag, java.lang.String emailPropsGroupStr)
          Creates an alert email message sender.
 
Method Summary
 boolean areEmailPropsReady()
          Determines if the email-related configuration-property items have been entered.
 AlertMsgDateFormatterInterface getAlertMsgDateFormatter()
          Gets the alert message date formatter.
 java.lang.String getDisplayStr()
          Returns a display string containing the 'From' email address and name for messages.
 java.lang.String getEmailPropsGroup()
          Gets the group string that are used for the properties.
 JavaMailUtil getJavaMailUtilObj()
          Returns the JavaMail utility object.
 java.util.TimeZone getLocalTimeZone()
          Get the local time zone.
 LocationPlacesInterface getLocationPlaces()
          Gets the location places.
 int getMaxSendMessageRetries()
          Returns the maximum number of retries to attempt when the sending of an alert message is failing.
 java.lang.String getProgramRevisionText()
          Gets the program revision text.
 boolean isTestMode()
          Determines if in test mode and test messages are to be used.
 boolean sendEmailMessage(AlertEmailRecipientInterface recipObj, AlertEmailMessageInterface emailMsgObj)
          Sends an email message using the given parameters.
 boolean sendMessage(AlertRecipient recipObj, java.lang.Object alertMsgObj)
          Sends an alert message using the given parameters.
 void setProgramRevisionText(java.lang.String programRevisionText)
          Sets the program revision text.
 void updateLocalTimeZone(boolean updateShortFlag)
          Updates the date formatters that use the local-time-zone configuration property.
 void updateShortDateFmtZone()
          Updates the time zone for the date formatter used for short messages.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sendEmailMsgSyncObj

protected final java.lang.Object sendEmailMsgSyncObj
Thread-synchronization object for 'sendEmailMessage()' method.


lastSendMsgRecipObj

protected AlertEmailRecipientInterface lastSendMsgRecipObj
Recipient tracking object for 'sendEmailMessage()' method.


lastSendSuccessfulFlag

protected boolean lastSendSuccessfulFlag
Send-result tracking flag for 'sendEmailMessage()' method.


sendMsgRetryWaitMs

protected int sendMsgRetryWaitMs
Send-message retry-wait-delay for 'sendEmailMessage()' method.


javaMailUtilObj

protected final JavaMailUtil javaMailUtilObj
JavaMail utility object.


MAX_RESEND_WAITMS

protected final int MAX_RESEND_WAITMS
Maximum wait time between email-resend attempts (ms).

See Also:
Constant Field Values

settingsProps

protected final CfgProperties settingsProps
Configuration properties object.


programRevisionText

protected java.lang.String programRevisionText
The program revision text.


alertMsgDateFormat

protected final AlertMsgDateFormatterInterface alertMsgDateFormat
The alert message date formatter.


locationPlacesObj

protected final LocationPlacesInterface locationPlacesObj
The location places.


alertSenderTestModeFlag

protected final boolean alertSenderTestModeFlag
Test mode flag.


emailPropsGroupStr

protected final java.lang.String emailPropsGroupStr
The configuration group string.


emailFromNameProp

public final CfgPropItem emailFromNameProp
'From' real-name for messages.


emailFromAddressProp

public final CfgPropItem emailFromAddressProp
'From' email-address for messages.


smtpServerAddressProp

public final CfgPropItem smtpServerAddressProp
Address of SMTP server for sending mail.


maxSendMailRetriesProp

public final CfgPropItem maxSendMailRetriesProp
Maximum number of send-mail retries after failure.


localTimeZoneProp

public final CfgPropItem localTimeZoneProp
Local time zone for messages.


useGMTShortFlagProp

public final CfgPropItem useGMTShortFlagProp
Flag set true to use GMT for date/times in short messages.


dontCheckSMTPFlagProp

public final CfgPropItem dontCheckSMTPFlagProp
Flag set true to not check SMTP email server.

Constructor Detail

AlertEmailSender

public AlertEmailSender(CfgProperties settingsProps,
                        java.lang.String programRevisionText,
                        AlertMsgDateFormatterInterface alertMsgDateFormat,
                        LocationPlacesInterface locationPlacesObj,
                        boolean alertSenderTestModeFlag,
                        java.lang.String emailPropsGroupStr)
Creates an alert email message sender.

Parameters:
settingsProps - the 'CfgProperties' object.
programRevisionText - the program revision text.
alertMsgDateFormat - the alert message date formatter.
locationPlacesObj - the location places.
alertSenderTestModeFlag - true for test messages, false otherwise.
emailPropsGroupStr - the group string to use for the properties.
See Also:
setProgramRevisionText.
Method Detail

areEmailPropsReady

public final boolean areEmailPropsReady()
Determines if the email-related configuration-property items have been entered.

Returns:
true if the email-related configuration-property items have been entered; false if not.

getAlertMsgDateFormatter

public AlertMsgDateFormatterInterface getAlertMsgDateFormatter()
Gets the alert message date formatter.

Specified by:
getAlertMsgDateFormatter in interface AlertEmailSenderInterface
Returns:
the alert message date formatter

getDisplayStr

public java.lang.String getDisplayStr()
Returns a display string containing the 'From' email address and name for messages. The format of string is: "name" .

Specified by:
getDisplayStr in interface AlertSenderInterface
Returns:
A display string containing the 'From' email address and name for messages.

getEmailPropsGroup

public java.lang.String getEmailPropsGroup()
Gets the group string that are used for the properties.

Returns:
the group string that are used for the properties.

getJavaMailUtilObj

public JavaMailUtil getJavaMailUtilObj()
Returns the JavaMail utility object.

Specified by:
getJavaMailUtilObj in interface AlertEmailSenderInterface
Returns:
The JavaMail utility object.

getLocalTimeZone

public java.util.TimeZone getLocalTimeZone()
Get the local time zone.

Returns:
the local time zone.

getLocationPlaces

public LocationPlacesInterface getLocationPlaces()
Gets the location places.

Specified by:
getLocationPlaces in interface AlertEmailSenderInterface
Returns:
the location places.

getMaxSendMessageRetries

public int getMaxSendMessageRetries()
Returns the maximum number of retries to attempt when the sending of an alert message is failing.

Specified by:
getMaxSendMessageRetries in interface AlertSenderInterface
Returns:
The maximum number of send alert message retries after failure.

getProgramRevisionText

public java.lang.String getProgramRevisionText()
Gets the program revision text.

Specified by:
getProgramRevisionText in interface AlertEmailSenderInterface
Returns:
the program revision text or null if not available.
See Also:
setProgramRevisionText.

isTestMode

public boolean isTestMode()
Determines if in test mode and test messages are to be used.

Specified by:
isTestMode in interface AlertEmailSenderInterface
Returns:
true for test messages, false otherwise.

sendMessage

public boolean sendMessage(AlertRecipient recipObj,
                           java.lang.Object alertMsgObj)
Sends an alert message using the given parameters. If the previous send attempt failed then this method may perform a wait-delay before sending the message.

Specified by:
sendMessage in interface AlertSenderInterface
Parameters:
recipObj - the alert recipient for the message.
alertMsgObj - the alert message object.
Returns:
true if successful; false if not (in which case a warning message will be logged).

sendEmailMessage

public boolean sendEmailMessage(AlertEmailRecipientInterface recipObj,
                                AlertEmailMessageInterface emailMsgObj)
Sends an email message using the given parameters. A "date" header showing the current date will be included in the message. If the previous send attempt failed then this method may perform a wait-delay before sending the message.

Specified by:
sendEmailMessage in interface AlertEmailSenderInterface
Parameters:
recipObj - the alert recipient for the message.
emailMsgObj - the message object for holding the message.
Returns:
true if successful; false if not (in which case a warning message will be logged).

setProgramRevisionText

public void setProgramRevisionText(java.lang.String programRevisionText)
Sets the program revision text.

Parameters:
programRevisionText - the program revision text.

updateLocalTimeZone

public void updateLocalTimeZone(boolean updateShortFlag)
Updates the date formatters that use the local-time-zone configuration property.

Parameters:
updateShortFlag - true to always update the the date formatter used for short messages.

updateShortDateFmtZone

public void updateShortDateFmtZone()
Updates the time zone for the date formatter used for short messages.