ejel
Class SenderEngine

java.lang.Object
  extended by java.lang.Thread
      extended by ejel.SenderEngine
All Implemented Interfaces:
java.lang.Runnable

public class SenderEngine
extends java.lang.Thread

The EMMR Java Emailer Library Sender Engine Class


Nested Class Summary
static class SenderEngine.RecipientsType
          Define the recipients type of the emails to send
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static long SLEEP_TIME
          Sleep time in millis while waiting for an event
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
SenderEngine(Email emailMsg, int rcptPerEmail, int maxCon)
          SenderEngine objects constructor
 
Method Summary
 boolean abortEngine()
          Raises the EventID.EID_ABORTED and abort the mass mailing operation
 void addAttachment(java.lang.String fileName)
          Adds a new attachment file to the main list for the mass mailing operation
 int addAttachments(Attachment[] atchmnts)
          Adds new Attachment objects into the main attachments list
 void addEmailAccount(EmailAccount account)
          Adds a new EmailAccount object in the main list for the mass mailing operation
 int addEmailAccounts(EmailAccount[] accounts)
          Adds new EmailAccount objects to the email accounts mail list
 void addExtraHeader(java.lang.String header)
          Adds an extra header to be included in each sent email
 int addExtraHeaders(java.lang.String[] headers)
          Adds new headers to the main email headers list
 void addRecipient(Recipient recipient)
          Add a new Recipient object to the Recipients list
 int addRecipients(Recipient[] rcpts)
          Adds one or more Recipient objects in the main list
 int getActiveConnectionsCount()
          Gets the number of current active connections/send operations
 Attachment getAttachmentAt(int index)
          Gets the Attachment object at the specified index param
 EmailAccount getEmailAccountAt(int index)
          Gets the EmailAccount at the specified index param
 int getEmailsSentCount()
          Gets the number of sent emails during the mass mailing operation
 int getErrorsCount()
          Gets the number of errors/exceptions occured since the start of the mass mailing operation
 int getMaxConnections()
          Gets the maximum number of simultanous connections/sender threads/send operations
 Recipient getRecipientAt(int index)
          Gets the Recipient object at the specified index param
 int getRecipientsPerEmail()
          Gets the number of recipients per one email send
 SenderEngine.RecipientsType getRecipientsType()
          Gets the recipients type of the emails to be sent
 boolean isAborted()
          Gets if the mass mailing operation is aborted
 boolean isFinished()
          Gets if the mass mailing operation is totally finished
 boolean isFinishing()
          Gets if the mass mainling operation is currently finishing
 boolean isModifiable()
          Gets wheter or not external code can modify/alter Sender engine data.
 boolean isPaused()
          Gets if the mass mailing operation is currently paused
 boolean isPausing()
          Gets true if external code ordered the Sender engine to pause and this one is waiting for SenderThreads to terminate their current send operations and switch to ready mode.
 boolean isRunning()
          Gets if the mass mailing operation is currently running
 boolean isStarted()
          Gets if the mass mailing operation is started
 boolean pauseEngine()
          Raises the EventID.EID_PAUSING event and if it's not cancelled, the Sender engine is paused and the EventID.EID_PAUSED event is raised when all SenderThreads terminate their send operations and switch to ready mode.
 void registerEventListener(EventManager.EventID evId, EventListener listener)
          Register an object listener for a specified event
 boolean resumeEngine()
          Raises the EventID.EID_RESUMING event and if it's not cancelled, the Sender engine is resumed and the EventID.EID_RESUMED event is raised.
 void run()
          The overriden Thread.run() which contains the Sender engine internal loop
 void setRecipientsType(SenderEngine.RecipientsType rcptsType)
          Sets the recipients type of the emails to be sent
 boolean startEngine()
          Starts the Sender engine and raises the EventID.EID_STARTED
 void unregisterEventListener(EventManager.EventID evId, EventListener listener)
          Unregister an object listener from the event manager for the event ID
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, 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
 

Field Detail

SLEEP_TIME

public static final long SLEEP_TIME
Sleep time in millis while waiting for an event

See Also:
Constant Field Values
Constructor Detail

SenderEngine

public SenderEngine(Email emailMsg,
                    int rcptPerEmail,
                    int maxCon)
             throws java.lang.IllegalArgumentException
SenderEngine objects constructor

Parameters:
emailMsg - Email object representing the email to send to recipients
rcptPerEmail - Number of recipients per email
maxCon - Number of simultanous connections/threads/send operations
Throws:
java.lang.IllegalArgumentException
Method Detail

isPausing

public boolean isPausing()
Gets true if external code ordered the Sender engine to pause and this one is waiting for SenderThreads to terminate their current send operations and switch to ready mode.

Returns:
true if SenderEngine is currently pausing

getActiveConnectionsCount

public int getActiveConnectionsCount()
Gets the number of current active connections/send operations

Returns:
The number of current active connections/send operations

getEmailsSentCount

public int getEmailsSentCount()
Gets the number of sent emails during the mass mailing operation

Returns:
The number of sent emails during the mass mailing operation

isModifiable

public boolean isModifiable()
Gets wheter or not external code can modify/alter Sender engine data. External code must check the returned value before trying to modify/alter the object.

Returns:
true if the Sender engine can be modified/altered

addRecipient

public void addRecipient(Recipient recipient)
                  throws java.lang.UnsupportedOperationException
Add a new Recipient object to the Recipients list

Parameters:
recipient - A Recipient object representing a recipient email address
Throws:
java.lang.UnsupportedOperationException

addEmailAccount

public void addEmailAccount(EmailAccount account)
                     throws java.lang.UnsupportedOperationException
Adds a new EmailAccount object in the main list for the mass mailing operation

Parameters:
account - EmailAccount object representing an email account used to send emails to recipients
Throws:
java.lang.UnsupportedOperationException

addAttachment

public void addAttachment(java.lang.String fileName)
                   throws java.lang.UnsupportedOperationException
Adds a new attachment file to the main list for the mass mailing operation

Parameters:
fileName - File name of the new attached file
Throws:
java.lang.UnsupportedOperationException

getRecipientAt

public Recipient getRecipientAt(int index)
                         throws java.lang.IndexOutOfBoundsException
Gets the Recipient object at the specified index param

Parameters:
index - Index of the Recipient to be retrieved
Returns:
The Recipient object at the specified index param
Throws:
java.lang.IndexOutOfBoundsException

getEmailAccountAt

public EmailAccount getEmailAccountAt(int index)
                               throws java.lang.IndexOutOfBoundsException
Gets the EmailAccount at the specified index param

Parameters:
index - Index of the EmailAccount to be retrieved
Returns:
The EmailAccount at the specified index param
Throws:
java.lang.IndexOutOfBoundsException

getAttachmentAt

public Attachment getAttachmentAt(int index)
                           throws java.lang.IndexOutOfBoundsException
Gets the Attachment object at the specified index param

Parameters:
index - Index of the Attachment object to be retrieved
Returns:
The Attachment object at the specified index param
Throws:
java.lang.IndexOutOfBoundsException

startEngine

public boolean startEngine()
                    throws java.lang.IllegalStateException
Starts the Sender engine and raises the EventID.EID_STARTED

Returns:
true if the Sender engine start operation succeeds
Throws:
java.lang.IllegalStateException

pauseEngine

public boolean pauseEngine()
Raises the EventID.EID_PAUSING event and if it's not cancelled, the Sender engine is paused and the EventID.EID_PAUSED event is raised when all SenderThreads terminate their send operations and switch to ready mode.

Returns:
true if the sender engine is paused successfully

resumeEngine

public boolean resumeEngine()
Raises the EventID.EID_RESUMING event and if it's not cancelled, the Sender engine is resumed and the EventID.EID_RESUMED event is raised.

Returns:
true if the Sender engine execution is successfully resumed

abortEngine

public boolean abortEngine()
Raises the EventID.EID_ABORTED and abort the mass mailing operation

Returns:
true if the abort order succeeds

registerEventListener

public void registerEventListener(EventManager.EventID evId,
                                  EventListener listener)
                           throws java.lang.IllegalArgumentException,
                                  java.lang.UnsupportedOperationException
Register an object listener for a specified event

Parameters:
evId - ID of the event associated with the object listener
listener - The object listener associated with the event ID
Throws:
java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException

unregisterEventListener

public void unregisterEventListener(EventManager.EventID evId,
                                    EventListener listener)
                             throws java.lang.IllegalArgumentException,
                                    java.lang.UnsupportedOperationException
Unregister an object listener from the event manager for the event ID

Parameters:
evId - ID of the event to unregister the listener's object
listener - The listener's object to unregister from the event manager
Throws:
java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException

run

public void run()
The overriden Thread.run() which contains the Sender engine internal loop

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

isAborted

public boolean isAborted()
Gets if the mass mailing operation is aborted

Returns:
true if the mass mailing operation is aborted

isPaused

public boolean isPaused()
Gets if the mass mailing operation is currently paused

Returns:
true if the mass mailing operation is currently paused

isRunning

public boolean isRunning()
Gets if the mass mailing operation is currently running

Returns:
true if the mass mailing operation is currently running

isFinishing

public boolean isFinishing()
Gets if the mass mainling operation is currently finishing

Returns:
true if the mass mainling operation is currently finishing

isFinished

public boolean isFinished()
Gets if the mass mailing operation is totally finished

Returns:
true if the mass mailing operation is totally finished

isStarted

public boolean isStarted()
Gets if the mass mailing operation is started

Returns:
true if the mass mailing operation is started

getRecipientsPerEmail

public int getRecipientsPerEmail()
Gets the number of recipients per one email send

Returns:
The number of recipients per one email send

getMaxConnections

public int getMaxConnections()
Gets the maximum number of simultanous connections/sender threads/send operations

Returns:
The maximum number of simultanous connections/sender threads/send operations

getErrorsCount

public int getErrorsCount()
Gets the number of errors/exceptions occured since the start of the mass mailing operation

Returns:
The number of errors/exceptions occured since the start of the mass mailing operation

addExtraHeader

public void addExtraHeader(java.lang.String header)
                    throws java.lang.IllegalArgumentException,
                           java.lang.UnsupportedOperationException
Adds an extra header to be included in each sent email

Parameters:
header - Email header to be added in the headers list
Throws:
java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException

addRecipients

public int addRecipients(Recipient[] rcpts)
                  throws java.lang.IllegalArgumentException,
                         java.lang.UnsupportedOperationException
Adds one or more Recipient objects in the main list

Parameters:
rcpts - An array of Recipient objects to add in the main recipients list
Returns:
The number of Recipient objects added to the main recipients list
Throws:
java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException

addEmailAccounts

public int addEmailAccounts(EmailAccount[] accounts)
                     throws java.lang.IllegalArgumentException,
                            java.lang.UnsupportedOperationException
Adds new EmailAccount objects to the email accounts mail list

Parameters:
accounts - An array of EmailAccount objects to add into the mail list
Returns:
The number of EmailAccount objects added to the email accounts main list
Throws:
java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException

addAttachments

public int addAttachments(Attachment[] atchmnts)
                   throws java.lang.IllegalArgumentException,
                          java.lang.UnsupportedOperationException
Adds new Attachment objects into the main attachments list

Parameters:
atchmnts - An array of Attachment objects to add in the main list
Returns:
The number of Attachment objects added to the attachments main list
Throws:
java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException

addExtraHeaders

public int addExtraHeaders(java.lang.String[] headers)
                    throws java.lang.IllegalArgumentException,
                           java.lang.UnsupportedOperationException
Adds new headers to the main email headers list

Parameters:
headers - An array of Strings objects representing the extra headers to add to the main list
Returns:
The number of headers added into the headers main list
Throws:
java.lang.IllegalArgumentException
java.lang.UnsupportedOperationException

setRecipientsType

public void setRecipientsType(SenderEngine.RecipientsType rcptsType)
                       throws java.lang.UnsupportedOperationException
Sets the recipients type of the emails to be sent

Parameters:
rcptsType - Type of the recipients TO, CC or BCC
Throws:
java.lang.UnsupportedOperationException

getRecipientsType

public SenderEngine.RecipientsType getRecipientsType()
Gets the recipients type of the emails to be sent

Returns:
the recipients type of the emails to be sent