atg.service.email
Class BatchEmailListener

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.service.email.BatchEmailListener
All Implemented Interfaces:
atg.naming.AbsoluteNameable, NameContextBindingListener, NameContextElement, atg.naming.NameContextParentable, NameResolver, AdminableService, atg.nucleus.Configured, ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, VariableArgumentApplicationLogging, ComponentNameResolver, Service, ServiceListener, EmailListener, Schedulable, java.util.EventListener

public class BatchEmailListener
extends GenericService
implements EmailListener, Schedulable

An EmailListener that batches up EmailEvent objects and periodically sends out corresponding pieces of email using an EmailMessageSender. Each batch of email messages is sent using a single connection to the mail server.

Two properties control how often the batch sends are performed - maxBatchSize and sendSchedule. If maxBatchSize is specified, a send is performed whenever the number of batched email events reaches maxBatchSize. Also, if sendSchedule is specified, sends are performed according to the schedule. At least one of these properties must be specified for the service to function properly.

Since the sendEmailEvent method may result in a batch send of all the collected events (if the number of events reaches maxBatchSize), you should not use the BatchEmailListener service directly, but rather in conjunction with the EmailListenerQueue (i.e., configure the EmailListenerQueue to have BatchEmailListener as a listener).


Field Summary
static java.lang.String CLASS_VERSION
          Class version string
 
Fields inherited from class atg.nucleus.GenericService
SERVICE_INFO_KEY
 
Fields inherited from interface atg.nucleus.logging.TraceApplicationLogging
DEFAULT_LOG_TRACE_STATUS
 
Fields inherited from interface atg.nucleus.logging.ApplicationLogging
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
 
Constructor Summary
BatchEmailListener()
           
 
Method Summary
 void clearDeadEmailEvents()
          Clears the current dead email queue
 void doStartService()
          Called after the service has been created, placed into the naming hierarchy, and initialized with its configured property values.
 void doStopService()
          Called when the service is required to shut down.
 Schedule getClearDeadEmailSchedule()
          Returns the Schedule for clearing the Dead Email Queue.
 int getDeadEmailCount()
          Gets the number of dead letters (letters that couldn't be sent due to errors)
 java.util.Dictionary getDeadEmailDictionary()
          Returns a Dictionary object with each row consisting of an undelivered EmailEvent and its corresponding EmailException
 java.util.Enumeration getDeadEmailEvents()
          Returns an Enumeration of undelivered EmailEvent objects
 java.util.Enumeration getDeadEmailExceptions()
          Returns an Enumeration of EmailExceptions that belong to undelivered EmailEvents
 EmailMessageSender getEmailMessageSender()
          Returns the EmailMessageSender used to send email.
 int getMaxBatchSize()
          Returns the maximum number of EmailEvents that will be batched before a send is performed.
 Scheduler getScheduler()
          Returns the Scheduler responsible for scheduling batch sends.
 Schedule getSendSchedule()
          Returns the Schedule for perfoming batch sends.
 boolean isCollectDeadEmail()
           
 void performScheduledTask(Scheduler pScheduler, ScheduledJob pJob)
          Called when a scheduled job tied to this object occurs.
 void sendDeadEmail()
          Sends all of the email currently in the dead letter queue.
 void sendEmailEvent(EmailEvent pEvent)
          Adds the given email event to the internal batch queue.
 void setClearDeadEmailSchedule(Schedule pClearDeadEmailSchedule)
          Sets the Schedule for clearing the Dead Email Queue.
 void setCollectDeadEmail(boolean p)
           
 void setEmailMessageSender(EmailMessageSender pSender)
          Sets the EmailMessageSender used to send email.
 void setMaxBatchSize(int pMaxBatchSize)
          Sets the maximum number of EmailEvents that will be batched before a send is performed.
 void setScheduler(Scheduler pScheduler)
          Sets the Scheduler responsible for scheduling batch sends.
 void setSendSchedule(Schedule pSendSchedule)
          Sets the Schedule for perfoming batch sends.
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, createAdminServlet, getAbsoluteName, getAdminServlet, getAdminServletOutputStreamEncoding, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isAdminServletUseServletOutputStream, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingTrace, isLoggingWarning, isRunning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, nameContextElementBound, nameContextElementUnbound, removeLogListener, reResolveThis, resolveName, resolveName, resolveName, resolveName, sendLogEvent, setAdminServletOutputStreamEncoding, setAdminServletUseServletOutputStream, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning, setNucleus, setServiceInfo, startService, stopService
 
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogDebugTrace, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Class version string

Constructor Detail

BatchEmailListener

public BatchEmailListener()
Method Detail

getEmailMessageSender

public EmailMessageSender getEmailMessageSender()
Returns the EmailMessageSender used to send email.


setEmailMessageSender

public void setEmailMessageSender(EmailMessageSender pSender)
Sets the EmailMessageSender used to send email.


getMaxBatchSize

public int getMaxBatchSize()
Returns the maximum number of EmailEvents that will be batched before a send is performed. If zero, no maximum is assumed - the events will keep accumulating until sent by some other means (e.g., via the schedule).


setMaxBatchSize

public void setMaxBatchSize(int pMaxBatchSize)
Sets the maximum number of EmailEvents that will be batched before a send is performed. If zero, no maximum is assumed - the events will keep accumulating until sent by some other means (e.g., via the schedule).


getScheduler

public Scheduler getScheduler()
Returns the Scheduler responsible for scheduling batch sends.


setScheduler

public void setScheduler(Scheduler pScheduler)
Sets the Scheduler responsible for scheduling batch sends.


getSendSchedule

public Schedule getSendSchedule()
Returns the Schedule for perfoming batch sends.


setSendSchedule

public void setSendSchedule(Schedule pSendSchedule)
Sets the Schedule for perfoming batch sends.


getClearDeadEmailSchedule

public Schedule getClearDeadEmailSchedule()
Returns the Schedule for clearing the Dead Email Queue.


setClearDeadEmailSchedule

public void setClearDeadEmailSchedule(Schedule pClearDeadEmailSchedule)
Sets the Schedule for clearing the Dead Email Queue.


setCollectDeadEmail

public void setCollectDeadEmail(boolean p)

isCollectDeadEmail

public boolean isCollectDeadEmail()

getDeadEmailCount

public int getDeadEmailCount()
Gets the number of dead letters (letters that couldn't be sent due to errors)


getDeadEmailDictionary

public java.util.Dictionary getDeadEmailDictionary()
Returns a Dictionary object with each row consisting of an undelivered EmailEvent and its corresponding EmailException


getDeadEmailEvents

public java.util.Enumeration getDeadEmailEvents()
Returns an Enumeration of undelivered EmailEvent objects


getDeadEmailExceptions

public java.util.Enumeration getDeadEmailExceptions()
Returns an Enumeration of EmailExceptions that belong to undelivered EmailEvents


clearDeadEmailEvents

public void clearDeadEmailEvents()
Clears the current dead email queue


sendDeadEmail

public void sendDeadEmail()
Sends all of the email currently in the dead letter queue. Be aware that some emails may be undeliverable and might end up right back in the dead letter queue. As such, it is advised to use either the getDeadEmailDictionary or getDeadEmailExceptions method to examine the reason why the email wasn't sent before using this method.


sendEmailEvent

public void sendEmailEvent(EmailEvent pEvent)
                    throws EmailException
Adds the given email event to the internal batch queue. If the number of events reaches maxBatchSize, this also causes all the collected events to be sent as email messages.

Specified by:
sendEmailEvent in interface EmailListener
Throws:
EmailException

performScheduledTask

public void performScheduledTask(Scheduler pScheduler,
                                 ScheduledJob pJob)
Called when a scheduled job tied to this object occurs.

Specified by:
performScheduledTask in interface Schedulable
Parameters:
pScheduler - calling the job
pJob - the ScheduledJob

doStartService

public void doStartService()
                    throws ServiceException
Called after the service has been created, placed into the naming hierarchy, and initialized with its configured property values.

Overrides:
doStartService in class GenericService
Throws:
ServiceException - if the service had a problem starting up

doStopService

public void doStopService()
                   throws ServiceException
Called when the service is required to shut down.

Overrides:
doStopService in class GenericService
Throws:
ServiceException - if the service had a problem shutting down