Class ConsoleUpdateManager

  • All Implemented Interfaces:
    ClientApp, RouterApp, UpdateManager

    public class ConsoleUpdateManager
    extends Object
    implements UpdateManager, RouterApp
    The central resource coordinating updates. This must be registered with the context. The UpdateManager starts and stops all updates, prevents multiple updates as appropriate, and controls notification to the user. Version notes: For news and unsigned updates, use Long.toString(modtime).
    Since:
    0.9.4
    • Method Detail

      • start

        public void start()
        UpdateManager interface
        Specified by:
        start in interface UpdateManager
      • startup

        public void startup()
        ClientApp interface
        Specified by:
        startup in interface ClientApp
        Since:
        0.9.12
      • shutdown

        public void shutdown()
        UpdateManager interface
        Specified by:
        shutdown in interface UpdateManager
      • shutdown

        public void shutdown​(String[] args)
        ClientApp interface
        Specified by:
        shutdown in interface ClientApp
        Parameters:
        args - ignored
        Since:
        0.9.12
      • getState

        public ClientAppState getState()
        Description copied from interface: ClientApp
        The current state of the ClientApp.
        Specified by:
        getState in interface ClientApp
        Returns:
        non-null
        Since:
        0.9.12
      • getName

        public String getName()
        Description copied from interface: ClientApp
        The generic name of the ClientApp, used for registration, e.g. "console". Do not translate.
        Specified by:
        getName in interface ClientApp
        Returns:
        non-null
        Since:
        0.9.12
      • getDisplayName

        public String getDisplayName()
        Description copied from interface: ClientApp
        The display name of the ClientApp, used in user interfaces. The app must translate.
        Specified by:
        getDisplayName in interface ClientApp
        Returns:
        non-null
        Since:
        0.9.12
      • getStatus

        public String getStatus()
        The status on any update current or last finished.
        Specified by:
        getStatus in interface UpdateManager
        Returns:
        status or ""
      • checkAvailable

        public String checkAvailable​(UpdateType type)
        Is an update available? Blocking. An available update may still have a constraint or lack sources.
        Specified by:
        checkAvailable in interface UpdateManager
        Parameters:
        type - the UpdateType of this request
        Returns:
        new version or null if nothing newer is available
        Since:
        0.9.21
      • checkAvailable

        public String checkAvailable​(UpdateType type,
                                     long maxWait)
        Is an update available? Blocking. An available update may still have a constraint or lack sources.
        Specified by:
        checkAvailable in interface UpdateManager
        Parameters:
        type - the UpdateType of this request
        maxWait - max time to block
        Returns:
        new version or null if nothing newer is available
      • checkAvailable

        public String checkAvailable​(UpdateType type,
                                     String id,
                                     long maxWait)
        Is an update available? Blocking. An available update may still have a constraint or lack sources.
        Specified by:
        checkAvailable in interface UpdateManager
        Parameters:
        type - the UpdateType of this request
        id - id of this request
        maxWait - max time to block
        Returns:
        new version or null if nothing newer is available
      • check

        public void check​(UpdateType type)
        Fire off a checker task Non-blocking.
      • check

        public void check​(UpdateType type,
                          String id)
        Fire off a checker task Non-blocking.
      • getUpdateAvailable

        public String getUpdateAvailable​(UpdateType type)
        Is an update available? Non-blocking, returns result of last check or notification from an Updater. An available update may still have a constraint or lack sources.
        Returns:
        new version or null if nothing newer is available
      • getUpdateAvailable

        public String getUpdateAvailable​(UpdateType type,
                                         String id)
        Is an update available? Non-blocking, returns result of last check or notification from an Updater. An available update may still have a constraint or lack sources.
        Returns:
        new version or null if nothing newer is available
      • getUpdateDownloaded

        public String getUpdateDownloaded​(UpdateType type)
        Is an update downloaded? Non-blocking, returns result of last download
        Returns:
        new version or null if nothing was downloaded
      • getUpdateDownloaded

        public String getUpdateDownloaded​(UpdateType type,
                                          String id)
        Is an update downloaded? Non-blocking, returns result of last download
        Returns:
        new version or null if nothing was downloaded
      • isUpdateInProgress

        public boolean isUpdateInProgress()
        Is any download in progress? Does not include checks.
        Specified by:
        isUpdateInProgress in interface UpdateManager
        Returns:
        true iff router update is being downloaded
      • isUpdateInProgress

        public boolean isUpdateInProgress​(UpdateType type)
        Is a download in progress?
        Specified by:
        isUpdateInProgress in interface UpdateManager
        Parameters:
        type - the UpdateType of this request
        Returns:
        true iff router update is being downloaded
      • isUpdateInProgress

        public boolean isUpdateInProgress​(UpdateType type,
                                          String id)
        Is a download in progress?
        Specified by:
        isUpdateInProgress in interface UpdateManager
        Parameters:
        type - the UpdateType of this request
        id - of this request
        Returns:
        true iff router update is being downloaded
      • stopUpdates

        public void stopUpdates()
        Stop all downloads in progress
      • stopUpdate

        public void stopUpdate​(UpdateType type)
        Stop this download
      • stopUpdate

        public void stopUpdate​(UpdateType type,
                               String id)
        Stop this download
      • isCheckInProgress

        public boolean isCheckInProgress()
        Is any check in progress? Does not include updates.
      • isCheckInProgress

        public boolean isCheckInProgress​(UpdateType type)
        Is a check in progress?
      • isCheckInProgress

        public boolean isCheckInProgress​(UpdateType type,
                                         String id)
        Is a check in progress?
      • stopChecks

        public void stopChecks()
        Stop all checks in progress
      • stopCheck

        public void stopCheck​(UpdateType type)
        Stop this check
      • stopCheck

        public void stopCheck​(UpdateType type,
                              String id)
        Stop this check
      • isExternalRestartPending

        public boolean isExternalRestartPending()
        A router update had been downloaded and handled by an UpdatePostProcessor. It will provide wrapper-like function to install the update and restart after shutdown.
        Since:
        0.9.51
      • installPlugin

        public boolean installPlugin​(String name,
                                     URI uri)
        Install a plugin. Non-blocking. If returns true, then call isUpdateInProgress() in a loop
        Parameters:
        name - if null, a new install
        Returns:
        true if task started
      • update

        public boolean update​(UpdateType type)
        Non-blocking. Does not check. If returns true, then call isUpdateInProgress() in a loop Max time 3 hours by default but not honored by all Updaters
        Specified by:
        update in interface UpdateManager
        Parameters:
        type - the UpdateType of this request
        Returns:
        true if task started
      • update

        public boolean update​(UpdateType type,
                              String id)
        Non-blocking. Does not check. Max time 3 hours by default but not honored by all Updaters If returns true, then call isUpdateInProgress() in a loop
        Specified by:
        update in interface UpdateManager
        Parameters:
        type - the UpdateType of this request
        id - id of this request
        Returns:
        true if task started
      • update

        public boolean update​(UpdateType type,
                              long maxTime)
        Non-blocking. Does not check. If returns true, then call isUpdateInProgress() in a loop
        Specified by:
        update in interface UpdateManager
        Parameters:
        maxTime - not honored by all Updaters
        type - the UpdateType of this request
        Returns:
        true if task started
      • update

        public boolean update​(UpdateType type,
                              String id,
                              long maxTime)
        Non-blocking. Does not check. Fails if check or update already in progress. If returns true, then call isUpdateInProgress() in a loop
        Specified by:
        update in interface UpdateManager
        Parameters:
        maxTime - not honored by all Updaters
        type - the UpdateType of this request
        id - id of this request
        Returns:
        true if task started
      • register

        public void register​(UpdatePostProcessor upp,
                             UpdateType type,
                             int fileType)
        Register a post-processor for this UpdateType and SU3File file type.
        Specified by:
        register in interface UpdateManager
        Parameters:
        type - only ROUTER_SIGNED_SU3 and ROUTER_DEV_SU3 are currently supported
        fileType - a SU3File TYPE_xxx constant, 1-255, TYPE_ZIP not supported.
        Since:
        0.9.51
      • notifyVersionAvailable

        public boolean notifyVersionAvailable​(UpdateTask task,
                                              URI newsSource,
                                              UpdateType type,
                                              String id,
                                              UpdateMethod method,
                                              List<URI> updateSources,
                                              String newVersion,
                                              String minVersion)
        Called by the Updater, either after check() was called, or it found out on its own. Use this if there is only one UpdateMethod; otherwise use the Map method below.
        Specified by:
        notifyVersionAvailable in interface UpdateManager
        Parameters:
        newsSource - who told us
        id - plugin name for plugins, ignored otherwise
        updateSources - Where to get the new version
        newVersion - The new version available
        minVersion - The minimum installed version to be able to update to newVersion
        method - How to get the new version
        Returns:
        true if it's newer
      • notifyVersionAvailable

        public boolean notifyVersionAvailable​(UpdateTask task,
                                              URI newsSource,
                                              UpdateType type,
                                              String id,
                                              Map<UpdateMethod,​List<URI>> sourceMap,
                                              String newVersion,
                                              String minVersion)
        Called by the Checker, either after check() was called, or it found out on its own. Checkers must use this method if there are multiple UpdateMethods discoverd simultaneously.
        Specified by:
        notifyVersionAvailable in interface UpdateManager
        Parameters:
        newsSource - who told us
        id - plugin name for plugins, ignored otherwise
        sourceMap - Mapping of methods to sources
        newVersion - The new version available
        minVersion - The minimum installed version to be able to update to newVersion
        Returns:
        true if we didn't know already
        Since:
        0.9.6
      • notifyVersionConstraint

        public void notifyVersionConstraint​(UpdateTask task,
                                            URI newsSource,
                                            UpdateType type,
                                            String id,
                                            String newVersion,
                                            String message)
        A new version is available but cannot be downloaded or installed due to some constraint. The manager should notify the user. Called by the Checker, either after check() was called, or it found out on its own.
        Specified by:
        notifyVersionConstraint in interface UpdateManager
        Parameters:
        newsSource - who told us
        id - plugin name for plugins, ignored otherwise
        newVersion - The new version available
        message - A translated message to be displayed to the user, non-null
        Since:
        0.9.9
      • notifyCheckComplete

        public void notifyCheckComplete​(UpdateTask task,
                                        boolean newer,
                                        boolean success)
        Called by the Updater after check() was called and all notifyVersionAvailable() callbacks are finished
        Specified by:
        notifyCheckComplete in interface UpdateManager
        newer - notifyVersionAvailable was called
        success - check succeeded (newer or not)
      • notifyComplete

        public void notifyComplete​(UpdateTask task,
                                   String status)
        An expiring status
        Parameters:
        task - may be null
      • notifyComplete

        public boolean notifyComplete​(UpdateTask task,
                                      String actualVersion,
                                      File file)
        An update has been downloaded but not verified. The manager will verify it. Caller should delete the file upon return, unless it will share it with others, e.g. on a torrent. If the return value is false, caller must call notifyTaskFailed() or notifyComplete() again.
        Specified by:
        notifyComplete in interface UpdateManager
        Parameters:
        task - must be an Updater, not a Checker
        actualVersion - may be higher (or lower?) than the version requested
        file - a valid format for the task's UpdateType, or null if it did the installation itself
        Returns:
        true if valid, false if corrupt
      • notifyInstalled

        public void notifyInstalled​(UpdateType type,
                                    String id,
                                    String version)
        Adds to installed, removes from downloaded and available
        Specified by:
        notifyInstalled in interface UpdateManager
        Parameters:
        id - subtype for plugins, or ""
        version - null to remove from installed
        Since:
        public since 0.9.45
      • shouldInstall

        boolean shouldInstall()
        from NewsFetcher
      • getUpdateConstraint

        public String getUpdateConstraint​(UpdateType type,
                                          String id)
        Is there a reason we can't download the update?
        Returns:
        translated contraint or null
        Since:
        0.9.9