stella.error
Class MailFinalizer

java.lang.Object
  extended by util.PropertyContainer
      extended by util.PropertyResources
          extended by util.PropertyBundles
              extended by stella.AbstractErrorFinalizer
                  extended by stella.error.MailFinalizer
All Implemented Interfaces:
Cloneable, ErrorFinalizing, Initializable, LocalizedSupplying, PropertySupplying, ResourceSupplying

public class MailFinalizer
extends AbstractErrorFinalizer

Handles error-notification by e-mail. The properties of the finalizer define whether it may be used for local or remote mail reporting, according to the error-event follow-ups ErrorEvent.MAIL_LOCAL and ErrorEvent.MAIL_HOME. Note that the type of error handled is defined in the KEY_FOLLOWUP property, in principle there is no difference in mailing to a local or remote person, except that the KEY_TO fields should differ.
The message sent back has the error event class name in its subject and the entire message in its body part. The sent date of the mail is set to the construction time of the error event.

This class relies on the mailin API provided by Sun. Ensure that the required extension, at time of writing mail.jar and activation.jar are in the CLASSPATH.


Nested Class Summary
static class MailFinalizer.Test
          A class to test mail sending after an error.
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
private static boolean DEFDEBUG
          The default debuggin mode.
private static String DEFFROM
          The default from address.
private static String DEFPASSWORD
          Default password name.
private static String DEFSMTPHOST
          The default smtphost.
private static int DEFSMTPPORT
          The default port.
private static String DEFTO
          The default to address.
private static String DEFUSERNAME
          Default user name.
private static boolean DEFUSESSL
          Default we use ssl.
private  javax.mail.Address from
          The from-address may not change.
static String KEY_BCC
          Address list of the recipients, bcc-type.
static String KEY_CC
          Address list of the recipients, cc-type.
static String KEY_DEBUG
          If true, mail-delivery is blocked for debugging mode.
static String KEY_FOLLOWUP
          One of the two follow-ups a mail finalizer can handle.
static String KEY_FROM
          Address of the sender, with or without domain.
static String KEY_TELESCOPE
          The issuing telescope.
static String KEY_TO
          Address list of the recipients, to-type.
private  Mailer mail
          The mail-session object used for transporting mails.
 
Fields inherited from class util.PropertyBundles
KEY_LOCALECOUNTRY, KEY_LOCALELANGUAGE, KEY_RESOURCEBUNDLES
 
Fields inherited from class util.PropertyResources
KEY_NOINITONCREATE, localurl, locate, POSTFIX_DIR, POSTFIX_EXT, POSTFIX_FILE, POSTFIX_LIST, POSTFIX_URL, urlset
 
Fields inherited from class util.PropertyContainer
KEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATOR
 
Fields inherited from interface util.PropertySupplying
CONFIG, KEY_CLASS
 
Fields inherited from interface util.ResourceSupplying
KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Constructor Summary
MailFinalizer(Map<String,String> prop)
          Constructs a new mail-finalizer with the distinct properties.
 
Method Summary
 boolean finalizeError(TargetDefinition ignore, ErrorEvent occur, CommandLaunching[] servers, Sequencing dummy, ParameterClustering set)
          Handles a send-mail error follow-up.
 String getFollowUp()
          Returns the follow-up this finalizer deals with.
 void init()
          On init, we try to parse the from field.
 boolean isFinalizing()
          This error finalizer is threadless, so it's finalizeError(stella.TargetDefinition, stella.ErrorEvent, stella.CommandLaunching[], stella.Sequencing, stella.ParameterClustering) method is blocking.
 
Methods inherited from class stella.AbstractErrorFinalizer
createErrorFinalizer, isAborting, setMonitor, wake
 
Methods inherited from class util.PropertyBundles
clone, getLocalized, getLocalized, getLocalizedString, getLocalizedString, loadResource
 
Methods inherited from class util.PropertyResources
createFrom, createFrom, createFrom, getApplet, getAsResources, getLocalClassLoader, getPropertiesToKey, getPropertiesToKey, getResource, getResourceAsStream, getResourceFromKey, getResources, keyCreate, keyCreate, reload, setApplet
 
Methods inherited from class util.PropertyContainer
augment, augment, augment, defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsEnums, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, isNew, parseObject, reload, removeProperty, rescanned, setObject, setProperties, setProperty, stringProperties, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface util.PropertySupplying
defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, parseObject, removeProperty, setObject, setProperty, stringProperties
 
Methods inherited from interface util.ResourceSupplying
getResource, getResourceAsStream, getResources
 

Field Detail

KEY_TELESCOPE

public static final String KEY_TELESCOPE
The issuing telescope.

See Also:
Constant Field Values

KEY_FROM

public static final String KEY_FROM
Address of the sender, with or without domain. Follow RFC822 syntax.

See Also:
Constant Field Values

KEY_TO

public static final String KEY_TO
Address list of the recipients, to-type. With or without domain.

See Also:
Constant Field Values

KEY_CC

public static final String KEY_CC
Address list of the recipients, cc-type. With or without domain.

See Also:
Constant Field Values

KEY_BCC

public static final String KEY_BCC
Address list of the recipients, bcc-type. With or without domain.

See Also:
Constant Field Values

KEY_DEBUG

public static final String KEY_DEBUG
If true, mail-delivery is blocked for debugging mode.

See Also:
Constant Field Values

KEY_FOLLOWUP

public static final String KEY_FOLLOWUP
One of the two follow-ups a mail finalizer can handle.

See Also:
Constant Field Values

DEFFROM

private static final String DEFFROM
The default from address.

See Also:
Constant Field Values

DEFSMTPHOST

private static final String DEFSMTPHOST
The default smtphost.

See Also:
Constant Field Values

DEFSMTPPORT

private static final int DEFSMTPPORT
The default port.

See Also:
Constant Field Values

DEFUSESSL

private static final boolean DEFUSESSL
Default we use ssl.

See Also:
Constant Field Values

DEFUSERNAME

private static final String DEFUSERNAME
Default user name.

See Also:
Constant Field Values

DEFPASSWORD

private static final String DEFPASSWORD
Default password name.

See Also:
Constant Field Values

DEFTO

private static final String DEFTO
The default to address.

See Also:
Constant Field Values

DEFDEBUG

private static final boolean DEFDEBUG
The default debuggin mode.

See Also:
Constant Field Values

mail

private Mailer mail
The mail-session object used for transporting mails.


from

private javax.mail.Address from
The from-address may not change.

Constructor Detail

MailFinalizer

public MailFinalizer(Map<String,String> prop)
Constructs a new mail-finalizer with the distinct properties. Make sure that the KEY_FOLLOWUP, the KEY_TO and the #KEY_SMTPHOST are present. The latter key's value is directly copied to the JavaMail required property mail.smtp.kost.

For efficiency, the mail session is initialized at finalizer construction, while the actual mail-transportation is done on error finalizing.

We use my properties to construct the Mailer instance to use.

Method Detail

init

public void init()
On init, we try to parse the from field. If that fails, we throw an IllegalArgumentException. We do not check, if a to-field exists, this is checked during error finalizing.

Specified by:
init in interface Initializable
Overrides:
init in class PropertyResources

getFollowUp

public String getFollowUp()
Returns the follow-up this finalizer deals with.


finalizeError

public boolean finalizeError(TargetDefinition ignore,
                             ErrorEvent occur,
                             CommandLaunching[] servers,
                             Sequencing dummy,
                             ParameterClustering set)
Handles a send-mail error follow-up. The recipient list is derived from the appropriate KEY_TO, KEY_CC, and KEY_BCC keys, the mail subject is the class name of the error and the mail body the human-readable part of the error. The mail date is set to the error- occurence date. If the mail was sent correctly, true is returned.


isFinalizing

public boolean isFinalizing()
This error finalizer is threadless, so it's finalizeError(stella.TargetDefinition, stella.ErrorEvent, stella.CommandLaunching[], stella.Sequencing, stella.ParameterClustering) method is blocking. This method always returns false.