Class 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 Details

    • STORAGE_NAME_PROPERTY

      public static final String STORAGE_NAME_PROPERTY
      Configuration parameter for storage directory product.
      See Also:
    • COMMAND_PROPERTY

      public static final String COMMAND_PROPERTY
      Configuration parameter for command.
      See Also:
    • SIGNATURE_ARGUMENT

      public static final String 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

      public void configure(Config config) throws Exception
      Configure an ExternalNotificationListener using a Config object.
      Specified by:
      configure in interface Configurable
      Overrides:
      configure in class DefaultNotificationListener
      Parameters:
      config - the config containing a
      Throws:
      Exception - if configuration exceptions occur.
    • shutdown

      public void shutdown() throws Exception
      Called when client is shutting down.
      Specified by:
      shutdown in interface Configurable
      Overrides:
      shutdown in class DefaultNotificationListener
      Throws:
      Exception - if exceptions occur while starting.
    • startup

      public void startup() throws Exception
      Called after client has been configured and should begin processing.
      Specified by:
      startup in interface Configurable
      Overrides:
      startup in class DefaultNotificationListener
      Throws:
      Exception - if exceptions occur while starting.
    • getProductCommand

      public String getProductCommand(Product product) throws Exception
      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

      protected static String[] splitCommand(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 Exception
      Call the external process for this product.
      Overrides:
      onProduct in class DefaultNotificationListener
      Parameters:
      product - Product
      Throws:
      Exception - if error occurs
    • commandComplete

      public void commandComplete(Product product, String command, int exitValue) throws 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:
      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 processed
      productCommand - command that was built
      exception - 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

      public FileProductStorage getStorage()
      Returns:
      the storage
    • setStorage

      public void setStorage(FileProductStorage storage)
      Parameters:
      storage - the storage to set
    • getCommand

      public String getCommand()
      Returns:
      the command
    • setCommand

      public void setCommand(String command)
      Parameters:
      command - the command to set