public class MailEventSource extends AbstractEventSource<MailEvent> implements PollingMailSource
| Modifier and Type | Field and Description |
|---|---|
protected java.net.URI[] |
eventManagerURIs
The event manager URIs to provide to the created events.
|
protected java.lang.String |
folderName
The name of the folder which causes an event when a new mail is received.
|
protected java.lang.String |
host
The host to connect to and from which to use as mail source.
|
protected boolean |
keepConnection
Whether the mail storage should not be disconnected between polls.
|
protected java.lang.String |
password
The password to connect to the host with.
|
protected java.lang.Long |
pollTime
The time in milliseconds this event source polls its data source.
|
protected int |
port
The port of the host to which to connect to.
|
protected java.lang.String |
protocol
The protocol to use for this mail events, for instance pop3, imap, ...
|
protected java.lang.Long |
startPoint
The start point (in milliseconds) this event should start polling.
|
protected javax.mail.Store |
store
The mail server which to check for mails.
|
protected long |
timeout
The timeout in milliseconds this event source uses for the mail server.
|
protected java.lang.String |
userName
The user name to connect to the host with.
|
eventType, handlerList, id, lock, logger, sourceType, thread, threadLockCONF_KEEP_CONNECTIONCONF_POLL_TIME, CONF_START_TIMECONF_FOLDER, CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_PROTOCOL, CONF_TIMEOUT, CONF_USER_NAME| Modifier | Constructor and Description |
|---|---|
|
MailEventSource(Configuration conf,
EventManager eventManager,
Registry registry)
Default constructor for a plugin of an
EventManager called by
a service registry. |
protected |
MailEventSource(Configuration conf,
EventManager eventManager,
Registry registry,
java.lang.Class<?> confDesc)
Constructor for subclasses allowing to set a separate class for the
configuration description.
|
| Modifier and Type | Method and Description |
|---|---|
void |
checkForAndHandleEvent()
Checks for an event and handles it (usually by using
AbstractEventSource.forwardEvent(Event, boolean, boolean)). |
protected void |
close(javax.mail.Folder folder)
Closes and expunges the designated folder if it is open.
|
protected void |
closeStore()
Closes the message store of this event source.
|
protected void |
connectToStore()
Connects to the configured store of this event source.
|
protected MailEvent |
createMailEvent(javax.mail.Message message)
Creates a
MailEvent for the designated message. |
long |
getPollTime()
Gets the time in milliseconds this event source polls, more precisely, the
time span between two polls.
|
long |
getStartTime()
Gets the absolute time in milliseconds since midnight, January 1, 1970 UTC
when this polling source should start polling.
|
void |
init()
Initialises this polling source.
|
protected boolean |
nextHandler(MailEvent event,
boolean consumed,
boolean concurrent)
This method is called right before an event is offered to the next handler.
|
protected javax.mail.Folder |
openFolder()
Opens and returns the folder configured for the message store in read/write
mode.
|
protected void |
setConfiguration(Configuration conf,
boolean completed)
Sets the internal fields according to the values of the designated
configuration.
|
void |
setConfiguration(Configuration conf,
java.lang.String id)
Sets the (additional) configuration of this event source and its ID.
|
void |
terminate()
Terminates this polling source.
|
protected boolean |
timedOut(java.lang.Throwable t)
Gets whether the designated throwable indicates a timeout.
|
protected void |
verifyConfigurationValues()
This method verifies the configuration values that have been set yet.
|
addAll, addedHandlerLocked, addedHandlerLocked, addHandler, createPattern, forwardEvent, getEventHandler, getHierarchicalSourceName, getID, getType, maskedInterrupt, maskInterrupt, removeHandler, removingHandlerLocked, replaceValueParams, run, unmaskInterruptclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddAll, addHandler, getEventHandler, getHierarchicalSourceName, getID, getType, removeHandlerprotected java.lang.Long pollTime
protected java.lang.Long startPoint
protected boolean keepConnection
protected java.lang.String protocol
protected java.lang.String host
protected int port
protected java.lang.String userName
protected java.lang.String password
protected java.lang.String folderName
protected long timeout
protected final java.net.URI[] eventManagerURIs
protected javax.mail.Store store
null in
case this source is not connected.public MailEventSource(Configuration conf, EventManager eventManager, Registry registry) throws ConfigurationException
EventManager called by
a service registry.
Note that this constructor calls
setConfiguration(Configuration, boolean); subclasses may not be
fully initialised at this point.
conf - The configuration as provided from the registry.eventManager - The event manager this event source is a plugin of.registry - The registry of this plugin.ConfigurationException - If the configuration is not valid for a
PollingMailSource, a ConfigurationException
will be thrown.protected MailEventSource(Configuration conf, EventManager eventManager, Registry registry, java.lang.Class<?> confDesc) throws ConfigurationException
Note that this constructor calls
setConfiguration(Configuration, boolean); subclasses may not be
fully initialised at this point.
conf - The configuration as provided from the registry.eventManager - The event manager this event source is a plugin of.registry - The registry of this plugin.confDesc - The class (or interface) providing the configuration
description to validate.ConfigurationException - If the configuration is not valid for a
PollingMailSource, a ConfigurationException
will be thrown.protected void setConfiguration(Configuration conf, boolean completed) throws ConfigurationException
conf - The configuration from which to get the configuration values.completed - Whether the configuration is complete after this setting
and therefore the values should be
verified.ConfigurationException - If there are problems with the
configuration, for instance the configuration does not provide
required values, a ConfigurationException may be
thrown.protected void verifyConfigurationValues()
throws ConfigurationException
ConfigurationException will be thrown.ConfigurationException - If there are problems with the
configuration, for instance the configuration does not provide
required values, a ConfigurationException may be
thrown.public void setConfiguration(Configuration conf, java.lang.String id) throws ConfigurationException
EventSourceRunnable.run().setConfiguration in interface EventSource<MailEvent>setConfiguration in class AbstractEventSource<MailEvent>conf - The configuration of this event source. This adheres (and
overwrites) the configuration provided by the plugin loading, if
this event source has been loaded as plugin. Whether this is
allowed to be null depends on the implementation of
the event source.id - The ID of this event source. This must not be null
nor the empty string.ConfigurationException - If there are problems with the designated
configuration (configuration is null although this
is not allowed, a required configuration value is missing, ...),
a ConfigurationException will be thrown.public long getPollTime()
PollingSourcePollingSource.init() and PollingSource.terminate() will be called.getPollTime in interface PollingSource<MailEvent>public long getStartTime()
PollingSourcePollingSource.getPollTime().getStartTime in interface PollingSource<MailEvent>public void init()
PollingSourceinit in interface PollingSource<MailEvent>public void checkForAndHandleEvent()
AbstractEventSourceAbstractEventSource.forwardEvent(Event, boolean, boolean)).checkForAndHandleEvent in class AbstractEventSource<MailEvent>public void terminate()
PollingSourceterminate in interface PollingSource<MailEvent>protected MailEvent createMailEvent(javax.mail.Message message) throws javax.mail.MessagingException, java.io.IOException
MailEvent for the designated message.message - The message for which to create a MailEvent.MailEvent created for the designated message.javax.mail.MessagingException - If retrieving the required data from the message
fails, a MessagingException will be thrown.java.io.IOException - Retrieving the (complex) content of the message may
thrown an IOException.protected boolean nextHandler(MailEvent event, boolean consumed, boolean concurrent)
AbstractEventSourcenextHandler in class AbstractEventSource<MailEvent>event - The event which is about to be handled by the next registered
handler.consumed - Whether the event has been consumed yet.concurrent - Whether the next event handling is concurrent and thus
the event will be offered to several event handler concurrently.false here.protected void connectToStore()
throws javax.mail.MessagingException
javax.mail.MessagingException - If there are problems connecting to the store, a
MessagingException will be thrown.protected void closeStore()
throws javax.mail.MessagingException
javax.mail.MessagingException - If there are problems closing the store, a
MessagingException will be thrown.protected javax.mail.Folder openFolder()
throws javax.mail.MessagingException
javax.mail.MessagingException - If there are problems retrieving or opening the
folder, a MessagingException will be thrown.protected void close(javax.mail.Folder folder)
throws javax.mail.MessagingException
folder - The folder to close and expunge.javax.mail.MessagingException - If there are problems closing the designated
folder, a MessagingException will be thrown.protected boolean timedOut(java.lang.Throwable t)
t - The throwable which to check for whether it indicates a timeout.