Class ProductTracker


  • public class ProductTracker
    extends java.lang.Object
    Send updates and search sent updates about distribution status. ProductDistribution clients to send status updates about received notifications, and processed products. Search Example
     ProductTracker tracker = new ProductTracker(new URL(
                    "http://ehppdl1.cr.usgs.gov/tracker/"));
     String source = "us";
     String type = "losspager";
     String code = "us2010abcd";
     Date updateTime = null;
     String className = null;
     List<ProductTrackerUpdate> updates = tracker.getUpdates(source, type, code,
                    updateTime, className);
     
    Update Example
     Product product = ...;
     ProductTracker tracker = new ProductTracker(product.getTrackerURL()).;
     ProductTrackerUpdate update = new ProductTrackerUpdate(product.getTrackerURL(),
                    product.getId(),
                    "my component name",
                    "my component message");
     tracker.sendUpdate(update);
     
    • Field Detail

      • ACTION_SEARCH

        public static final java.lang.String ACTION_SEARCH
        Search a product tracker.
        See Also:
        Constant Field Values
      • ACTION_UPDATE

        public static final java.lang.String ACTION_UPDATE
        Send an update to a product tracker.
        See Also:
        Constant Field Values
      • ARGUMENT_CLASSNAME

        public static final java.lang.String ARGUMENT_CLASSNAME
        Used when searching or sending an update to a product tracker.
        See Also:
        Constant Field Values
      • ARGUMENT_PRODUCT_ID

        public static final java.lang.String ARGUMENT_PRODUCT_ID
        Used when searching or sending an update to a product tracker.
        See Also:
        Constant Field Values
      • ARGUMENT_START_ID

        public static final java.lang.String ARGUMENT_START_ID
        Used when searching.
        See Also:
        Constant Field Values
    • Constructor Detail

      • ProductTracker

        public ProductTracker​(java.net.URL trackerURL)
        Create a new ProductTracker object.
        Parameters:
        trackerURL - location of tracker
    • Method Detail

      • setTrackerEnabled

        public static void setTrackerEnabled​(boolean enabled)
        Set whether sending tracker updates is enabled from this host.
        Parameters:
        enabled - true to send tracker updates, false to disable.
      • getTrackerURL

        public java.net.URL getTrackerURL()
        Returns:
        the trackerURL
      • setTrackerURL

        public void setTrackerURL​(java.net.URL trackerURL)
        Parameters:
        trackerURL - the trackerURL to set
      • sendUpdate

        public ProductTrackerUpdate sendUpdate​(ProductTrackerUpdate update)
                                        throws java.lang.Exception
        Send an update to this ProductTracker.
        Parameters:
        update - the update to send to the tracker.
        Returns:
        the update object processed by the tracker, including sequence number, or null if unable to send.
        Throws:
        java.lang.Exception - if error occurs
      • sendUpdateXML

        public java.lang.String sendUpdateXML​(ProductTrackerUpdate update)
                                       throws java.lang.Exception
        Send an update to this ProductTracker.
        Parameters:
        update - the update to send to the tracker.
        Returns:
        the raw XML returned by the tracker, or null if unable to send.
        Throws:
        java.lang.Exception - if error occurs
      • getUpdates

        public java.util.List<ProductTrackerUpdate> getUpdates​(java.lang.String source,
                                                               java.lang.String type,
                                                               java.lang.String code,
                                                               java.util.Date updateTime,
                                                               java.lang.String className)
                                                        throws java.lang.Exception
        Same as getUpdates with 0 for startid
        Parameters:
        source - product source.
        type - product type.
        code - product code.
        updateTime - product update time.
        className - module name.
        Returns:
        updates matching the provided fields.
        Throws:
        java.lang.Exception - if error occurs
      • getUpdates

        public java.util.List<ProductTrackerUpdate> getUpdates​(java.lang.String source,
                                                               java.lang.String type,
                                                               java.lang.String code,
                                                               java.util.Date updateTime,
                                                               java.lang.String className,
                                                               java.lang.Long startid)
                                                        throws java.lang.Exception
        Search for updates on this tracker. At least one field must be not null, or this method will return no updates.
        Parameters:
        source - product source.
        type - product type.
        code - product code.
        updateTime - product update time.
        className - module name.
        startid - starting ID
        Returns:
        updates matching the provided fields.
        Throws:
        java.lang.Exception - if error occurs
      • getUpdateXML

        public java.lang.String getUpdateXML​(java.lang.String source,
                                             java.lang.String type,
                                             java.lang.String code,
                                             java.util.Date updateTime,
                                             java.lang.String className,
                                             java.lang.Long startid)
                                      throws java.lang.Exception
        Search for updates on this tracker, returning raw xml.
        Parameters:
        source - product source.
        type - product type.
        code - product code.
        updateTime - product update time.
        className - module name.
        startid - start id
        Returns:
        the raw xml response from the tracker.
        Throws:
        java.lang.Exception - if error occurs
      • sendUpdate

        public ProductTrackerUpdate sendUpdate​(java.lang.String className,
                                               ProductId id,
                                               java.lang.String message)
                                        throws java.lang.Exception
        Send a custom tracker update message.
        Parameters:
        className - the module that is sending the message.
        id - the product the message is about.
        message - the message about the product.
        Returns:
        the sent update.
        Throws:
        java.lang.Exception - if error occurs
      • productCreated

        public ProductTrackerUpdate productCreated​(java.lang.String className,
                                                   ProductId id)
                                            throws java.lang.Exception
        Send a productCreated update.
        Parameters:
        className - the module that created the product.
        id - the product that was created.
        Returns:
        the sent update.
        Throws:
        java.lang.Exception - if error occurs
      • productIndexed

        public ProductTrackerUpdate productIndexed​(java.lang.String className,
                                                   ProductId id)
                                            throws java.lang.Exception
        Send a productIndexed update.
        Parameters:
        className - the module that indexed the product.
        id - the product that was indexed.
        Returns:
        the sent update.
        Throws:
        java.lang.Exception - if error occurs
      • notificationSent

        public ProductTrackerUpdate notificationSent​(java.lang.String className,
                                                     Notification notification)
                                              throws java.lang.Exception
        Send a notificationSent update.
        Parameters:
        className - the module that sent the notification.
        notification - the notification that was sent.
        Returns:
        the sent update.
        Throws:
        java.lang.Exception - if error occurs
      • notificationReceived

        public ProductTrackerUpdate notificationReceived​(java.lang.String className,
                                                         Notification notification)
                                                  throws java.lang.Exception
        Send a notificationReceived update.
        Parameters:
        className - the module that received the notification.
        notification - the notification that was received.
        Returns:
        the sent update.
        Throws:
        java.lang.Exception - if error occurs
      • productDownloaded

        public ProductTrackerUpdate productDownloaded​(java.lang.String className,
                                                      ProductId id)
                                               throws java.lang.Exception
        Send a productDownloaded update.
        Parameters:
        className - the module that downloaded the product.
        id - the product that was downloaded.
        Returns:
        the sent update.
        Throws:
        java.lang.Exception - if error occurs
      • productReceived

        public ProductTrackerUpdate productReceived​(java.lang.String className,
                                                    ProductId id)
                                             throws java.lang.Exception
        Send a productReceived update.
        Parameters:
        className - the module that received the product.
        id - the product that was received.
        Returns:
        the sent update.
        Throws:
        java.lang.Exception - if error occurs
      • exception

        public ProductTrackerUpdate exception​(java.lang.String className,
                                              ProductId id,
                                              java.lang.Exception e)
                                       throws java.lang.Exception
        Send an exception update.
        Parameters:
        className - the module that encountered an exception.
        id - the product that was being processed.
        e - the exception that was caught.
        Returns:
        the sent update.
        Throws:
        java.lang.Exception - if error occurs
      • encodeURLData

        public static java.lang.String encodeURLData​(java.util.Map<java.lang.String,​java.lang.String> data)
                                              throws java.lang.Exception
        Encode data for a HTTP Post.
        Parameters:
        data - a map containing name value pairs for encoding.
        Returns:
        a string of encoded data.
        Throws:
        java.lang.Exception - if error occurs
      • post

        public static java.lang.String post​(java.net.URL url,
                                            java.util.Map<java.lang.String,​java.lang.String> data)
                                     throws java.lang.Exception
        Execute a HTTP Post.
        Parameters:
        url - the target url.
        data - the data to send.
        Returns:
        the response text.
        Throws:
        java.lang.Exception - if error occurs
      • parseTrackerResponse

        public java.util.List<ProductTrackerUpdate> parseTrackerResponse​(java.net.URL trackerURL,
                                                                         java.io.InputStream updateStream)
        Parse xml received from a ProductTracker using a ProductTrackerParser.
        Parameters:
        trackerURL - the trackerURL being parsed (so updates are flagged as from this tracker).
        updateStream - the XML response stream from a product tracker.
        Returns:
        a list of parsed updates.
      • main

        public static void main​(java.lang.String[] args)
                         throws java.lang.Exception
        Command Line Interface to ProductTracker.
        Parameters:
        args - CLI arguments
        Throws:
        java.lang.Exception - if error occurs
      • getUsage

        public static java.lang.String getUsage()
        Usage for ProductTracker
        Returns:
        CLI usage