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 LogUtil.CLog.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

public TerribleFailureEmailHandler ()

Create a TerribleFailureEmailHandler

Protected constructors

TerribleFailureEmailHandler

protected 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

public void addDestination (String dest)

Adds an email destination address.

onTerribleFailure

public boolean onTerribleFailure (String description, 
                Throwable cause)

Triggered when a terrible failure occurs in LogUtil.CLog.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

public void setMinEmailInterval (long interval)

Sets the minimum email interval.

setSender

public void setSender (String sender)

Sets the email sender address.

Protected methods

generateEmailBody

protected 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

protected 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

protected 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

protected long getCurrentTimeMillis ()

Gets the current time in milliseconds.

Returns
long

getLocalHostName

protected String getLocalHostName ()

Gets the local host name of the machine.

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