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:
AbstractListener
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCLEANUP_INTERVAL_PROPERTYHow long to wait until checking for expired notifications/products.static java.lang.StringCONCURRENT_PRODUCTS_PROPERTYProperty for concurrentProductsstatic java.lang.StringDEFAULT_CLEANUP_INTERVALDefault time to wait for cleanup.static java.lang.StringDEFAULT_CONCURRENT_PRODUCTSHow many products to process at a time.static java.lang.StringDEFAULT_PROCESS_DUPLICATESDefault for process duplicates.static java.lang.StringEXCLUDE_PATHS_PROPERTYProperty for exludePathsstatic java.lang.StringINCLUDE_PATHS_PROPERTYFilter products based on content paths they contain.static java.lang.StringINDEX_FILE_PROPERTYProperty for listener index filestatic java.lang.StringNOTIFICATION_INDEX_PROPERTYProperty referencing a notification index config section.static java.lang.StringPROCESS_DUPLICATESWhether 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 Constructor Description DefaultNotificationListener()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcleanup()Periodic cleanup task.voidconfigure(Config config)Read the include and exclude types from config.java.lang.LonggetCleanupInterval()intgetConcurrentProducts()java.util.ArrayList<java.lang.String>getExcludePaths()java.util.ArrayList<java.lang.String>getIncludePaths()NotificationIndexgetNotificationIndex()booleanisProcessDuplicates()protected voidonAfterProcessNotification(Notification notification)Called when this listener has successfully processed a notification.protected booleanonBeforeProcessNotification(Notification notification)Called just before this listener processes a notification.protected booleanonBeforeProcessProduct(Product product)Called after a product has been downloaded, but before onProduct is called.voidonExpiredNotification(Notification notification)Called when an expired notification is being removed from the index.voidonNotification(NotificationEvent event)Implement the NotificationListener interface.voidonProduct(Product product)Called by onNotification when a product is retrieved.voidsetCleanupInterval(java.lang.Long cleanupInterval)voidsetConcurrentProducts(int concurrentProducts)voidsetNotificationIndex(NotificationIndex notificationIndex)voidsetProcessDuplicates(boolean processDuplicates)voidshutdown()Stop any processing/background threads.voidstartup()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 Detail
-
NOTIFICATION_INDEX_PROPERTY
public static final java.lang.String NOTIFICATION_INDEX_PROPERTY
Property referencing a notification index config section.- See Also:
- Constant Field Values
-
INDEX_FILE_PROPERTY
public static final java.lang.String INDEX_FILE_PROPERTY
Property for listener index file- See Also:
- Constant Field Values
-
CLEANUP_INTERVAL_PROPERTY
public static final java.lang.String CLEANUP_INTERVAL_PROPERTY
How long to wait until checking for expired notifications/products.- See Also:
- Constant Field Values
-
DEFAULT_CLEANUP_INTERVAL
public static final java.lang.String DEFAULT_CLEANUP_INTERVAL
Default time to wait for cleanup. 1h- See Also:
- Constant Field Values
-
CONCURRENT_PRODUCTS_PROPERTY
public static final java.lang.String CONCURRENT_PRODUCTS_PROPERTY
Property for concurrentProducts- See Also:
- Constant Field Values
-
DEFAULT_CONCURRENT_PRODUCTS
public static final java.lang.String DEFAULT_CONCURRENT_PRODUCTS
How many products to process at a time.- See Also:
- Constant Field Values
-
PROCESS_DUPLICATES
public static final java.lang.String PROCESS_DUPLICATES
Whether or not to process products more than once.- See Also:
- Constant Field Values
-
DEFAULT_PROCESS_DUPLICATES
public static final java.lang.String DEFAULT_PROCESS_DUPLICATES
Default for process duplicates. False- See Also:
- Constant Field Values
-
INCLUDE_PATHS_PROPERTY
public static final java.lang.String INCLUDE_PATHS_PROPERTY
Filter products based on content paths they contain.- See Also:
- Constant Field Values
-
EXCLUDE_PATHS_PROPERTY
public static final java.lang.String EXCLUDE_PATHS_PROPERTY
Property for exludePaths- See Also:
- Constant Field Values
-
-
Method Detail
-
onNotification
public void onNotification(NotificationEvent event) throws java.lang.Exception
Implement the NotificationListener interface. This method calls accept, and if accept returns true, retrieves the product and calls onProduct.- Specified by:
onNotificationin interfaceNotificationListener- Parameters:
event- the event corresponding to the notification that is available.- Throws:
ContinuableListenerException- if redelivery should be attempted (depending on what getAttemptCount() returns).java.lang.Exception- See Also:
ContinuableListenerException,InterruptedException,NotificationListener.getMaxTries()
-
onProduct
public void onProduct(Product product) throws java.lang.Exception
Called by onNotification when a product is retrieved.- Parameters:
product- a product whose notification was accepted.- Throws:
java.lang.Exception- if error occurs
-
onBeforeProcessNotification
protected boolean onBeforeProcessNotification(Notification notification) throws java.lang.Exception
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:
java.lang.Exception- if error occurs
-
onBeforeProcessProduct
protected boolean onBeforeProcessProduct(Product product) throws java.lang.Exception
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:
java.lang.Exception- if error occurs
-
onAfterProcessNotification
protected void onAfterProcessNotification(Notification notification) throws java.lang.Exception
Called when this listener has successfully processed a notification.- Parameters:
notification- notification that was processed.- Throws:
java.lang.Exception- if error occurs
-
onExpiredNotification
public void onExpiredNotification(Notification notification) throws java.lang.Exception
Called when an expired notification is being removed from the index.- Specified by:
onExpiredNotificationin interfaceNotificationIndexCleanup.Listener- Parameters:
notification- to be removed- Throws:
java.lang.Exception- if error occurs
-
cleanup
public void cleanup() throws java.lang.ExceptionPeriodic cleanup task. Called every cleanupInterval milliseconds.- Throws:
java.lang.Exception
-
startup
public void startup() throws java.lang.ExceptionDescription copied from class:DefaultConfigurableStart any processing/background threads.- Specified by:
startupin interfaceConfigurable- Overrides:
startupin classDefaultConfigurable- Throws:
java.lang.Exception- if exceptions occur while starting.
-
shutdown
public void shutdown() throws java.lang.ExceptionDescription copied from class:DefaultConfigurableStop any processing/background threads.- Specified by:
shutdownin interfaceConfigurable- Overrides:
shutdownin classDefaultConfigurable- Throws:
java.lang.Exception- if exceptions occur while starting.
-
configure
public void configure(Config config) throws java.lang.Exception
Description copied from class:AbstractListenerRead the include and exclude types from config.- Specified by:
configurein interfaceConfigurable- Overrides:
configurein classAbstractListener- Parameters:
config- the Config object with settings.- Throws:
java.lang.Exception- if configuration exceptions occur.
-
getNotificationIndex
public NotificationIndex getNotificationIndex()
- Returns:
- notificationIndex
-
setNotificationIndex
public void setNotificationIndex(NotificationIndex notificationIndex)
- Parameters:
notificationIndex- to set
-
getCleanupInterval
public java.lang.Long getCleanupInterval()
- Returns:
- cleanupInterval
-
setCleanupInterval
public void setCleanupInterval(java.lang.Long cleanupInterval)
- 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
public java.util.ArrayList<java.lang.String> getIncludePaths()
- Returns:
- the includePaths
-
getExcludePaths
public java.util.ArrayList<java.lang.String> getExcludePaths()
- Returns:
- the excludePaths
-
-