net.i2p.router.update
Class ConsoleUpdateManager

java.lang.Object
  extended by net.i2p.router.update.ConsoleUpdateManager
All Implemented Interfaces:
UpdateManager

public class ConsoleUpdateManager
extends Object
implements UpdateManager

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

Constructor Summary
ConsoleUpdateManager(RouterContext ctx)
           
 
Method Summary
 String _(String s)
          translate a string
 String _(String s, Object o)
          translate a string with a parameter
 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, long maxWait)
           
 String checkAvailable(UpdateType type, String id, long maxWait)
          Is an update available? Blocking.
static ConsoleUpdateManager getInstance()
           
 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 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 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 notifyProgress(UpdateTask task, String status)
           
 void notifyProgress(UpdateTask task, String status, long downloaded, long totalSize)
           
 void notifyTaskFailed(UpdateTask task, String reason, Throwable t)
          The task has finished and failed.
 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 register(Checker updater, UpdateType type, UpdateMethod method, int priority)
           
 void register(Updater updater, UpdateType type, UpdateMethod method, int priority)
          Call once for each type/method pair.
 void renderStatusHTML(Writer out)
          debug
 void shutdown()
           
 void start()
           
 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)
           
 void unregister(Updater updater, UpdateType type, UpdateMethod method)
           
 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)
Method Detail

getInstance

public static ConsoleUpdateManager getInstance()

start

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

shutdown

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

getStatus

public String getStatus()
The status on any update current or last finished.

Returns:
status or ""

checkAvailable

public String checkAvailable(UpdateType type,
                             long maxWait)

checkAvailable

public String checkAvailable(UpdateType type,
                             String id,
                             long maxWait)
Is an update available? Blocking.

Parameters:
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

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

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.


isUpdateInProgress

public boolean isUpdateInProgress(UpdateType type)
Is a download in progress?


isUpdateInProgress

public boolean isUpdateInProgress(UpdateType type,
                                  String id)
Is a download in progress?


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


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

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

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

Parameters:
maxTime - not honored by all Updaters
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

Parameters:
maxTime - not honored by all Updaters
Returns:
true if task started

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

unregister

public void unregister(Updater updater,
                       UpdateType type,
                       UpdateMethod method)
Specified by:
unregister in interface UpdateManager

register

public void register(Checker updater,
                     UpdateType type,
                     UpdateMethod method,
                     int priority)
Specified by:
register in interface UpdateManager

unregister

public void unregister(Checker updater,
                       UpdateType type,
                       UpdateMethod method)
Specified by:
unregister in interface UpdateManager

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.

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

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)

notifyProgress

public void notifyProgress(UpdateTask task,
                           String status,
                           long downloaded,
                           long totalSize)
Specified by:
notifyProgress in interface UpdateManager

notifyProgress

public void notifyProgress(UpdateTask task,
                           String status)
Specified by:
notifyProgress in interface UpdateManager
Parameters:
task - may be null

notifyComplete

public void notifyComplete(UpdateTask task,
                           String status)
An expiring status

Parameters:
task - may be null

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

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

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

getUpdateURLs

public List<URI> getUpdateURLs(UpdateType type,
                               String id,
                               UpdateMethod method)
Where to find various resources

Returns:
non-null may be empty

linkify

static String linkify(String url)

_

public String _(String s)
translate a string


_

public String _(String s,
                Object o)
translate a string with a parameter


renderStatusHTML

public void renderStatusHTML(Writer out)
                      throws IOException
debug

Specified by:
renderStatusHTML in interface UpdateManager
Throws:
IOException