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 SummaryFields 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.AbstractEventSourceeventType, handlerList, id, lock, logger, sourceType, thread, threadLock
 - 
Fields inherited from interface de.aristaflow.adept2.model.events.sources.MailSourceCONF_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.PollingMailSourceCONF_KEEP_CONNECTION
 - 
Fields inherited from interface de.aristaflow.adept2.model.events.sources.PollingSourceCONF_POLL_TIME, CONF_START_TIME
 
- 
 - 
Constructor SummaryConstructors 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 SummaryAll 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.voidinit()Initialises this polling source.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.AbstractEventSourceaddAll, addedHandlerLocked, addedHandlerLocked, addHandler, createPattern, forwardEvent, getEventHandler, getHierarchicalSourceName, getID, getType, maskedInterrupt, maskInterrupt, removeHandler, removingHandlerLocked, replaceValueParams, run, unmaskInterrupt
 - 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 - 
Methods inherited from interface de.aristaflow.adept2.model.events.sources.EventSourceaddAll, addHandler, getEventHandler, getHierarchicalSourceName, getID, getType, removeHandler
 
- 
 
- 
- 
- 
Field Detail- 
PLUGIN_TYPE_OAUTH2_ACCESS_TOKEN_PROVIDERpublic 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_MECHANISMpublic 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_XOAUTH2public static final String AUTHMECH_XOAUTH2 Configuration value for the "XOAUTH2" authentication mechanisms.- See Also:
- Constant Field Values
 
 - 
CONF_OAUTH2_ACCESS_TOKEN_PROVIDER_IDpublic 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
 
 - 
pollTimeprotected Long pollTime The time in milliseconds this event source polls its data source.
 - 
startPointprotected Long startPoint The start point (in milliseconds) this event should start polling.
 - 
keepConnectionprotected boolean keepConnection Whether the mail storage should not be disconnected between polls.
 - 
protocolprotected String protocol The protocol to use for this mail events, for instance pop3, imap, ...
 - 
sslProtocolsprotected String sslProtocols The SSL protocols used for secure protocols.
 - 
hostprotected String host The host to connect to and from which to use as mail source.
 - 
portprotected int port The port of the host to which to connect to.
 - 
userNameprotected String userName The user name to connect to the host with.
 - 
authMechanismprotected String authMechanism The authentication mechanism to use.
 - 
passwordprotected String password The password used to connect to the host with, unless the current authentication mechanism requires something different.
 - 
oauth2AccessTokenProviderIdprotected 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.
 - 
oauth2AccessTokenProviderprotected OAuth2AccessTokenProvider oauth2AccessTokenProvider The plugin instance that will be used to acquire an OAuth2 access token when the "XOAUTH2" authentication mechanisms is used.
 - 
folderNameprotected 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.
 - 
timeoutprotected long timeout The timeout in milliseconds this event source uses for the mail server.
 - 
eventManagerprotected AbstractEventManager eventManager The event manager for retrieving the OAuth2 access token provider.
 - 
eventManagerURIsprotected final URI[] eventManagerURIs The event manager URIs to provide to the created events.
 - 
storeprotected javax.mail.Store store The mail server which to check for mails. This will benullin case this source is not connected.
 
- 
 - 
Constructor Detail- 
MailEventSourcepublic 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 a- PollingMailSource, a- ConfigurationExceptionwill be thrown.
 
 - 
MailEventSourceprotected 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 a- PollingMailSource, a- ConfigurationExceptionwill be thrown.
 
 
- 
 - 
Method Detail- 
setConfigurationprotected 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, a- ConfigurationExceptionmay be thrown.
 
 - 
verifyConfigurationValuesprotected 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, a- ConfigurationExceptionmay be thrown.
 
 - 
setConfigurationpublic 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 interface- EventSource<MailEvent>
- Overrides:
- setConfigurationin class- AbstractEventSource<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 be- nulldepends on the implementation of the event source.
- id- The ID of this event source. This must not be- nullnor the empty string.
- Throws:
- ConfigurationException- If there are problems with the designated configuration (configuration is- nullalthough this is not allowed, a required configuration value is missing, ...), a- ConfigurationExceptionwill be thrown.
 
 - 
getPollTimepublic 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 interface- PollingSource<MailEvent>
- Returns:
- The time in milliseconds this event source polls (> 0).
 
 - 
getStartTimepublic 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 interface- PollingSource<MailEvent>
- Returns:
- The absolute time in milliseconds since midnight, January 1, 1970 UTC when this polling source should start polling.
 
 - 
initpublic void init() Description copied from interface:PollingSourceInitialises this polling source. This is called once before polling is started the first time.- Specified by:
- initin interface- PollingSource<MailEvent>
 
 - 
checkForAndHandleEventpublic void checkForAndHandleEvent() Description copied from class:AbstractEventSourceChecks for an event and handles it (usually by usingAbstractEventSource.forwardEvent(Event, boolean, boolean)).- Specified by:
- checkForAndHandleEventin class- AbstractEventSource<MailEvent>
 
 - 
terminatepublic 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 interface- PollingSource<MailEvent>
 
 - 
createMailEventprotected MailEvent createMailEvent(javax.mail.Message message) throws javax.mail.MessagingException, IOException Creates aMailEventfor the designated message.- Parameters:
- message- The message for which to create a- MailEvent.
- Returns:
- The MailEventcreated for the designated message.
- Throws:
- javax.mail.MessagingException- If retrieving the required data from the message fails, a- MessagingExceptionwill be thrown.
- IOException- Retrieving the (complex) content of the message may thrown an- IOException.
 
 - 
nextHandlerprotected 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 class- AbstractEventSource<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.
 
 - 
connectToStoreprotected 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, a- MessagingExceptionwill be thrown.
 
 - 
closeStoreprotected void closeStore() throws javax.mail.MessagingExceptionCloses the message store of this event source.- Throws:
- javax.mail.MessagingException- If there are problems closing the store, a- MessagingExceptionwill be thrown.
 
 - 
openFolderprotected 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, a- MessagingExceptionwill be thrown.
 
 - 
closeprotected 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, a- MessagingExceptionwill be thrown.
 
 - 
timedOutprotected 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.
 
 
- 
 
-