Project Wonder 2.0

er.javamail
Class ERMailSender

java.lang.Object
  extended byjava.lang.Thread
      extended byer.javamail.ERMailSender
All Implemented Interfaces:
Runnable

public class ERMailSender
extends Thread

This class is used to send mails in a threaded way.
This is needed in WebObjects because if sending 20 mails takes 40 seconds, then the user must wait 40 seconds before attempting to use the application.

Author:
Camille Troillard , Tatsuya Kawano , Max Muller

Nested Class Summary
static class ERMailSender.SizeOverflowException
          Exception class for alerting about a stack overflow
 class ERMailSender.Stats
          This class is about logging mail event for stats purposes.
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Method Summary
protected  javax.mail.Transport _connectedTransportForSession(javax.mail.Session session)
          Utility method that gets the SMTP Transport method for a session and connects the Transport before returning it.
protected  void _sendMessageNow(ERMessage message, javax.mail.Transport transport)
          Common method used by 'sendMessageNow' and 'sendMessageDeffered' (actully the 'run' method when the thread is running) to send a message.
protected  void notifyInvalidEmails(Object callbackObject, NSArray invalidEmails)
          Executes the callback method to notify the calling application of any invalid emails.
 void run()
          Don't call this method, this is the thread run loop and is automatically called.
 void sendMessageDeffered(ERMessage message)
          Sends a message in a non-blocking way.
 void sendMessageNow(ERMessage message)
          Sends a message immediately.
static ERMailSender sharedMailSender()
           
 ERMailSender.Stats stats()
           
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

sharedMailSender

public static ERMailSender sharedMailSender()
Returns:
the shared instance of the singleton ERMailSender object

stats

public ERMailSender.Stats stats()
Returns:
the stats associated with this ERMailSender object

sendMessageDeffered

public void sendMessageDeffered(ERMessage message)
                         throws ERMailSender.SizeOverflowException
Sends a message in a non-blocking way.
This means that the thread won't be blocked, but the message will be queued before being delivered.

Throws:
ERMailSender.SizeOverflowException

sendMessageNow

public void sendMessageNow(ERMessage message)
Sends a message immediately.
This means that the thread could be blocked if the message takes time to be delivered.


_sendMessageNow

protected void _sendMessageNow(ERMessage message,
                               javax.mail.Transport transport)
                        throws javax.mail.MessagingException
Common method used by 'sendMessageNow' and 'sendMessageDeffered' (actully the 'run' method when the thread is running) to send a message.
This method sends the message and increments the processed mail count. If an exception occurs while sending the mail, and if a callback object has been given, the notifyInvalidEmails method is called.
If a MessagingException is thrown, then the exception is catched and rethrown immediately, thus letting us to process another callbacks or not. For example, This is used when sendMessageNow is used, the MessagingException is encapsulated in a ERMailSender.ForwardException, and thrown to the user.

Throws:
javax.mail.MessagingException

_connectedTransportForSession

protected javax.mail.Transport _connectedTransportForSession(javax.mail.Session session)
Utility method that gets the SMTP Transport method for a session and connects the Transport before returning it.


run

public void run()
Don't call this method, this is the thread run loop and is automatically called.


notifyInvalidEmails

protected void notifyInvalidEmails(Object callbackObject,
                                   NSArray invalidEmails)
Executes the callback method to notify the calling application of any invalid emails.


Last updated: Do, Dez 9, 2004 • 12:46 PM CET

Copyright © 2002 – 2004 Project Wonder.