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 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
    • Constructor Detail

      • ExternalNotificationListener

        public ExternalNotificationListener()
        Construct a new ExternalNotificationListener. The listener must be configured with a FileProductStorage and command to function.
    • Method Detail

      • configure

        public void configure​(Config config)
                       throws java.lang.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:
        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 interface Configurable
        Overrides:
        shutdown in class DefaultNotificationListener
        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 interface Configurable
        Overrides:
        startup in class DefaultNotificationListener
        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 class DefaultNotificationListener
        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 processed
        productCommand - command that was built
        exception - 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.
      • 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