TerribleFailureEmailHandler

public class TerribleFailureEmailHandler
extends Object implements ITerribleFailureHandler

java.lang.Object
   ↳ com.android.tradefed.log.TerribleFailureEmailHandler


A simple handler class that sends an email to interested people when a WTF (What a Terrible Failure) error occurs within a Trade Federation instance.

Summary

Public constructors

TerribleFailureEmailHandler()

Create a TerribleFailureEmailHandler

Protected constructors

TerribleFailureEmailHandler(IEmail mailer)

Create a TerribleFailureEmailHandler with a custom IEmail instance to use.

Public methods

void addDestination(String dest)

Adds an email destination address.

boolean onTerribleFailure(String description, Throwable cause)

Triggered when a terrible failure occurs in wtf(String, Throwable)

void setMinEmailInterval(long interval)

Sets the minimum email interval.

void setSender(String sender)

Sets the email sender address.

Protected methods

String generateEmailBody(String message, Throwable cause)

A method to generate the body for WTF email reports.

IEmail.Message generateEmailMessage(String description, Throwable cause)

Generates a new email message based on the attributes already gathered (subject, sender, destinations), as well as the description and cause (Optional)

String generateEmailSubject()

A method to generate the subject for email reports.

long getCurrentTimeMillis()

Gets the current time in milliseconds.

String getLocalHostName()

Gets the local host name of the machine.

Public constructors

TerribleFailureEmailHandler

TerribleFailureEmailHandler ()

Create a TerribleFailureEmailHandler

Protected constructors

TerribleFailureEmailHandler

TerribleFailureEmailHandler (IEmail mailer)

Create a TerribleFailureEmailHandler with a custom IEmail instance to use.

Exposed for unit testing.

Parameters
mailer IEmail: the IEmail instance to use.

Public methods

addDestination

void addDestination (String dest)

Adds an email destination address.

onTerribleFailure

boolean onTerribleFailure (String description, 
                Throwable cause)

Triggered when a terrible failure occurs in wtf(String, Throwable)

Parameters
description String: a summary of the terrible failure that occurred
cause Throwable: (Optional) contains the stack trace of the terrible failure
Returns
boolean true on being handled successfully, false otherwise

setMinEmailInterval

void setMinEmailInterval (long interval)

Sets the minimum email interval.

setSender

void setSender (String sender)

Sets the email sender address.

Protected methods

generateEmailBody

String generateEmailBody (String message, 
                Throwable cause)

A method to generate the body for WTF email reports.

Parameters
message String: summary of the terrible failure
cause Throwable: throwable containing stack trace information
Returns
String A String containing the body to use for an email report

generateEmailMessage

IEmail.Message generateEmailMessage (String description, 
                Throwable cause)

Generates a new email message based on the attributes already gathered (subject, sender, destinations), as well as the description and cause (Optional)

Parameters
description String: Summary of the terrible failure
cause Throwable: (Optional) Throwable that includes stack trace info
Returns
IEmail.Message Message object with all email attributes populated

generateEmailSubject

String generateEmailSubject ()

A method to generate the subject for email reports. The subject will be formatted as: " on "

Returns
String A String containing the subject to use for an email report

getCurrentTimeMillis

long getCurrentTimeMillis ()

Gets the current time in milliseconds.

Returns
long

getLocalHostName

String getLocalHostName ()

Gets the local host name of the machine.

Returns
String the name of the host machine, or "unknown host" if unknown