Package gov.usgs.earthquake.indexer
Class Indexer
java.lang.Object
gov.usgs.util.DefaultConfigurable
gov.usgs.earthquake.product.AbstractListener
gov.usgs.earthquake.distribution.DefaultNotificationListener
gov.usgs.earthquake.indexer.Indexer
- All Implemented Interfaces:
NotificationIndexCleanup.Listener
,NotificationListener
,Configurable
The indexer receives products from Distribution, and adds them to the
EventIndex.
This class provides the following configurable properties (in addition to
those inherited from DefaultNotificationListener):
- associator
- An object that implements the Associator interface.
- storage
- An object that implements the ProductStorage interface.
- index
- An object that implements the ProductIndex interface.
- modules
- A comma delimited list of objects that implement the IndexerModule interface
- listeners
- A comma delimited list of objects that implement the IndexerListener interface
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Property to associate using current productsstatic final String
Property name to configure a custom associator.static final String
Default state for associate using current productsstatic final String
Default value whether to enable search socket.static final String
Path to local regions file.static final String
Default port where search socket listens.static final String
Number of threads (concurrent searches) allowed.static final String
Property name to enable search socket.static final String
Property for geoserve endpointstatic final String
Configurable property for index archive internalstatic final String
Configurable property for index archive policystatic final String
Property name to configure a custom index.static final String
Shortcut name to configure a sqlite index.static final String
Property name to configure listeners.static final String
Property name to configure local regions file.static final String
Property name to configure modules.static final String
Prefix for persistent trumpstatic final String
Property name for search socket port.static final String
Property name for search socket thread pool size.static final String
Property name to configure a custom storage.static final String
Shortcut name to configure a file product storage.static final long
Preferred weight for persistent trump.static final String
Type for persistent trimpFields inherited from class gov.usgs.earthquake.distribution.DefaultNotificationListener
CLEANUP_INTERVAL_PROPERTY, CONCURRENT_PRODUCTS_PROPERTY, DEFAULT_CLEANUP_INTERVAL, DEFAULT_CONCURRENT_PRODUCTS, DEFAULT_PROCESS_DUPLICATES, EXCLUDE_PATHS_PROPERTY, INCLUDE_PATHS_PROPERTY, INDEX_FILE_PROPERTY, NOTIFICATION_INDEX_PROPERTY, PROCESS_DUPLICATES
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 TypeMethodDescriptionboolean
Override the DefaultNotificationListener accept method, to always process products that may affect event association.void
addListener
(IndexerListener toAdd) Adds a listener to this indexer.void
addModule
(IndexerModule toAdd) Adds the give indexer module to the current list of modules used by the indexer to handle products.protected List<IndexerChange>
checkForEventMerges
(ProductSummary summary, Event originalEvent, Event updatedEvent) Check and merge any nearby events or previously unassociated products that now associate.protected List<IndexerChange>
checkForEventSplits
(ProductSummary summary, Event originalEvent, Event updatedEvent) Check for event splits (and split them if needed).void
Loads parent, specific, and dependent configurations; in that order.long
Returns the current associator used to associate products to one-another and products to events.protected IndexerModule
This method checks each module's support level for the given product, returning the first module with the highest support level.protected Event
getPrevEvent
(ProductSummary summary) Associate products are processed duringcheckForEventMerges(ProductSummary, Event, Event)
and are ignored during this method.protected Event
getPrevEvent
(ProductSummary summary, boolean associating) Find an existing event that summary should associate with.protected ProductSummary
getPrevProductVersion
(ProductSummary summary) Takes a summary return the previousReturns the product index component used to index product information as it is received.Returns the product storage component that is used to store products as they are received.protected ProductSummary
Get a product summary object using its product id.protected ProductId
getTrumpedProductId
(ProductSummary trumpSummary) Get the productId referred to by a trump product.protected boolean
Check whether this product is in the index.protected ProductSummary
indexProduct
(ProductSummary productSummary) Add product summary to product index.boolean
protected Event
mergeEvents
(Event target, Event child) Merges the child event (and all its products) into the target event.protected void
notifyListeners
(IndexerEvent event) Send an indexer event to all registered IndexerListeners.protected boolean
onBeforeProcessNotification
(Notification notification) Check whether to skip products that have already been indexed.void
This method receives a product from Product Distribution and adds it to the index.void
Receive a product and add it to the index.int[]
Checks the index for content that match a configured archive policy.protected void
removeEvent
(Event event) Removes the given event from the Indexer ProductIndex and ProductStorage.void
removeListener
(IndexerListener toRemove) Removes a listener from this indexer.Listeners are notified when an event is added, updated, or deleted, or when a new product arrives and is un-associated to an event.void
removeModule
(IndexerModule toRemove) Removes the first occurrence of the given indexer module from the current list of known modules.protected void
removeSummary
(ProductSummary summary) Removes the given summary from the Indexer ProductIndex and ProductStorage.protected Event
resummarizeProduct
(Event event, ProductSummary summary) Resummarize a product within an event.search
(SearchRequest request) Search for products in this index.void
setArchiveInterval
(long archiveInterval) void
setAssociator
(Associator associator) Sets the given associator as the current associator to associate products to one-another and products to events.void
setDisableArchive
(boolean disableArchive) void
setProductIndex
(ProductIndex productIndex) Sets the product index component used to index product information as it is received.void
setProductStorage
(ProductStorage productStorage) Sets the current product storage component used to store products as they are received.protected Event
setSummaryWeight
(Event event, ProductSummary summary, Long preferredWeight) Update a product summary weightvoid
shutdown()
Shuts down the Indexer.protected Event
splitEvents
(Event root, Event leaf) Removes the leaf event (and all its products) from the root event.void
startup()
Starts up the necessary parent, specific, and dependent processes, in that order.storeProduct
(Product product, boolean force) Stores a productsummarizeProduct
(Product product) Use modules to summarize product.Methods inherited from class gov.usgs.earthquake.distribution.DefaultNotificationListener
cleanup, getCleanupInterval, getConcurrentProducts, getExcludePaths, getIncludePaths, getNotificationIndex, isProcessDuplicates, onAfterProcessNotification, onBeforeProcessProduct, onExpiredNotification, onNotification, setCleanupInterval, setConcurrentProducts, setNotificationIndex, setProcessDuplicates
Methods inherited from class gov.usgs.earthquake.product.AbstractListener
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
-
TRUMP_PREFERRED_WEIGHT
public static final long TRUMP_PREFERRED_WEIGHTPreferred weight for persistent trump.- See Also:
-
TRUMP_PRODUCT_TYPE
Type for persistent trimp- See Also:
-
PERSISTENT_TRUMP_PREFIX
Prefix for persistent trump- See Also:
-
ASSOCIATOR_CONFIG_PROPERTY
Property name to configure a custom associator.- See Also:
-
ASSOCIATE_USING_CURRENT_PRODUCTS_PROPERTY
Property to associate using current products- See Also:
-
DEFAULT_ASSOCIATE_USING_CURRENT_PRODUCTS
Default state for associate using current products- See Also:
-
STORAGE_CONFIG_PROPERTY
Property name to configure a custom storage.- See Also:
-
STORAGE_DIRECTORY_CONFIG_PROPERTY
Shortcut name to configure a file product storage.- See Also:
-
INDEX_CONFIG_PROPERTY
Property name to configure a custom index.- See Also:
-
INDEXFILE_CONFIG_PROPERTY
Shortcut name to configure a sqlite index.- See Also:
-
MODULES_CONFIG_PROPERTY
Property name to configure modules.- See Also:
-
LISTENERS_CONFIG_PROPERTY
Property name to configure listeners.- See Also:
-
LOCAL_REGIONS_PROPERTY
Property name to configure local regions file.- See Also:
-
DEFAULT_LOCAL_REGIONS
Path to local regions file.- See Also:
-
GEOSERVE_ENDPOINT_URL_PROPERTY
Property for geoserve endpoint- See Also:
-
ENABLE_SEARCH_PROPERTY
Property name to enable search socket.- See Also:
-
SEARCH_PORT_PROPERTY
Property name for search socket port.- See Also:
-
SEARCH_THREADS_PROPERTY
Property name for search socket thread pool size.- See Also:
-
DEFAULT_ENABLE_SEARCH
Default value whether to enable search socket.- See Also:
-
DEFAULT_SEARCH_PORT
Default port where search socket listens.- See Also:
-
DEFAULT_SEARCH_THREADS
Number of threads (concurrent searches) allowed.- See Also:
-
INDEX_ARCHIVE_INTERVAL_PROPERTY
Configurable property for index archive internal- See Also:
-
INDEX_ARCHIVE_POLICY_PROPERTY
Configurable property for index archive policy- See Also:
-
-
Constructor Details
-
Indexer
Default no-arg constructor. This gets called from the Configurable API. All configuration parameters are set in the "configure" method.- Throws:
Exception
- If the JDBCProductIndex throws an exception.
-
-
Method Details
-
getAssociator
Returns the current associator used to associate products to one-another and products to events.- Returns:
- The current Associator.
-
setAssociator
Sets the given associator as the current associator to associate products to one-another and products to events.- Parameters:
associator
- The associator to use from this point forward.
-
getProductStorage
Returns the product storage component that is used to store products as they are received.- Returns:
- The current product storage component.
-
setProductStorage
Sets the current product storage component used to store products as they are received.- Parameters:
productStorage
- The product storage component to use from this point forward.
-
getProductIndex
Returns the product index component used to index product information as it is received.- Returns:
- The current product index component.
-
setProductIndex
Sets the product index component used to index product information as it is received.- Parameters:
productIndex
- The product index component to use from this point forward.
-
addModule
Adds the give indexer module to the current list of modules used by the indexer to handle products.- Parameters:
toAdd
- The IndexerModule to add to our list.
-
removeModule
Removes the first occurrence of the given indexer module from the current list of known modules.- Parameters:
toRemove
- The module to remove.- See Also:
-
getModule
This method checks each module's support level for the given product, returning the first module with the highest support level.- Parameters:
product
- the product to summarize.- Returns:
- module best suited to summarize product.
-
addListener
Adds a listener to this indexer. Listeners are notified when an event is added, updated, or deleted, or when a new product arrives and is un-associated to an event.- Parameters:
toAdd
- The IndexerListener to add
-
removeListener
Removes a listener from this indexer.Listeners are notified when an event is added, updated, or deleted, or when a new product arrives and is un-associated to an event.- Parameters:
toRemove
- The IndexerListener to remove
-
notifyListeners
Send an indexer event to all registered IndexerListeners. Creates a NotificationEvent, with a reference to this object and calls each notificationListeners onNotification method in separate threads. This method usually returns before registered NotificationListeners have completed processing a notification.- Parameters:
event
- The event that occurred to trigger the notification. Note: An IndexerEvent has a specific "type" to clarify the type of event that occurred.
-
hasProductBeenIndexed
Check whether this product is in the index. NOT synchronized to allow multiple threads to access. readProductIndex.hasProduct is synchronized.- Parameters:
id
- ProductId to check- Returns:
- true if product has already been indexed.
-
accept
Override the DefaultNotificationListener accept method, to always process products that may affect event association.- Overrides:
accept
in classAbstractListener
- Parameters:
id
- the product id to check.- Returns:
- boolean whether the product should be indexed.
-
onBeforeProcessNotification
Check whether to skip products that have already been indexed.- Overrides:
onBeforeProcessNotification
in classDefaultNotificationListener
- Parameters:
notification
- notification about to be processed.- Returns:
- true to process the notification, false to skip
- Throws:
Exception
- if error occurs
-
onProduct
This method receives a product from Product Distribution and adds it to the index. Implementation follows from Product Indexer Diagram (pg.10) of ProductIndexer.pdf document dated 09/09/2010. Calls onProduct(product, false), which will not reprocess already processed products.- Overrides:
onProduct
in classDefaultNotificationListener
- Parameters:
product
- The product triggering the event.- Throws:
Exception
- if an exception occurs.
-
onProduct
Receive a product and add it to the index. Optionally, reprocessing a product that has already been processed.- Parameters:
product
- The product triggering the event.force
- Whether to reprocess products that have already been processed (true), or skip (false).- Throws:
Exception
- if error occurs
-
storeProduct
Stores a product- Parameters:
product
- Product to storeforce
- if should skip already indexed check- Returns:
- Product if stored, null if not
- Throws:
Exception
- if error occurs
-
summarizeProduct
Use modules to summarize product.- Parameters:
product
- To summarize- Returns:
- A product summary
- Throws:
Exception
- if error occurs
-
indexProduct
Add product summary to product index.- Parameters:
productSummary
- to add- Returns:
- Summary added to index
- Throws:
Exception
- if error occurs
-
getTrumpedProductId
Get the productId referred to by a trump product.- Parameters:
trumpSummary
- trump product with reference to product id.- Returns:
- product id, or null if unable to parse product id.
-
getProductSummaryById
Get a product summary object using its product id.- Parameters:
id
- id to find.- Returns:
- matching product summary or null.
- Throws:
Exception
- if error occurs
-
setSummaryWeight
protected Event setSummaryWeight(Event event, ProductSummary summary, Long preferredWeight) throws Exception Update a product summary weight- Parameters:
event
- the event.summary
- the summary.preferredWeight
- the weight to set.- Returns:
- event with updated summary.
- Throws:
Exception
- if error occurs
-
resummarizeProduct
Resummarize a product within an event.- Parameters:
event
- the event.summary
- the summary.- Returns:
- event with updated summary.
- Throws:
Exception
- if error occurs
-
checkForEventSplits
protected List<IndexerChange> checkForEventSplits(ProductSummary summary, Event originalEvent, Event updatedEvent) throws Exception Check for event splits (and split them if needed).- Parameters:
summary
- the summary the indexer is currently processing.originalEvent
- the event before the indexer made any changes.updatedEvent
- the event after the indexer made any changes.- Returns:
- List of changes made during this method.
- Throws:
Exception
- if error occurs
-
splitEvents
Removes the leaf event (and all its products) from the root event. This method modifies the runtime objects as well as updating the index DB.- Parameters:
root
- The root event from which all leaf products will be removedleaf
- The event (with products) that will be removed from the root- Returns:
- copy of root without the products that have been removed. The indexId property of leaf is updated to its new value.
- Throws:
Exception
- if error occurs
-
mergeEvents
Merges the child event (and all its products) into the target event. If the child event attempts to merge in a product that is the same as one already associated to the target event, the child version of the product takes precedence. Note: This only applies when the target and child product have the same type, code, source, and update time; i.e. the products are duplicates. This method modifies the runtime objects as well as the index DB. The child event is then deleted.- Parameters:
target
- The target event into which the child is merged.child
- The child event to be merged into the target.- Returns:
- the updated event
- Throws:
Exception
- if error occurs
-
checkForEventMerges
protected List<IndexerChange> checkForEventMerges(ProductSummary summary, Event originalEvent, Event updatedEvent) throws Exception Check and merge any nearby events or previously unassociated products that now associate.- Parameters:
summary
- the summary currently being processed by the indexer.originalEvent
- the event before any changes.updatedEvent
- the event after the summary was associated.- Returns:
- list of any merge type changes.
- Throws:
Exception
- if error occurs
-
getPrevProductVersion
Takes a summary return the previous- Parameters:
summary
- A product summary- Returns:
- The previous summary
- Throws:
Exception
- if error occurs
-
getPrevEvent
Associate products are processed duringcheckForEventMerges(ProductSummary, Event, Event)
and are ignored during this method.- Parameters:
summary
- ProductSummary- Returns:
- Event to which a productSummary is associated, or null if not found.
- Throws:
Exception
- if error occurs- See Also:
-
getPrevEvent
Find an existing event that summary should associate with.- Parameters:
summary
- the previous event.associating
- whether associating (vs archiving).- Returns:
- previous event, or null if none found.
- Throws:
Exception
- if error occurs
-
configure
Loads parent, specific, and dependent configurations; in that order.- Specified by:
configure
in interfaceConfigurable
- Overrides:
configure
in classDefaultNotificationListener
- Parameters:
config
- the Config object with settings.- Throws:
Exception
- if configuration exceptions occur.
-
shutdown
Shuts down the Indexer. The parent shutdown method is called and then all executor services (from listeners) are shutdown in sequence.- Specified by:
shutdown
in interfaceConfigurable
- Overrides:
shutdown
in classDefaultNotificationListener
- Throws:
Exception
- if exceptions occur while starting.
-
startup
Starts up the necessary parent, specific, and dependent processes, in that order.- Specified by:
startup
in interfaceConfigurable
- Overrides:
startup
in classDefaultNotificationListener
- Throws:
Exception
- if exceptions occur while starting.
-
purgeExpiredProducts
Checks the index for content that match a configured archive policy. Events are checked first and matched events are removed along with all their products. Listeners are notified of each archived event with an EVENT_ARCHIVED type. Unassociated products are checked next, matched unassociated products are archived and listeners are notified with PRODUCT_ARCHIVE type. Note: Product "age" is determined by when the earthquake for that product occurred and does not reflect how long the product has actually been in the index.- Returns:
- Int array of size 2
- Throws:
Exception
- if error occurs- See Also:
-
archivePolicies
-
removeEvent
Removes the given event from the Indexer ProductIndex and ProductStorage.- Parameters:
event
- event to remove- Throws:
Exception
- If errors occur while removing the event
-
removeSummary
Removes the given summary from the Indexer ProductIndex and ProductStorage.- Parameters:
summary
- to remove- Throws:
Exception
- If errors occur while removing the summary
-
search
Search for products in this index.- Parameters:
request
- the search request.- Returns:
- the search response.
- Throws:
Exception
- if error occurs
-
isDisableArchive
public boolean isDisableArchive()- Returns:
- disableArchive
-
setDisableArchive
public void setDisableArchive(boolean disableArchive) - Parameters:
disableArchive
- boolean to set
-
getArchiveInterval
public long getArchiveInterval()- Returns:
- the archiveInterval
-
setArchiveInterval
public void setArchiveInterval(long archiveInterval) - Parameters:
archiveInterval
- the archiveInterval to set
-
getArchivePolicies
- Returns:
- the archivePolicies
-