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
,Runnable
- Direct Known Subclasses:
ExtentIndexerListener
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
FieldsModifier and TypeFieldDescriptionprotected static final Logger
Logger objectprotected ProductIndex
Product IndexFields 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 -
Method Summary
Modifier and TypeMethodDescriptionvoid
Sets up an object on startlong
Gets index ID of last processed productGets the next products using the index provided in Configprotected void
Run before thread start.void
onIndexerEvent
(IndexerEvent delta) Wakes thread when indexer makes changesprotected void
onProcessException
(ProductSummary product, Exception e) Exception handling for product processing.protected void
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 functionalityMethods 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 Details
-
LOGGER
Logger object -
productIndex
Product Index
-
-
Constructor Details
-
ReliableIndexerListener
public ReliableIndexerListener()
-
-
Method Details
-
configure
Sets up an object on start- Specified by:
configure
in interfaceConfigurable
- Overrides:
configure
in classDefaultIndexerListener
- Parameters:
config
- configuration- Throws:
Exception
- if missing product index
-
onIndexerEvent
Wakes thread when indexer makes changes- Specified by:
onIndexerEvent
in interfaceIndexerListener
- Overrides:
onIndexerEvent
in classDefaultIndexerListener
- Parameters:
delta
- Indexer Event - not used- Throws:
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. -
startup
Starts thread Calls onBeforeProcessThreadStart() in case subclasses want to add functionality- Specified by:
startup
in interfaceConfigurable
- Overrides:
startup
in classDefaultConfigurable
- Throws:
Exception
- if there's a thread issueException
- if thread start fails
-
shutdown
Closes thread- Specified by:
shutdown
in interfaceConfigurable
- Overrides:
shutdown
in classDefaultConfigurable
- Throws:
Exception
- if there's a thread issue
-
getProductIndex
- Returns:
- ProductIndex
-
setProductIndex
- 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
Run before thread start.- Throws:
Exception
- available for subclasses
-
onProductGetException
Exception handling for product fetch- Parameters:
e
- the caught exception- Throws:
Exception
- in case we can't handle the first exception
-
onProcessException
Exception handling for product processing.- Parameters:
product
- the product that gave us the errore
- the caught exception- Throws:
Exception
- in case we can't handle the first exception.
-
getNextProducts
Gets the next products using the index provided in Config- Returns:
- List of product summaries
- Throws:
Exception
- if we have a database issue
-
processProduct
Does a task with each product- Parameters:
product
- ProductSummary to process- Throws:
Exception
- available for subclasses
-