Package gov.usgs.earthquake.indexer
Class ReliableIndexerListener
- java.lang.Object
-
- gov.usgs.util.DefaultConfigurable
-
- gov.usgs.earthquake.product.AbstractListener
-
- gov.usgs.earthquake.indexer.DefaultIndexerListener
-
- gov.usgs.earthquake.indexer.ReliableIndexerListener
-
- All Implemented Interfaces:
IndexerListener
,Configurable
,java.lang.Runnable
- Direct Known Subclasses:
ExtentIndexerListener
public class ReliableIndexerListener extends DefaultIndexerListener implements java.lang.Runnable
ReliableIndexerListener listens for product changes by the indexer, then handles the new products independently in a background thread. This class does little more than output logs for the products it has seen; it is designed to be extended. Several useful methods are availble to be overridden or otherwise used:- onBeforeProcessThreadStart
- onProcessException
- getNextProducts
- processProducts
- index
- (Required) The index to use for product querying.
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.util.logging.Logger
LOGGER
Logger objectprotected ProductIndex
productIndex
Product Index-
Fields inherited from class gov.usgs.earthquake.indexer.DefaultIndexerListener
IGNORE_ARCHIVE_DEFAULT, IGNORE_ARCHIVE_PROPERTY, PROCESS_ONLY_WHEN_EVENT_CHANGE_DEFAULT, PROCESS_ONLY_WHEN_EVENT_CHANGE_PROPERTY, PROCESS_PREFERRED_ONLY_DEFAULT, PROCESS_PREFERRED_ONLY_PROPERTY, PROCESS_UNASSOCIATED_DEFAULT, PROCESS_UNASSOCIATED_PROPERTY
-
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 ReliableIndexerListener()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
configure(Config config)
Sets up an object on startlong
getLastIndexId()
Gets index ID of last processed productjava.util.List<ProductSummary>
getNextProducts()
Gets the next products using the index provided in ConfigProductIndex
getProductIndex()
protected void
onBeforeProcessThreadStart()
Run before thread start.void
onIndexerEvent(IndexerEvent delta)
Wakes thread when indexer makes changesprotected void
onProcessException(ProductSummary product, java.lang.Exception e)
Exception handling for product processing.protected void
onProductGetException(java.lang.Exception e)
Exception handling for product fetchvoid
processProduct(ProductSummary product)
Does a task with each productvoid
run()
Thread main body.void
setLastIndexId(long lastIndexId)
Sets index ID of last processed productvoid
setProductIndex(ProductIndex productIndex)
void
shutdown()
Closes threadvoid
startup()
Starts thread Calls onBeforeProcessThreadStart() in case subclasses want to add functionality-
Methods inherited from class gov.usgs.earthquake.indexer.DefaultIndexerListener
accept, accept, getProcessOnlyPreferredProducts, getProcessUnassociatedProducts, isIgnoreArchive, isProcessOnlyWhenEventChanged, setIgnoreArchive, setProcessOnlyPreferredProducts, setProcessOnlyWhenEventChanged, setProcessUnassociatedProducts
-
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.indexer.IndexerListener
getMaxTries, getTimeout
-
-
-
-
Field Detail
-
LOGGER
protected static final java.util.logging.Logger LOGGER
Logger object
-
productIndex
protected ProductIndex productIndex
Product Index
-
-
Method Detail
-
configure
public void configure(Config config) throws java.lang.Exception
Sets up an object on start- Specified by:
configure
in interfaceConfigurable
- Overrides:
configure
in classDefaultIndexerListener
- Parameters:
config
- configuration- Throws:
java.lang.Exception
- if missing product index
-
onIndexerEvent
public void onIndexerEvent(IndexerEvent delta) throws java.lang.Exception
Wakes thread when indexer makes changes- Specified by:
onIndexerEvent
in interfaceIndexerListener
- Overrides:
onIndexerEvent
in classDefaultIndexerListener
- Parameters:
delta
- Indexer Event - not used- Throws:
java.lang.Exception
- if something goes wrong
-
run
public void run()
Thread main body. Waits until notified, then tries to get the next products and process them.- Specified by:
run
in interfacejava.lang.Runnable
-
startup
public void startup() throws java.lang.Exception
Starts thread Calls onBeforeProcessThreadStart() in case subclasses want to add functionality- Specified by:
startup
in interfaceConfigurable
- Overrides:
startup
in classDefaultConfigurable
- Throws:
java.lang.Exception
- if there's a thread issuejava.lang.Exception
- if thread start fails
-
shutdown
public void shutdown() throws java.lang.Exception
Closes thread- Specified by:
shutdown
in interfaceConfigurable
- Overrides:
shutdown
in classDefaultConfigurable
- Throws:
java.lang.Exception
- if there's a thread issue
-
getProductIndex
public ProductIndex getProductIndex()
- Returns:
- ProductIndex
-
setProductIndex
public void setProductIndex(ProductIndex productIndex)
- Parameters:
productIndex
- to set
-
getLastIndexId
public long getLastIndexId()
Gets index ID of last processed product- Returns:
- lastIndexId
-
setLastIndexId
public void setLastIndexId(long lastIndexId)
Sets index ID of last processed product- Parameters:
lastIndexId
- to set
-
onBeforeProcessThreadStart
protected void onBeforeProcessThreadStart() throws java.lang.Exception
Run before thread start.- Throws:
java.lang.Exception
- available for subclasses
-
onProductGetException
protected void onProductGetException(java.lang.Exception e) throws java.lang.Exception
Exception handling for product fetch- Parameters:
e
- the caught exception- Throws:
java.lang.Exception
- in case we can't handle the first exception
-
onProcessException
protected void onProcessException(ProductSummary product, java.lang.Exception e) throws java.lang.Exception
Exception handling for product processing.- Parameters:
product
- the product that gave us the errore
- the caught exception- Throws:
java.lang.Exception
- in case we can't handle the first exception.
-
getNextProducts
public java.util.List<ProductSummary> getNextProducts() throws java.lang.Exception
Gets the next products using the index provided in Config- Returns:
- List of product summaries
- Throws:
java.lang.Exception
- if we have a database issue
-
processProduct
public void processProduct(ProductSummary product) throws java.lang.Exception
Does a task with each product- Parameters:
product
- ProductSummary to process- Throws:
java.lang.Exception
- available for subclasses
-
-