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
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
FieldsModifier and TypeFieldDescriptionstatic final StringConfiguration value for the "XOAUTH2" authentication mechanisms.protected StringThe authentication mechanism to use.static final StringThe configuration key for the authentication mechanism.static final StringThe configuration key for the ID (simple instance name) of theOAuth2AccessTokenProviderto be used when the "XOAUTH2" authentication mechanism is configured.protected AbstractEventManagerThe event manager for retrieving the OAuth2 access token provider.protected final URI[]The event manager URIs to provide to the created events.protected StringThe name of the folder which causes an event when a new mail is received.protected StringThe host to connect to and from which to use as mail source.protected booleanWhether the mail storage should not be disconnected between polls.protected OAuth2AccessTokenProviderThe plugin instance that will be used to acquire an OAuth2 access token when the "XOAUTH2" authentication mechanisms is used.protected StringThe optional (simple) instance name of the OAuth2AccessTokenProvider to use when the "XOAUTH2" authentication mechanism is configured.protected StringThe password used to connect to the host with, unless the current authentication mechanism requires something different.static final StringThe plug-in type ID for OAuth 2 access token providers.protected LongThe time in milliseconds this event source polls its data source.protected intThe port of the host to which to connect to.protected StringThe protocol to use for this mail events, for instance pop3, imap, ...protected StringThe SSL protocols used for secure protocols.protected LongThe start point (in milliseconds) this event should start polling.protected jakarta.mail.StoreThe mail server which to check for mails.protected longThe timeout in milliseconds this event source uses for the mail server.protected StringThe 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, threadLockFields 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_NAMEFields inherited from interface de.aristaflow.adept2.model.events.sources.PollingMailSource
CONF_KEEP_CONNECTIONFields inherited from interface de.aristaflow.adept2.model.events.sources.PollingSource
CONF_POLL_TIME, CONF_START_TIME -
Constructor Summary
ConstructorsModifierConstructorDescriptionMailEventSource(Configuration conf, AbstractEventManager eventManager, Registry registry) Default constructor for a plugin of anEventManagercalled by a service registry.protectedMailEventSource(Configuration conf, AbstractEventManager eventManager, Registry registry, Class<?> confDesc) Constructor for subclasses allowing to set a separate class for the configuration description. -
Method Summary
Modifier and TypeMethodDescriptionvoidChecks for an event and handles it (usually by usingAbstractEventSource.forwardEvent(Event, boolean, boolean)).protected voidclose(jakarta.mail.Folder folder) Closes and expunges the designated folder if it is open.protected voidCloses the message store of this event source.protected voidConnects to the configured store of this event source.protected MailEventcreateMailEvent(jakarta.mail.Message message) Creates aMailEventfor the designated message.longGets the time in milliseconds this event source polls, more precisely, the time span between two polls.longGets 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 jakarta.mail.FolderOpens and returns the folder configured for the message store in read/write mode.protected voidsetConfiguration(Configuration conf, boolean completed) Sets the internal fields according to the values of the designated configuration.voidsetConfiguration(Configuration conf, String id) Sets the (additional) configuration of this event source and its ID.voidTerminates this polling source.protected booleanGets whether the designated throwable indicates a timeout.protected voidThis 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, unmaskInterruptMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface de.aristaflow.adept2.model.events.sources.EventSource
addAll, addHandler, getEventHandler, getHierarchicalSourceName, getID, getType, removeHandlerMethods inherited from interface de.aristaflow.adept2.model.events.sources.PollingSource
init
-
Field Details
-
PLUGIN_TYPE_OAUTH2_ACCESS_TOKEN_PROVIDER
The plug-in type ID for OAuth 2 access token providers.- See Also:
-
CONF_AUTH_MECHANISM
The configuration key for the authentication mechanism. This will be used in thePropertiesfor connecting to the mail store.- See Also:
-
AUTHMECH_XOAUTH2
Configuration value for the "XOAUTH2" authentication mechanisms.- See Also:
-
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:
-
pollTime
The time in milliseconds this event source polls its data source. -
startPoint
The start point (in milliseconds) this event should start polling. -
keepConnection
protected boolean keepConnectionWhether the mail storage should not be disconnected between polls. -
protocol
The protocol to use for this mail events, for instance pop3, imap, ... -
sslProtocols
The SSL protocols used for secure protocols. -
host
The host to connect to and from which to use as mail source. -
port
protected int portThe port of the host to which to connect to. -
userName
The user name to connect to the host with. -
authMechanism
The authentication mechanism to use. -
password
The password used to connect to the host with, unless the current authentication mechanism requires something different. -
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
The plugin instance that will be used to acquire an OAuth2 access token when the "XOAUTH2" authentication mechanisms is used. -
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 timeoutThe timeout in milliseconds this event source uses for the mail server. -
eventManager
The event manager for retrieving the OAuth2 access token provider. -
eventManagerURIs
The event manager URIs to provide to the created events. -
store
protected jakarta.mail.Store storeThe mail server which to check for mails. This will benullin case this source is not connected.
-
-
Constructor Details
-
MailEventSource
public MailEventSource(Configuration conf, AbstractEventManager eventManager, Registry registry) throws ConfigurationException Default 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(Configuration conf, AbstractEventManager eventManager, Registry registry, Class<?> confDesc) throws ConfigurationException Constructor 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 Details
-
setConfiguration
protected void setConfiguration(Configuration conf, boolean completed) throws ConfigurationException Sets 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
This 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
Description 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(jakarta.mail.Message message) throws jakarta.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:
jakarta.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
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 jakarta.mail.MessagingExceptionConnects to the configured store of this event source.- Throws:
jakarta.mail.MessagingException- If there are problems connecting to the store, aMessagingExceptionwill be thrown.
-
closeStore
protected void closeStore() throws jakarta.mail.MessagingExceptionCloses the message store of this event source.- Throws:
jakarta.mail.MessagingException- If there are problems closing the store, aMessagingExceptionwill be thrown.
-
openFolder
protected jakarta.mail.Folder openFolder() throws jakarta.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:
jakarta.mail.MessagingException- If there are problems retrieving or opening the folder, aMessagingExceptionwill be thrown.
-
close
protected void close(jakarta.mail.Folder folder) throws jakarta.mail.MessagingException Closes and expunges the designated folder if it is open.- Parameters:
folder- The folder to close and expunge.- Throws:
jakarta.mail.MessagingException- If there are problems closing the designated folder, aMessagingExceptionwill be thrown.
-
timedOut
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.
-