Package gov.usgs.earthquake.indexer
Class ExternalIndexerListener
- java.lang.Object
-
- gov.usgs.util.DefaultConfigurable
-
- gov.usgs.earthquake.product.AbstractListener
-
- gov.usgs.earthquake.indexer.DefaultIndexerListener
-
- gov.usgs.earthquake.indexer.ExternalIndexerListener
-
- All Implemented Interfaces:
IndexerListener,Configurable
- Direct Known Subclasses:
ExternalPreferredListener
public class ExternalIndexerListener extends DefaultIndexerListener
ExternalIndexerListener triggers external, non-Java listener processes. Provides a translation to a command-line interface for the product indexer to speak with external, non-Java listeners. As a child-class of the AbstractListener, this also accepts the following configration parameters:- command
- (Required) The command to execute. This must be an executable command and may include arguments. Any product-specific arguments are appended at the end of command.
- storage
- (Required) A directory used to store all products. Each product is extracted into a separate directory within this directory and is referenced by the --directory=/path/to/directory argument when command is executed.
- processUnassociated
- (Optional, Default = false) Whether or not to process unassociated products. Valid values are "true" and "false".
- processPreferredOnly
- (Optional, Default = false) Whether or not to process only preferred products of the type accepted by this listener. Valid values are "true" and "false".
- autoArchive
- (Optional, Default = false) Whether or not to archive products from storage when they are archived by the indexer.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringAUTO_ARCHIVE_DEFAULTDefault state for auto archivestatic java.lang.StringAUTO_ARCHIVE_PROPERTYConfiguration parameter for autoArchive.static java.lang.StringCOMMAND_PROPERTYConfiguration parameter for command.static java.lang.StringEVENT_ACTION_ARGUMENTArgument for event actionstatic java.lang.StringEVENT_IDS_ARGUMENTArgument for event idsstatic java.lang.StringPREFERRED_DEPTH_ARGUMENTArgument for preferred depthstatic java.lang.StringPREFERRED_EVENTSOURCE_ARGUMENTArgument for preferred eventsourcestatic java.lang.StringPREFERRED_EVENTSOURCECODE_ARGUMENTArgument for preferred eventsourcecodestatic java.lang.StringPREFERRED_ID_ARGUMENTArgument for preferred event idstatic java.lang.StringPREFERRED_LATITUDE_ARGUMENTArgument for preferred latitudestatic java.lang.StringPREFERRED_LONGITUDE_ARGUMENTArgument for preferred longitudestatic java.lang.StringPREFERRED_MAGNITUDE_ARGUMENTArgument for preferred magnitudestatic java.lang.StringPREFERRED_ORIGIN_TIME_ARGUMENTArgument for preferred eventitmestatic java.lang.StringSIGNATURE_ARGUMENTArgument used to pass signature to external process.static java.lang.StringSTORAGE_DIRECTORY_PROPERTYShort circuit to directly configure storage directory.static java.lang.StringSTORAGE_NAME_PROPERTYConfiguration parameter for storage directory product.-
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 ExternalIndexerListener()Construct a new ExternalIndexerListener object The listener must be configured with a FileProductStorage and a command to function.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconfigure(Config config)Configure an ExternalNotificationListener using a Config object.java.lang.StringgetCommand()java.lang.StringgetEventArguments(Event event)Get command line arguments for an event.java.lang.StringgetProductSummaryArguments(ProductSummary summary)Get command line arguments for a product summary.java.lang.StringgetProductSummaryCommand(Event event, ProductSummary summary)Get the command for a specific event and summary.java.lang.StringgetProductSummaryCommand(IndexerEvent change, IndexerChange indexerChange)Get the product command and add the indexer arguments to it.FileProductStoragegetStorage()booleanisAutoArchive()voidonIndexerEvent(IndexerEvent change)This method is called when the indexer makes a change to the ProductIndex.voidrunProductCommand(java.lang.String command, Product product)Run a product command.voidsetAutoArchive(boolean autoArchive)voidsetCommand(java.lang.String command)voidsetStorage(FileProductStorage storage)voidshutdown()Called when client is shutting down.voidstartup()Called after client has been configured and should begin processing.ProductstoreProduct(Product product)Store product associated with the change.-
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
-
EVENT_ACTION_ARGUMENT
public static final java.lang.String EVENT_ACTION_ARGUMENT
Argument for event action- See Also:
- Constant Field Values
-
EVENT_IDS_ARGUMENT
public static final java.lang.String EVENT_IDS_ARGUMENT
Argument for event ids- See Also:
- Constant Field Values
-
PREFERRED_ID_ARGUMENT
public static final java.lang.String PREFERRED_ID_ARGUMENT
Argument for preferred event id- See Also:
- Constant Field Values
-
PREFERRED_EVENTSOURCE_ARGUMENT
public static final java.lang.String PREFERRED_EVENTSOURCE_ARGUMENT
Argument for preferred eventsource- See Also:
- Constant Field Values
-
PREFERRED_EVENTSOURCECODE_ARGUMENT
public static final java.lang.String PREFERRED_EVENTSOURCECODE_ARGUMENT
Argument for preferred eventsourcecode- See Also:
- Constant Field Values
-
PREFERRED_MAGNITUDE_ARGUMENT
public static final java.lang.String PREFERRED_MAGNITUDE_ARGUMENT
Argument for preferred magnitude- See Also:
- Constant Field Values
-
PREFERRED_LONGITUDE_ARGUMENT
public static final java.lang.String PREFERRED_LONGITUDE_ARGUMENT
Argument for preferred longitude- See Also:
- Constant Field Values
-
PREFERRED_LATITUDE_ARGUMENT
public static final java.lang.String PREFERRED_LATITUDE_ARGUMENT
Argument for preferred latitude- See Also:
- Constant Field Values
-
PREFERRED_DEPTH_ARGUMENT
public static final java.lang.String PREFERRED_DEPTH_ARGUMENT
Argument for preferred depth- See Also:
- Constant Field Values
-
PREFERRED_ORIGIN_TIME_ARGUMENT
public static final java.lang.String PREFERRED_ORIGIN_TIME_ARGUMENT
Argument for preferred eventitme- See Also:
- Constant Field Values
-
STORAGE_NAME_PROPERTY
public static final java.lang.String STORAGE_NAME_PROPERTY
Configuration parameter for storage directory product.- See Also:
- Constant Field Values
-
STORAGE_DIRECTORY_PROPERTY
public static final java.lang.String STORAGE_DIRECTORY_PROPERTY
Short circuit to directly configure storage directory.- See Also:
- Constant Field Values
-
COMMAND_PROPERTY
public static final java.lang.String COMMAND_PROPERTY
Configuration parameter for command.- See Also:
- Constant Field Values
-
AUTO_ARCHIVE_PROPERTY
public static final java.lang.String AUTO_ARCHIVE_PROPERTY
Configuration parameter for autoArchive.- See Also:
- Constant Field Values
-
AUTO_ARCHIVE_DEFAULT
public static final java.lang.String AUTO_ARCHIVE_DEFAULT
Default state for auto archive- See Also:
- Constant Field Values
-
SIGNATURE_ARGUMENT
public static final java.lang.String SIGNATURE_ARGUMENT
Argument used to pass signature to external process.- See Also:
- Constant Field Values
-
-
Method Detail
-
onIndexerEvent
public void onIndexerEvent(IndexerEvent change) throws java.lang.Exception
Description copied from interface:IndexerListenerThis method is called when the indexer makes a change to the ProductIndex.- Specified by:
onIndexerEventin interfaceIndexerListener- Overrides:
onIndexerEventin classDefaultIndexerListener- Parameters:
change- description of the change.- Throws:
java.lang.Exception- if error occurs
-
storeProduct
public Product storeProduct(Product product) throws java.lang.Exception
Store product associated with the change.- Parameters:
product- product to be stored.- Returns:
- a new product object, read from the listener storage.
- Throws:
java.lang.Exception- if error occurs
-
runProductCommand
public void runProductCommand(java.lang.String command, Product product) throws java.lang.ExceptionRun a product command.- Parameters:
command- command and arguments.product- product, when set and empty content (path "") is defined, the content is provided to the command on stdin.- Throws:
java.lang.Exception- if error occurs
-
getProductSummaryCommand
public java.lang.String getProductSummaryCommand(IndexerEvent change, IndexerChange indexerChange) throws java.lang.Exception
Get the product command and add the indexer arguments to it.- Parameters:
change- The IndexerEvent received by the ExternalIndexerListenerindexerChange- The IndexerChange- Returns:
- the command to execute with its arguments as a string
- Throws:
java.lang.Exception- if error occurs
-
getProductSummaryCommand
public java.lang.String getProductSummaryCommand(Event event, ProductSummary summary) throws java.lang.Exception
Get the command for a specific event and summary.- Parameters:
event- Specific eventsummary- Specific product summary- Returns:
- command line arguments as a string.
- Throws:
java.lang.Exception- if error occurs
-
getEventArguments
public java.lang.String getEventArguments(Event event)
Get command line arguments for an event.- Parameters:
event- the event- Returns:
- command line arguments
-
getProductSummaryArguments
public java.lang.String getProductSummaryArguments(ProductSummary summary) throws java.io.IOException
Get command line arguments for a product summary.- Parameters:
summary- the product summary- Returns:
- command line arguments
- Throws:
java.io.IOException- if IO error occurs
-
configure
public void configure(Config config) throws java.lang.Exception
Configure an ExternalNotificationListener using a Config object.- Specified by:
configurein interfaceConfigurable- Overrides:
configurein classDefaultIndexerListener- Parameters:
config- the config containing a- Throws:
java.lang.Exception- if configuration exceptions occur.
-
shutdown
public void shutdown() throws java.lang.ExceptionCalled when client is shutting down.- Specified by:
shutdownin interfaceConfigurable- Overrides:
shutdownin classDefaultConfigurable- Throws:
java.lang.Exception- if exceptions occur while starting.
-
startup
public void startup() throws java.lang.ExceptionCalled after client has been configured and should begin processing.- Specified by:
startupin interfaceConfigurable- Overrides:
startupin classDefaultConfigurable- Throws:
java.lang.Exception- if exceptions occur while starting.
-
getStorage
public FileProductStorage getStorage()
- Returns:
- the storage
-
setStorage
public void setStorage(FileProductStorage storage)
- Parameters:
storage- the storage to set
-
getCommand
public java.lang.String getCommand()
- Returns:
- the command
-
setCommand
public void setCommand(java.lang.String command)
- Parameters:
command- the command to set
-
isAutoArchive
public boolean isAutoArchive()
- Returns:
- the autoArchive
-
setAutoArchive
public void setAutoArchive(boolean autoArchive)
- Parameters:
autoArchive- the autoArchive to set
-
-