Package gov.usgs.earthquake.distribution
Class ExternalNotificationListener
java.lang.Object
gov.usgs.util.DefaultConfigurable
gov.usgs.earthquake.product.AbstractListener
gov.usgs.earthquake.distribution.DefaultNotificationListener
gov.usgs.earthquake.distribution.ExternalNotificationListener
- All Implemented Interfaces:
NotificationIndexCleanup.Listener,NotificationListener,Configurable
- Direct Known Subclasses:
DYFIIndexerWedge
An external process that is called when new products arrive.
The ExternalNotificationListener implements the Configurable interface and
can use the following configuration 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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringConfiguration parameter for command.static final StringArgument used to pass signature to external process.static final StringConfiguration parameter for storage directory product.Fields 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_DUPLICATESFields 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
ConstructorsConstructorDescriptionConstruct a new ExternalNotificationListener. -
Method Summary
Modifier and TypeMethodDescriptionvoidcommandComplete(Product product, String command, int exitValue) Called when the command finishes executing normally.voidcommandException(Product product, String productCommand, Exception exception) Called when an exception occurs while running command.voidConfigure an ExternalNotificationListener using a Config object.getProductCommand(Product product) Append product arguments to the base command.voidCall the external process for this product.voidsetCommand(String command) voidsetStorage(FileProductStorage storage) voidshutdown()Called when client is shutting down.protected static String[]splitCommand(String command) Split a command string into a command array.voidstartup()Called after client has been configured and should begin processing.Methods inherited from class gov.usgs.earthquake.distribution.DefaultNotificationListener
cleanup, getCleanupInterval, getConcurrentProducts, getExcludePaths, getIncludePaths, getNotificationIndex, isProcessDuplicates, onAfterProcessNotification, onBeforeProcessNotification, onBeforeProcessProduct, onExpiredNotification, onNotification, setCleanupInterval, setConcurrentProducts, setNotificationIndex, setProcessDuplicatesMethods 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, setTimeoutMethods inherited from class gov.usgs.util.DefaultConfigurable
getName, setNameMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface gov.usgs.util.Configurable
getName, setNameMethods inherited from interface gov.usgs.earthquake.distribution.NotificationListener
getMaxTries, getTimeout
-
Field Details
-
STORAGE_NAME_PROPERTY
Configuration parameter for storage directory product.- See Also:
-
COMMAND_PROPERTY
Configuration parameter for command.- See Also:
-
SIGNATURE_ARGUMENT
Argument used to pass signature to external process.- See Also:
-
-
Constructor Details
-
ExternalNotificationListener
public ExternalNotificationListener()Construct a new ExternalNotificationListener. The listener must be configured with a FileProductStorage and command to function.
-
-
Method Details
-
configure
Configure an ExternalNotificationListener using a Config object.- Specified by:
configurein interfaceConfigurable- Overrides:
configurein classDefaultNotificationListener- Parameters:
config- the config containing a- Throws:
Exception- if configuration exceptions occur.
-
shutdown
Called when client is shutting down.- Specified by:
shutdownin interfaceConfigurable- Overrides:
shutdownin classDefaultNotificationListener- Throws:
Exception- if exceptions occur while starting.
-
startup
Called after client has been configured and should begin processing.- Specified by:
startupin interfaceConfigurable- Overrides:
startupin classDefaultNotificationListener- Throws:
Exception- if exceptions occur while starting.
-
getProductCommand
Append product arguments to the base command.- Parameters:
product- the product used to generate arguments.- Returns:
- command as a string.
- Throws:
Exception- if error occurs
-
splitCommand
Split a command string into a command array. This version uses a StringTokenizer to split arguments. Quoted arguments are supported (single or double), with quotes removed before passing to runtime. Double quoting arguments will preserve quotes when passing to runtime.- Parameters:
command- command to run.- Returns:
- Array of arguments suitable for passing to Runtime.exec(String[]).
-
onProduct
Call the external process for this product.- Overrides:
onProductin classDefaultNotificationListener- Parameters:
product- Product- Throws:
Exception- if error occurs
-
commandComplete
Called when the command finishes executing normally. This implementation throws a NotificationListenerException if the exitValue is non-zero.- Parameters:
product- the product being processed.command- the generated command, as a string.exitValue- the exit status of the process.- Throws:
Exception- When re-notification should occur, based on maxTries, or none if done.
-
commandException
public void commandException(Product product, String productCommand, Exception exception) throws Exception Called when an exception occurs while running command. This implementation throws a NotificationListenerException with exception as the cause.- Parameters:
product- product being processedproductCommand- command that was builtexception- exception that was thrown during execution. This will be an InterruptedException if the process timed out.- Throws:
Exception- When re-notification should occur, based on maxTries, or none if done.
-
getStorage
- Returns:
- the storage
-
setStorage
- Parameters:
storage- the storage to set
-
getCommand
- Returns:
- the command
-
setCommand
- Parameters:
command- the command to set
-