Package gov.usgs.earthquake.distribution
Class DefaultNotificationListener
java.lang.Object
gov.usgs.util.DefaultConfigurable
gov.usgs.earthquake.product.AbstractListener
gov.usgs.earthquake.distribution.DefaultNotificationListener
- All Implemented Interfaces:
NotificationIndexCleanup.Listener
,NotificationListener
,Configurable
- Direct Known Subclasses:
ContentListener
,DefaultNotificationSender
,EIDSOutputWedge
,ExternalNotificationListener
,HeartbeatListener
,Indexer
,RelayProductListener
,ShakeMapIndexerWedge
public class DefaultNotificationListener
extends AbstractListener
implements NotificationListener, NotificationIndexCleanup.Listener
A base implementation of a notification listener. Implements functionality
that is useful for most notification listeners.
Sub classes should override the onProduct(Product) method to add custom
processing.
The DefaultNotificationListener extends the AbstractListener and can use any
of those configuration parameters.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
How long to wait until checking for expired notifications/products.static final String
Property for concurrentProductsstatic final String
Default time to wait for cleanup.static final String
How many products to process at a time.static final String
Default for process duplicates.static final String
Property for exludePathsstatic final String
Filter products based on content paths they contain.static final String
Property for listener index filestatic final String
Property referencing a notification index config section.static final String
Whether or not to process products more than once.Fields inherited from class gov.usgs.earthquake.product.AbstractListener
ATTEMPT_COUNT_PROPERTY, DEFAULT_ATTEMPT_COUNT, DEFAULT_RETRY_DELAY, DEFAULT_TIMEOUT, EXCLUDE_SOURCES_PROPERTY, EXCLUDE_TYPES_PROPERTY, INCLUDE_ACTUALS_PROPERTY, INCLUDE_DEVELOPMENTS_PROPERTY, INCLUDE_INTERNALS_PROPERTY, INCLUDE_SCENARIOS_PROPERTY, INCLUDE_SOURCES_PROPERTY, INCLUDE_TESTS_PROPERTY, INCLUDE_TYPES_PROPERTY, MAX_TRIES_PROPERTY, RETRY_DELAY_PROPERTY, TIMEOUT_PROPERTY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
cleanup()
Periodic cleanup task.void
Read the include and exclude types from config.int
boolean
protected void
onAfterProcessNotification
(Notification notification) Called when this listener has successfully processed a notification.protected boolean
onBeforeProcessNotification
(Notification notification) Called just before this listener processes a notification.protected boolean
onBeforeProcessProduct
(Product product) Called after a product has been downloaded, but before onProduct is called.void
onExpiredNotification
(Notification notification) Called when an expired notification is being removed from the index.void
onNotification
(NotificationEvent event) Implement the NotificationListener interface.void
Called by onNotification when a product is retrieved.void
setCleanupInterval
(Long cleanupInterval) void
setConcurrentProducts
(int concurrentProducts) void
setNotificationIndex
(NotificationIndex notificationIndex) void
setProcessDuplicates
(boolean processDuplicates) void
shutdown()
Stop any processing/background threads.void
startup()
Start any processing/background threads.Methods inherited from class gov.usgs.earthquake.product.AbstractListener
accept, getExcludeSources, getExcludeTypes, getIncludeSources, getIncludeTypes, getMaxTries, getRetryDelay, getTimeout, isIncludeActuals, isIncludeDevelopments, isIncludeInternals, isIncludeScenarios, isIncludeTests, setIncludeActuals, setIncludeDevelopments, setIncludeInternals, setIncludeScenarios, setIncludeTests, setMaxTries, setRetryDelay, setTimeout
Methods inherited from class gov.usgs.util.DefaultConfigurable
getName, setName
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface gov.usgs.util.Configurable
getName, setName
Methods inherited from interface gov.usgs.earthquake.distribution.NotificationListener
getMaxTries, getTimeout
-
Field Details
-
NOTIFICATION_INDEX_PROPERTY
Property referencing a notification index config section.- See Also:
-
INDEX_FILE_PROPERTY
Property for listener index file- See Also:
-
CLEANUP_INTERVAL_PROPERTY
How long to wait until checking for expired notifications/products.- See Also:
-
DEFAULT_CLEANUP_INTERVAL
Default time to wait for cleanup. 1h- See Also:
-
CONCURRENT_PRODUCTS_PROPERTY
Property for concurrentProducts- See Also:
-
DEFAULT_CONCURRENT_PRODUCTS
How many products to process at a time.- See Also:
-
PROCESS_DUPLICATES
Whether or not to process products more than once.- See Also:
-
DEFAULT_PROCESS_DUPLICATES
Default for process duplicates. False- See Also:
-
INCLUDE_PATHS_PROPERTY
Filter products based on content paths they contain.- See Also:
-
EXCLUDE_PATHS_PROPERTY
Property for exludePaths- See Also:
-
-
Constructor Details
-
DefaultNotificationListener
public DefaultNotificationListener()
-
-
Method Details
-
onNotification
Implement the NotificationListener interface. This method calls accept, and if accept returns true, retrieves the product and calls onProduct.- Specified by:
onNotification
in interfaceNotificationListener
- Parameters:
event
- the event corresponding to the notification that is available.- Throws:
ContinuableListenerException
- if redelivery should be attempted (depending on what getAttemptCount() returns).Exception
- See Also:
-
onProduct
Called by onNotification when a product is retrieved.- Parameters:
product
- a product whose notification was accepted.- Throws:
Exception
- if error occurs
-
onBeforeProcessNotification
Called just before this listener processes a notification.- Parameters:
notification
- notification about to be processed.- Returns:
- true to process the notification, false to skip
- Throws:
Exception
- if error occurs
-
onBeforeProcessProduct
Called after a product has been downloaded, but before onProduct is called. Sometimes a listener cannot tell whether it should process a product until its contents are available. This is where the "includePaths" and "excludePaths" are evaluated.- Parameters:
product
- product about to be processed.- Returns:
- true to process the product, false to skip
- Throws:
Exception
- if error occurs
-
onAfterProcessNotification
Called when this listener has successfully processed a notification.- Parameters:
notification
- notification that was processed.- Throws:
Exception
- if error occurs
-
onExpiredNotification
Called when an expired notification is being removed from the index.- Specified by:
onExpiredNotification
in interfaceNotificationIndexCleanup.Listener
- Parameters:
notification
- to be removed- Throws:
Exception
- if error occurs
-
cleanup
Periodic cleanup task. Called every cleanupInterval milliseconds.- Throws:
Exception
- if could not create new notificationCleanup
-
startup
Description copied from class:DefaultConfigurable
Start any processing/background threads.- Specified by:
startup
in interfaceConfigurable
- Overrides:
startup
in classDefaultConfigurable
- Throws:
Exception
- if exceptions occur while starting.
-
shutdown
Description copied from class:DefaultConfigurable
Stop any processing/background threads.- Specified by:
shutdown
in interfaceConfigurable
- Overrides:
shutdown
in classDefaultConfigurable
- Throws:
Exception
- if exceptions occur while starting.
-
configure
Description copied from class:AbstractListener
Read the include and exclude types from config.- Specified by:
configure
in interfaceConfigurable
- Overrides:
configure
in classAbstractListener
- Parameters:
config
- the Config object with settings.- Throws:
Exception
- if configuration exceptions occur.
-
getNotificationIndex
- Returns:
- notificationIndex
-
setNotificationIndex
- Parameters:
notificationIndex
- to set
-
getCleanupInterval
- Returns:
- cleanupInterval
-
setCleanupInterval
- Parameters:
cleanupInterval
- long to set
-
getConcurrentProducts
public int getConcurrentProducts()- Returns:
- concurrentProducts
-
setConcurrentProducts
public void setConcurrentProducts(int concurrentProducts) - Parameters:
concurrentProducts
- int to set
-
isProcessDuplicates
public boolean isProcessDuplicates()- Returns:
- processDuplicates
-
setProcessDuplicates
public void setProcessDuplicates(boolean processDuplicates) - Parameters:
processDuplicates
- boolean to set
-
getIncludePaths
- Returns:
- the includePaths
-
getExcludePaths
- Returns:
- the excludePaths
-