Class MailMonitor
- All Implemented Interfaces:
Iterable<ComponentType>
,Channel
,ComponentType
,Eligible
,Manager
After establishing a connection to a store and selected
folders (see onOpenMailMonitor(OpenMailMonitor, Channel)
),
the existing and all subsequently arriving mails will be sent
downstream using MailFoldersUpdated
events.
This implementation uses the IdleManager
. The
IdleManager
works only if its IdleManager.watch(jakarta.mail.Folder)
method is invoked (for a folder) after any operation on that folder.
Note that operations such as e.g. setting the deleted flag of
a message is also an operation on a folder.
Folders are updated in response to an UpdateMailFolders
event
or when the store signals the arrival of new messages. Information
about the folders is delivered by a MailFoldersUpdated
event.
Folders may be freely used while handling the event, because the
folders will be re-registered with the IdleManager
when the MailFoldersUpdated
event completes.
Any usage of folders independent of handling the events mentioned
will result in a loss of the monitor function.
If required, the monitor function may be reestablished any time
by firing a UpdateMailFolders
event for the folders used.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.jgrapes.mail.MailConnectionManager
MailConnectionManager.AbstractMailChannel
Nested classes/interfaces inherited from class org.jgrapes.io.util.ConnectionManager
ConnectionManager.Connection
Nested classes/interfaces inherited from interface org.jgrapes.core.Channel
Channel.Default
-
Field Summary
Fields inherited from class org.jgrapes.mail.MailConnectionManager
mailProps
Fields inherited from class org.jgrapes.io.util.ConnectionManager
connections
-
Constructor Summary
ConstructorDescriptionMailMonitor
(Channel componentChannel) Creates a new server using the given channel. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
configureComponent
(Map<String, String> values) Configure the component.protected boolean
If connections are event generators, register the component as generator upon the creation of the first connection and unregister it when closing the last one.Returns the max idle time.void
onOpenMailMonitor
(OpenMailMonitor event, Channel channel) Open a store as specified by the event and monitor the folders (also specified by the event).void
onUpdateFolders
(UpdateMailFolders event, MailChannel channel) Retrieves the folders specified in the event.setMaxIdleTime
(Duration maxIdleTime) Sets the maximum idle time.toString()
If a name has been set for this component (seeManager.setName(String)
), return the name, else return the object name provided byComponents.objectName(Object)
, usingComponentVertex.component()
as argument.Methods inherited from class org.jgrapes.mail.MailConnectionManager
onConfigUpdate, password, setMailProperties, setPassword
Methods inherited from class org.jgrapes.io.util.ConnectionManager
executorService, onClose, onStop, setExecutorService
Methods inherited from class org.jgrapes.core.Component
channel, component, defaultCriterion, isEligibleFor, setName
Methods inherited from class org.jgrapes.core.internal.ComponentVertex
activeEventPipeline, addHandler, attach, channelReplacements, children, componentPath, componentVertex, detach, fire, initComponentsHandlers, iterator, name, newEventPipeline, newEventPipeline, parent, registerAsGenerator, root, unregisterAsGenerator
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
MailMonitor
Creates a new server using the given channel.- Parameters:
componentChannel
- the component’s channel
-
-
Method Details
-
connectionsGenerate
Description copied from class:ConnectionManager
If connections are event generators, register the component as generator upon the creation of the first connection and unregister it when closing the last one.- Specified by:
connectionsGenerate
in classConnectionManager<MailMonitor.MonitorChannel>
- Returns:
- true, if connections generate
-
setMaxIdleTime
Sets the maximum idle time.A running
IMAPFolder.idle()
is terminated and renewed after this time. Defaults to 25 minutes.- Parameters:
maxIdleTime
- the new max idle time
-
maxIdleTime
Returns the max idle time.- Returns:
- the duration
-
configureComponent
Configure the component.Currently, only max idle time is supported.
- Specified by:
configureComponent
in classMailConnectionManager<MailMonitor.MonitorChannel,
OpenMailMonitor> - Parameters:
values
- the values
-
onOpenMailMonitor
Open a store as specified by the event and monitor the folders (also specified by the event).Information about all existing and all subsequently arriving mails will be signaled downstream using
MailFoldersUpdated
events.- Parameters:
event
- the eventchannel
- the channel
-
onUpdateFolders
Retrieves the folders specified in the event.- Parameters:
event
- the eventchannel
- the channel
-
toString
Description copied from class:ComponentVertex
If a name has been set for this component (seeManager.setName(String)
), return the name, else return the object name provided byComponents.objectName(Object)
, usingComponentVertex.component()
as argument.- Overrides:
toString
in classComponentVertex
-