Package hudson.model

Class DownloadService.Downloadable

  • All Implemented Interfaces:
    ExtensionPoint
    Enclosing class:
    DownloadService

    public static class DownloadService.Downloadable
    extends Object
    implements ExtensionPoint
    Represents a periodically updated JSON data file obtained from a remote URL.

    This mechanism is one of the basis of the update center, which involves fetching up-to-date data file.

    Since:
    1.305
    • Constructor Detail

      • Downloadable

        public Downloadable​(@NonNull
                            String id,
                            @NonNull
                            String url,
                            long interval)
        Creates a new downloadable.
        Parameters:
        id - The ID to use.
        url - URL relative to UpdateCenter.getDefaultBaseUrl(). So if this string is "foo.json", the ultimate URL will be something like "http://updates.jenkins-ci.org/updates/foo.json" For security and privacy reasons, we don't allow the retrieval from random locations.
        interval - The interval, in milliseconds, between attempts to update this downloadable's data.
      • Downloadable

        public Downloadable()
        Creates a new downloadable. This will generate an ID based on this downloadable's class (using idFor(Class). The URL will be set to that ID, with an added .json extension, and the default interval will be used.
      • Downloadable

        public Downloadable​(@NonNull
                            Class<?> clazz)
        Creates a new downloadable. This will generate an ID based on the specified class (using idFor(Class). The URL will be set to that ID, with an added .json extension, and the default interval will be used.
        Parameters:
        clazz - The class to use to generate the ID.
      • Downloadable

        public Downloadable​(@NonNull
                            String id)
        Creates a new downloadable with a specific ID. The URL will be set to that ID, with an added .json extension, and the default interval will be used.
        Parameters:
        id - The ID to use.
      • Downloadable

        public Downloadable​(@NonNull
                            String id,
                            @NonNull
                            String url)
        Creates a new downloadable with a specific ID and URL. The default interval will be used.
        Parameters:
        id - The ID to use.
        url - URL relative to UpdateCenter.getDefaultBaseUrl(). So if this string is "foo.json", the ultimate URL will be something like "http://updates.jenkins-ci.org/updates/foo.json".

        For security and privacy reasons, we don't allow the retrieval from random locations.

    • Method Detail

      • getId

        @NonNull
        public String getId()
      • idFor

        @NonNull
        public static String idFor​(@NonNull
                                   Class<?> clazz)
        Generates an ID based on a class.
        Parameters:
        clazz - The class to use to generate an ID.
        Returns:
        The ID generated based on the specified class.
        Since:
        2.244
      • getUrl

        public String getUrl()
        URL to download.
      • getUrls

        public List<String> getUrls()
        URLs to download from.
      • getInterval

        public long getInterval()
        How often do we retrieve the new image?
        Returns:
        number of milliseconds between retrieval.
      • getDataFile

        public TextFile getDataFile()
        This is where the retrieved file will be stored.
      • getDue

        public long getDue()
        When shall we retrieve this file next time?
      • getData

        public net.sf.json.JSONObject getData()
                                       throws IOException
        Loads the current file into JSON and returns it, or null if no data exists.
        Throws:
        IOException
      • reduce

        public net.sf.json.JSONObject reduce​(List<net.sf.json.JSONObject> jsonList)
        Function that takes multiple JSONObjects and returns a single one.
        Parameters:
        jsonList - to be processed
        Returns:
        a single JSONObject
      • hasDuplicates

        public static <T> boolean hasDuplicates​(List<T> genericList,
                                                String comparator)
        check if the list of update center entries has duplicates
        Type Parameters:
        T - the generic class
        Parameters:
        genericList - list of entries coming from multiple update centers
        comparator - the unique ID of an entry
        Returns:
        true if the list has duplicates, false otherwise