net.i2p.router.update

## Class ConsoleUpdateManager

- java.lang.Object
- - net.i2p.router.update.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).

- - ### Field Summary

    - ### Fields inherited from interface net.i2p.update.UpdateManager

      `APP_NAME`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ConsoleUpdateManager(RouterContext ctx, ClientAppManager listener, String[] args)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `String` | `_t(String s)` translate a string
    `String` | `_t(String s, Object o)` translate a string with a parameter
    `String` | `_t(String s, Object o, Object o2)` translate a string with parameters
    `void` | `check(UpdateType type)` Fire off a checker task Non-blocking.
    `void` | `check(UpdateType type, String id)` Fire off a checker task Non-blocking.
    `String` | `checkAvailable(UpdateType type)` Is an update available? Blocking.
    `String` | `checkAvailable(UpdateType type, long maxWait)` Is an update available? Blocking.
    `String` | `checkAvailable(UpdateType type, String id, long maxWait)` Is an update available? Blocking.
    `String` | `getDisplayName()` The display name of the ClientApp, used in user interfaces.
    `static ConsoleUpdateManager` | `getInstance()`
    `String` | `getName()` The generic name of the ClientApp, used for registration, e.g.
    `ClientAppState` | `getState()` The current state of the ClientApp.
    `String` | `getStatus()` The status on any update current or last finished.
    `String` | `getUpdateAvailable(UpdateType type)` Is an update available? Non-blocking, returns result of last check or notification from an Updater.
    `String` | `getUpdateAvailable(UpdateType type, String id)` Is an update available? Non-blocking, returns result of last check or notification from an Updater.
    `String` | `getUpdateConstraint(UpdateType type, String id)` Is there a reason we can't download the update?
    `String` | `getUpdateDownloaded(UpdateType type)` Is an update downloaded? Non-blocking, returns result of last download
    `String` | `getUpdateDownloaded(UpdateType type, String id)` Is an update downloaded? Non-blocking, returns result of last download
    `List<URI>` | `getUpdateURLs(UpdateType type, String id, UpdateMethod method)` Where to find various resources
    `boolean` | `installPlugin(String name, URI uri)` Install a plugin.
    `boolean` | `isCheckInProgress()` Is any check in progress? Does not include updates.
    `boolean` | `isCheckInProgress(UpdateType type)` Is a check in progress?
    `boolean` | `isCheckInProgress(UpdateType type, String id)` Is a check in progress?
    `boolean` | `isExternalRestartPending()` A router update had been downloaded and handled by an UpdatePostProcessor.
    `boolean` | `isUpdateInProgress()` Is any download in progress? Does not include checks.
    `boolean` | `isUpdateInProgress(UpdateType type)` Is a download in progress?
    `boolean` | `isUpdateInProgress(UpdateType type, String id)` Is a download in progress?
    `(package private) static String` | `linkify(String url)`
    `void` | `notifyAttemptFailed(UpdateTask task, String reason, Throwable t)` Not necessarily the end if there are more URIs to try.
    `void` | `notifyCheckComplete(UpdateTask task, boolean newer, boolean success)` Called by the Updater after check() was called and all notifyVersionAvailable() callbacks are finished
    `void` | `notifyComplete(UpdateTask task, String status)` An expiring status
    `boolean` | `notifyComplete(UpdateTask task, String actualVersion, File file)` An update has been downloaded but not verified.
    `void` | `notifyInstalled(UpdateType type, String id, String version)` Adds to installed, removes from downloaded and available
    `void` | `notifyProgress(UpdateTask task, String status)` Notify of progress update.
    `void` | `notifyProgress(UpdateTask task, String status, long downloaded, long totalSize)` Notify of progress update with size information.
    `void` | `notifyTaskFailed(UpdateTask task, String reason, Throwable t)` The task has finished and failed.
    `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.
    `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.
    `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.
    `void` | `register(Checker updater, UpdateType type, UpdateMethod method, int priority)` Register a checker for updates.
    `void` | `register(UpdatePostProcessor upp, UpdateType type, int fileType)` Register a post-processor for this UpdateType and SU3File file type.
    `void` | `register(Updater updater, UpdateType type, UpdateMethod method, int priority)` Call once for each type/method pair.
    `void` | `renderStatusHTML(Writer out)` debug
    `(package private) boolean` | `shouldInstall()` from NewsFetcher
    `void` | `shutdown()` UpdateManager interface
    `void` | `shutdown(String[] args)` ClientApp interface
    `void` | `start()` UpdateManager interface
    `void` | `startup()` ClientApp interface
    `void` | `stopCheck(UpdateType type)` Stop this check
    `void` | `stopCheck(UpdateType type, String id)` Stop this check
    `void` | `stopChecks()` Stop all checks in progress
    `void` | `stopUpdate(UpdateType type)` Stop this download
    `void` | `stopUpdate(UpdateType type, String id)` Stop this download
    `void` | `stopUpdates()` Stop all downloads in progress
    `void` | `unregister(Checker updater, UpdateType type, UpdateMethod method)` Unregister a checker.
    `void` | `unregister(Updater updater, UpdateType type, UpdateMethod method)` Unregister an updater.
    `boolean` | `update(UpdateType type)` Non-blocking.
    `boolean` | `update(UpdateType type, long maxTime)` Non-blocking.
    `boolean` | `update(UpdateType type, String id)` Non-blocking.
    `boolean` | `update(UpdateType type, String id, long maxTime)` Non-blocking.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ConsoleUpdateManager

          public ConsoleUpdateManager(RouterContext ctx,
                                      ClientAppManager listener,
                                      String[] args)

      Parameters:
        `args` - ignored

  - ### Method Detail

    - #### _t

          public String _t(String s)

      translate a string

    - #### _t

          public String _t(String s,
                           Object o)

      translate a string with a parameter

    - #### _t

          public String _t(String s,
                           Object o,
                           Object o2)

      translate a string with parameters

    - #### 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.

    - #### 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

    - #### 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

    - #### 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

    - #### getInstance

          public static ConsoleUpdateManager getInstance()

      Returns:
        null if not found

    - #### 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

    - #### getState

          public ClientAppState getState()

      Description copied from interface: `ClientApp`
      The current state of the ClientApp.
      Specified by:
        `getState` in interface `ClientApp`
      Returns:
        non-null

    - #### getStatus

          public String getStatus()

      The status on any update current or last finished.
      Specified by:
        `getStatus` in interface `UpdateManager`
      Returns:
        status or ""

    - #### 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

    - #### getUpdateConstraint

          public String getUpdateConstraint(UpdateType type,
                                            String id)

      Is there a reason we can't download the update?
      Returns:
        translated contraint or null

    - #### 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

    - #### getUpdateURLs

          public List<URI> getUpdateURLs(UpdateType type,
                                         String id,
                                         UpdateMethod method)

      Where to find various resources
      Returns:
        non-null may be empty

    - #### 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

    - #### 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?

    - #### 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.

    - #### 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

    - #### linkify

          static String linkify(String url)

    - #### notifyAttemptFailed

          public void notifyAttemptFailed(UpdateTask task,
                                          String reason,
                                          Throwable t)

      Not necessarily the end if there are more URIs to try.
      Specified by:
        `notifyAttemptFailed` in interface `UpdateManager`
      Parameters:
        `task` - checker or updater
        `t` - may be null
        `reason` - failure reason

    - #### 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`
      Parameters:
        `task` - update task
        `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
        `type` - update type

    - #### notifyProgress

          public void notifyProgress(UpdateTask task,
                                     String status)

      Description copied from interface: `UpdateManager`
      Notify of progress update.
      Specified by:
        `notifyProgress` in interface `UpdateManager`
      Parameters:
        `task` - may be null
        `status` - status message

    - #### notifyProgress

          public void notifyProgress(UpdateTask task,
                                     String status,
                                     long downloaded,
                                     long totalSize)

      Description copied from interface: `UpdateManager`
      Notify of progress update with size information.
      Specified by:
        `notifyProgress` in interface `UpdateManager`
      Parameters:
        `task` - update task
        `status` - status message
        `downloaded` - bytes downloaded
        `totalSize` - total size

    - #### notifyTaskFailed

          public void notifyTaskFailed(UpdateTask task,
                                       String reason,
                                       Throwable t)

      The task has finished and failed.
      Specified by:
        `notifyTaskFailed` in interface `UpdateManager`
      Parameters:
        `task` - checker or updater
        `t` - may be null
        `reason` - failure reason

    - #### 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
        `task` - update task
        `type` - update type
      Returns:
        true if we didn't know already

    - #### 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
        `task` - update task
        `type` - update type
        `method` - How to get the new version
      Returns:
        true if it's newer

    - #### 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
        `task` - update task
        `type` - update type

    - #### register

          public void register(Checker updater,
                               UpdateType type,
                               UpdateMethod method,
                               int priority)

      Description copied from interface: `UpdateManager`
      Register a checker for updates.
      Specified by:
        `register` in interface `UpdateManager`
      Parameters:
        `updater` - the checker implementation
        `type` - the update type
        `method` - the update method
        `priority` - the priority

    - #### 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.
        `upp` - update post processor

    - #### register

          public void register(Updater updater,
                               UpdateType type,
                               UpdateMethod method,
                               int priority)

      Call once for each type/method pair.
      Specified by:
        `register` in interface `UpdateManager`
      Parameters:
        `updater` - the updater implementation
        `type` - the update type
        `method` - the update method
        `priority` - the priority

    - #### renderStatusHTML

          public void renderStatusHTML(Writer out)
                                throws IOException

      debug
      Specified by:
        `renderStatusHTML` in interface `UpdateManager`
      Parameters:
        `out` - writer to output to
      Throws:
        `IOException` - if writing fails

    - #### shouldInstall

          boolean shouldInstall()

      from NewsFetcher

    - #### 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

    - #### start

          public void start()

      UpdateManager interface
      Specified by:
        `start` in interface `UpdateManager`

    - #### startup

          public void startup()

      ClientApp interface
      Specified by:
        `startup` in interface `ClientApp`

    - #### stopCheck

          public void stopCheck(UpdateType type)

      Stop this check

    - #### stopCheck

          public void stopCheck(UpdateType type,
                                String id)

      Stop this check

    - #### stopChecks

          public void stopChecks()

      Stop all checks in progress

    - #### stopUpdate

          public void stopUpdate(UpdateType type)

      Stop this download

    - #### stopUpdate

          public void stopUpdate(UpdateType type,
                                 String id)

      Stop this download

    - #### stopUpdates

          public void stopUpdates()

      Stop all downloads in progress

    - #### unregister

          public void unregister(Checker updater,
                                 UpdateType type,
                                 UpdateMethod method)

      Description copied from interface: `UpdateManager`
      Unregister a checker.
      Specified by:
        `unregister` in interface `UpdateManager`
      Parameters:
        `updater` - the checker implementation
        `type` - the update type
        `method` - the update method

    - #### unregister

          public void unregister(Updater updater,
                                 UpdateType type,
                                 UpdateMethod method)

      Description copied from interface: `UpdateManager`
      Unregister an updater.
      Specified by:
        `unregister` in interface `UpdateManager`
      Parameters:
        `updater` - the updater implementation
        `type` - the update type
        `method` - the update method

    - #### 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,
                                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)

      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,
                                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