Class MailEventSource
- java.lang.Object
-
- de.aristaflow.adept2.core.eventmanager.common.AbstractEventSource<MailEvent>
-
- de.aristaflow.adept2.core.eventmanager.mailevents.MailEventSource
-
- All Implemented Interfaces:
EventSource<MailEvent>,MailSource,PollingMailSource,PollingSource<MailEvent>,Runnable
- Direct Known Subclasses:
FilteredMailEventSource,MailEventActivitySource
public class MailEventSource extends AbstractEventSource<MailEvent> implements PollingMailSource
A source for events based on mails in a specific folder (usually the INBOX). This folder is checked regularly and any mail found is notified as event to the corresponding event handler.
-
-
Field Summary
Fields Modifier and Type Field Description static StringAUTHMECH_XOAUTH2Configuration value for the "XOAUTH2" authentication mechanisms.protected StringauthMechanismThe authentication mechanism to use.static StringCONF_AUTH_MECHANISMThe configuration key for the authentication mechanism.static StringCONF_OAUTH2_ACCESS_TOKEN_PROVIDER_IDThe configuration key for the ID (simple instance name) of theOAuth2AccessTokenProviderto be used when the "XOAUTH2" authentication mechanism is configured.protected AbstractEventManagereventManagerThe event manager for retrieving the OAuth2 access token provider.protected URI[]eventManagerURIsThe event manager URIs to provide to the created events.protected StringfolderNameThe name of the folder which causes an event when a new mail is received.protected StringhostThe host to connect to and from which to use as mail source.protected booleankeepConnectionWhether the mail storage should not be disconnected between polls.protected OAuth2AccessTokenProvideroauth2AccessTokenProviderThe plugin instance that will be used to acquire an OAuth2 access token when the "XOAUTH2" authentication mechanisms is used.protected Stringoauth2AccessTokenProviderIdThe optional (simple) instance name of the OAuth2AccessTokenProvider to use when the "XOAUTH2" authentication mechanism is configured.protected StringpasswordThe password used to connect to the host with, unless the current authentication mechanism requires something different.static StringPLUGIN_TYPE_OAUTH2_ACCESS_TOKEN_PROVIDERThe plug-in type ID for OAuth 2 access token providers.protected LongpollTimeThe time in milliseconds this event source polls its data source.protected intportThe port of the host to which to connect to.protected StringprotocolThe protocol to use for this mail events, for instance pop3, imap, ...protected StringsslProtocolsThe SSL protocols used for secure protocols.protected LongstartPointThe start point (in milliseconds) this event should start polling.protected javax.mail.StorestoreThe mail server which to check for mails.protected longtimeoutThe timeout in milliseconds this event source uses for the mail server.protected StringuserNameThe user name to connect to the host with.-
Fields inherited from class de.aristaflow.adept2.core.eventmanager.common.AbstractEventSource
eventType, handlerList, id, lock, logger, sourceType, thread, threadLock
-
Fields inherited from interface de.aristaflow.adept2.model.events.sources.MailSource
CONF_FOLDER, CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_PROTOCOL, CONF_SSL_PROTOCOLS, CONF_TIMEOUT, CONF_USER_NAME
-
Fields inherited from interface de.aristaflow.adept2.model.events.sources.PollingMailSource
CONF_KEEP_CONNECTION
-
Fields inherited from interface de.aristaflow.adept2.model.events.sources.PollingSource
CONF_POLL_TIME, CONF_START_TIME
-
-
Constructor Summary
Constructors Modifier Constructor Description MailEventSource(org.apache.commons.configuration2.Configuration conf, AbstractEventManager eventManager, Registry registry)Default constructor for a plugin of anEventManagercalled by a service registry.protectedMailEventSource(org.apache.commons.configuration2.Configuration conf, AbstractEventManager eventManager, Registry registry, Class<?> confDesc)Constructor for subclasses allowing to set a separate class for the configuration description.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcheckForAndHandleEvent()Checks for an event and handles it (usually by usingAbstractEventSource.forwardEvent(Event, boolean, boolean)).protected voidclose(javax.mail.Folder folder)Closes and expunges the designated folder if it is open.protected voidcloseStore()Closes the message store of this event source.protected voidconnectToStore()Connects to the configured store of this event source.protected MailEventcreateMailEvent(javax.mail.Message message)Creates aMailEventfor the designated message.longgetPollTime()Gets the time in milliseconds this event source polls, more precisely, the time span between two polls.longgetStartTime()Gets the absolute time in milliseconds since midnight, January 1, 1970 UTC when this polling source should start polling.protected booleannextHandler(MailEvent event, boolean consumed, boolean concurrent)This method is called right before an event is offered to the next handler.protected javax.mail.FolderopenFolder()Opens and returns the folder configured for the message store in read/write mode.protected voidsetConfiguration(org.apache.commons.configuration2.Configuration conf, boolean completed)Sets the internal fields according to the values of the designated configuration.voidsetConfiguration(org.apache.commons.configuration2.Configuration conf, String id)Sets the (additional) configuration of this event source and its ID.voidterminate()Terminates this polling source.protected booleantimedOut(Throwable t)Gets whether the designated throwable indicates a timeout.protected voidverifyConfigurationValues()This method verifies the configuration values that have been set yet.-
Methods inherited from class de.aristaflow.adept2.core.eventmanager.common.AbstractEventSource
addAll, addedHandlerLocked, addedHandlerLocked, addHandler, createPattern, forwardEvent, getEventHandler, getHierarchicalSourceName, getID, getType, maskedInterrupt, maskInterrupt, removeHandler, removingHandlerLocked, replaceValueParams, run, unmaskInterrupt
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface de.aristaflow.adept2.model.events.sources.EventSource
addAll, addHandler, getEventHandler, getHierarchicalSourceName, getID, getType, removeHandler
-
Methods inherited from interface de.aristaflow.adept2.model.events.sources.PollingSource
init
-
-
-
-
Field Detail
-
PLUGIN_TYPE_OAUTH2_ACCESS_TOKEN_PROVIDER
public static final String PLUGIN_TYPE_OAUTH2_ACCESS_TOKEN_PROVIDER
The plug-in type ID for OAuth 2 access token providers.- See Also:
- Constant Field Values
-
CONF_AUTH_MECHANISM
public static final String CONF_AUTH_MECHANISM
The configuration key for the authentication mechanism. This will be used in thePropertiesfor connecting to the mail store.- See Also:
- Constant Field Values
-
AUTHMECH_XOAUTH2
public static final String AUTHMECH_XOAUTH2
Configuration value for the "XOAUTH2" authentication mechanisms.- See Also:
- Constant Field Values
-
CONF_OAUTH2_ACCESS_TOKEN_PROVIDER_ID
public static final String CONF_OAUTH2_ACCESS_TOKEN_PROVIDER_ID
The configuration key for the ID (simple instance name) of theOAuth2AccessTokenProviderto be used when the "XOAUTH2" authentication mechanism is configured.- See Also:
- Constant Field Values
-
pollTime
protected Long pollTime
The time in milliseconds this event source polls its data source.
-
startPoint
protected Long startPoint
The start point (in milliseconds) this event should start polling.
-
keepConnection
protected boolean keepConnection
Whether the mail storage should not be disconnected between polls.
-
protocol
protected String protocol
The protocol to use for this mail events, for instance pop3, imap, ...
-
sslProtocols
protected String sslProtocols
The SSL protocols used for secure protocols.
-
host
protected String host
The host to connect to and from which to use as mail source.
-
port
protected int port
The port of the host to which to connect to.
-
userName
protected String userName
The user name to connect to the host with.
-
authMechanism
protected String authMechanism
The authentication mechanism to use.
-
password
protected String password
The password used to connect to the host with, unless the current authentication mechanism requires something different.
-
oauth2AccessTokenProviderId
protected String oauth2AccessTokenProviderId
The optional (simple) instance name of the OAuth2AccessTokenProvider to use when the "XOAUTH2" authentication mechanism is configured. If no ID is specified, the default instance will be used.
-
oauth2AccessTokenProvider
protected OAuth2AccessTokenProvider oauth2AccessTokenProvider
The plugin instance that will be used to acquire an OAuth2 access token when the "XOAUTH2" authentication mechanisms is used.
-
folderName
protected String folderName
The name of the folder which causes an event when a new mail is received. If not specified the usual INBOX will be used.
-
timeout
protected long timeout
The timeout in milliseconds this event source uses for the mail server.
-
eventManager
protected AbstractEventManager eventManager
The event manager for retrieving the OAuth2 access token provider.
-
eventManagerURIs
protected final URI[] eventManagerURIs
The event manager URIs to provide to the created events.
-
store
protected javax.mail.Store store
The mail server which to check for mails. This will benullin case this source is not connected.
-
-
Constructor Detail
-
MailEventSource
public MailEventSource(org.apache.commons.configuration2.Configuration conf, AbstractEventManager eventManager, Registry registry) throws ConfigurationExceptionDefault constructor for a plugin of anEventManagercalled by a service registry.Note that this constructor calls
setConfiguration(Configuration, boolean); subclasses may not be fully initialised at this point.- Parameters:
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.- Throws:
ConfigurationException- If the configuration is not valid for aPollingMailSource, aConfigurationExceptionwill be thrown.
-
MailEventSource
protected MailEventSource(org.apache.commons.configuration2.Configuration conf, AbstractEventManager eventManager, Registry registry, Class<?> confDesc) throws ConfigurationExceptionConstructor for subclasses allowing to set a separate class for the configuration description.Note that this constructor calls
setConfiguration(Configuration, boolean); subclasses may not be fully initialised at this point.- Parameters:
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.- Throws:
ConfigurationException- If the configuration is not valid for aPollingMailSource, aConfigurationExceptionwill be thrown.
-
-
Method Detail
-
setConfiguration
protected void setConfiguration(org.apache.commons.configuration2.Configuration conf, boolean completed) throws ConfigurationExceptionSets the internal fields according to the values of the designated configuration. Note that this method is called from the constructor and therefore this object may not be fully initialised!- Parameters:
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.- Throws:
ConfigurationException- If there are problems with the configuration, for instance the configuration does not provide required values, aConfigurationExceptionmay be thrown.
-
verifyConfigurationValues
protected void verifyConfigurationValues() throws ConfigurationExceptionThis method verifies the configuration values that have been set yet. If a configuration value is missing or inappropriate, aConfigurationExceptionwill be thrown.- Throws:
ConfigurationException- If there are problems with the configuration, for instance the configuration does not provide required values, aConfigurationExceptionmay be thrown.
-
setConfiguration
public void setConfiguration(org.apache.commons.configuration2.Configuration conf, String id) throws ConfigurationExceptionDescription copied from interface:EventSourceSets the (additional) configuration of this event source and its ID. The configuration is additional with respect to the configuration provided by the plugin load mechanism, if the event source is loaded as plugin.
It is ensured that this method will be called beforeRunnable.run().- Specified by:
setConfigurationin interfaceEventSource<MailEvent>- Overrides:
setConfigurationin classAbstractEventSource<MailEvent>- Parameters:
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 benulldepends on the implementation of the event source.id- The ID of this event source. This must not benullnor the empty string.- Throws:
ConfigurationException- If there are problems with the designated configuration (configuration isnullalthough this is not allowed, a required configuration value is missing, ...), aConfigurationExceptionwill be thrown.
-
getPollTime
public long getPollTime()
Description copied from interface:PollingSourceGets the time in milliseconds this event source polls, more precisely, the time span between two polls. If this is 0 or negative, no polling will apply. However,PollingSource.init()andPollingSource.terminate()will be called.- Specified by:
getPollTimein interfacePollingSource<MailEvent>- Returns:
- The time in milliseconds this event source polls (> 0).
-
getStartTime
public long getStartTime()
Description copied from interface:PollingSourceGets the absolute time in milliseconds since midnight, January 1, 1970 UTC when this polling source should start polling. This is used for calculating the first poll time by adding the time span defined inPollingSource.getPollTime().- Specified by:
getStartTimein interfacePollingSource<MailEvent>- Returns:
- The absolute time in milliseconds since midnight, January 1, 1970 UTC when this polling source should start polling.
-
checkForAndHandleEvent
public void checkForAndHandleEvent()
Description copied from class:AbstractEventSourceChecks for an event and handles it (usually by usingAbstractEventSource.forwardEvent(Event, boolean, boolean)).- Specified by:
checkForAndHandleEventin classAbstractEventSource<MailEvent>
-
terminate
public void terminate()
Description copied from interface:PollingSourceTerminates this polling source. This is called once after polling has terminated and this source is removed.
Note that this may be called any time, even when creating or handling an event. So take care to synchronise the implementation appropriately!- Specified by:
terminatein interfacePollingSource<MailEvent>
-
createMailEvent
protected MailEvent createMailEvent(javax.mail.Message message) throws javax.mail.MessagingException, IOException
Creates aMailEventfor the designated message.- Parameters:
message- The message for which to create aMailEvent.- Returns:
- The
MailEventcreated for the designated message. - Throws:
javax.mail.MessagingException- If retrieving the required data from the message fails, aMessagingExceptionwill be thrown.IOException- Retrieving the (complex) content of the message may thrown anIOException.
-
nextHandler
protected boolean nextHandler(MailEvent event, boolean consumed, boolean concurrent)
Description copied from class:AbstractEventSourceThis method is called right before an event is offered to the next handler. In case of concurrent handling, this method will only be called once for all concurrent handling but this will be indicated by the corresponding parameter.- Specified by:
nextHandlerin classAbstractEventSource<MailEvent>- Parameters:
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.- Returns:
- Whether the event handling may continue. In case of serious
problems preventing further event handling, return
falsehere.
-
connectToStore
protected void connectToStore() throws javax.mail.MessagingExceptionConnects to the configured store of this event source.- Throws:
javax.mail.MessagingException- If there are problems connecting to the store, aMessagingExceptionwill be thrown.
-
closeStore
protected void closeStore() throws javax.mail.MessagingExceptionCloses the message store of this event source.- Throws:
javax.mail.MessagingException- If there are problems closing the store, aMessagingExceptionwill be thrown.
-
openFolder
protected javax.mail.Folder openFolder() throws javax.mail.MessagingExceptionOpens and returns the folder configured for the message store in read/write mode.- Returns:
- The opened folder configured for the message store.
- Throws:
javax.mail.MessagingException- If there are problems retrieving or opening the folder, aMessagingExceptionwill be thrown.
-
close
protected void close(javax.mail.Folder folder) throws javax.mail.MessagingExceptionCloses and expunges the designated folder if it is open.- Parameters:
folder- The folder to close and expunge.- Throws:
javax.mail.MessagingException- If there are problems closing the designated folder, aMessagingExceptionwill be thrown.
-
timedOut
protected boolean timedOut(Throwable t)
Gets whether the designated throwable indicates a timeout. Depending on the protocol provider, a timeout can be signalled differently.- Parameters:
t- The throwable which to check for whether it indicates a timeout.- Returns:
- Whether the designated throwable indicates a timeout.
-
-