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
public class ExternalNotificationListener extends DefaultNotificationListener
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
Fields Modifier and Type Field Description static java.lang.String
COMMAND_PROPERTY
Configuration parameter for command.static java.lang.String
SIGNATURE_ARGUMENT
Argument used to pass signature to external process.static java.lang.String
STORAGE_NAME_PROPERTY
Configuration 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_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 Constructor Description ExternalNotificationListener()
Construct a new ExternalNotificationListener.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
commandComplete(Product product, java.lang.String command, int exitValue)
Called when the command finishes executing normally.void
commandException(Product product, java.lang.String productCommand, java.lang.Exception exception)
Called when an exception occurs while running command.void
configure(Config config)
Configure an ExternalNotificationListener using a Config object.java.lang.String
getCommand()
java.lang.String
getProductCommand(Product product)
Append product arguments to the base command.FileProductStorage
getStorage()
void
onProduct(Product product)
Call the external process for this product.void
setCommand(java.lang.String command)
void
setStorage(FileProductStorage storage)
void
shutdown()
Called when client is shutting down.protected static java.lang.String[]
splitCommand(java.lang.String command)
Split a command string into a command array.void
startup()
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, setProcessDuplicates
-
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.distribution.NotificationListener
getMaxTries, getTimeout
-
-
-
-
Field Detail
-
STORAGE_NAME_PROPERTY
public static final java.lang.String STORAGE_NAME_PROPERTY
Configuration parameter for storage directory product.- See Also:
- Constant Field Values
-
COMMAND_PROPERTY
public static final java.lang.String COMMAND_PROPERTY
Configuration parameter for command.- 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
-
configure
public void configure(Config config) throws java.lang.Exception
Configure an ExternalNotificationListener using a Config object.- Specified by:
configure
in interfaceConfigurable
- Overrides:
configure
in classDefaultNotificationListener
- Parameters:
config
- the config containing a- Throws:
java.lang.Exception
- if configuration exceptions occur.
-
shutdown
public void shutdown() throws java.lang.Exception
Called when client is shutting down.- Specified by:
shutdown
in interfaceConfigurable
- Overrides:
shutdown
in classDefaultNotificationListener
- Throws:
java.lang.Exception
- if exceptions occur while starting.
-
startup
public void startup() throws java.lang.Exception
Called after client has been configured and should begin processing.- Specified by:
startup
in interfaceConfigurable
- Overrides:
startup
in classDefaultNotificationListener
- Throws:
java.lang.Exception
- if exceptions occur while starting.
-
getProductCommand
public java.lang.String getProductCommand(Product product) throws java.lang.Exception
Append product arguments to the base command.- Parameters:
product
- the product used to generate arguments.- Returns:
- command as a string.
- Throws:
java.lang.Exception
- if error occurs
-
splitCommand
protected static java.lang.String[] splitCommand(java.lang.String command)
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
public void onProduct(Product product) throws java.lang.Exception
Call the external process for this product.- Overrides:
onProduct
in classDefaultNotificationListener
- Parameters:
product
- Product- Throws:
java.lang.Exception
- if error occurs
-
commandComplete
public void commandComplete(Product product, java.lang.String command, int exitValue) throws java.lang.Exception
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:
java.lang.Exception
- When re-notification should occur, based on maxTries, or none if done.
-
commandException
public void commandException(Product product, java.lang.String productCommand, java.lang.Exception exception) throws java.lang.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:
java.lang.Exception
- When re-notification should occur, based on maxTries, or none if done.
-
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
-
-