Package 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).- Since:
- 0.9.4
-
-
Field Summary
-
Fields inherited from interface net.i2p.update.UpdateManager
APP_NAME
-
-
Constructor Summary
Constructors Constructor Description ConsoleUpdateManager(RouterContext ctx, ClientAppManager listener, String[] args)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String_t(String s)translate a stringString_t(String s, Object o)translate a string with a parameterString_t(String s, Object o, Object o2)translate a string with parametersvoidcheck(UpdateType type)Fire off a checker task Non-blocking.voidcheck(UpdateType type, String id)Fire off a checker task Non-blocking.StringcheckAvailable(UpdateType type)Is an update available? Blocking.StringcheckAvailable(UpdateType type, long maxWait)Is an update available? Blocking.StringcheckAvailable(UpdateType type, String id, long maxWait)Is an update available? Blocking.StringgetDisplayName()The display name of the ClientApp, used in user interfaces.static ConsoleUpdateManagergetInstance()StringgetName()The generic name of the ClientApp, used for registration, e.g.ClientAppStategetState()The current state of the ClientApp.StringgetStatus()The status on any update current or last finished.StringgetUpdateAvailable(UpdateType type)Is an update available? Non-blocking, returns result of last check or notification from an Updater.StringgetUpdateAvailable(UpdateType type, String id)Is an update available? Non-blocking, returns result of last check or notification from an Updater.StringgetUpdateConstraint(UpdateType type, String id)Is there a reason we can't download the update?StringgetUpdateDownloaded(UpdateType type)Is an update downloaded? Non-blocking, returns result of last downloadStringgetUpdateDownloaded(UpdateType type, String id)Is an update downloaded? Non-blocking, returns result of last downloadList<URI>getUpdateURLs(UpdateType type, String id, UpdateMethod method)Where to find various resourcesbooleaninstallPlugin(String name, URI uri)Install a plugin.booleanisCheckInProgress()Is any check in progress? Does not include updates.booleanisCheckInProgress(UpdateType type)Is a check in progress?booleanisCheckInProgress(UpdateType type, String id)Is a check in progress?booleanisExternalRestartPending()A router update had been downloaded and handled by an UpdatePostProcessor.booleanisUpdateInProgress()Is any download in progress? Does not include checks.booleanisUpdateInProgress(UpdateType type)Is a download in progress?booleanisUpdateInProgress(UpdateType type, String id)Is a download in progress?(package private) static Stringlinkify(String url)voidnotifyAttemptFailed(UpdateTask task, String reason, Throwable t)Not necessarily the end if there are more URIs to try.voidnotifyCheckComplete(UpdateTask task, boolean newer, boolean success)Called by the Updater after check() was called and all notifyVersionAvailable() callbacks are finishedvoidnotifyComplete(UpdateTask task, String status)An expiring statusbooleannotifyComplete(UpdateTask task, String actualVersion, File file)An update has been downloaded but not verified.voidnotifyInstalled(UpdateType type, String id, String version)Adds to installed, removes from downloaded and availablevoidnotifyProgress(UpdateTask task, String status)voidnotifyProgress(UpdateTask task, String status, long downloaded, long totalSize)voidnotifyTaskFailed(UpdateTask task, String reason, Throwable t)The task has finished and failed.booleannotifyVersionAvailable(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.booleannotifyVersionAvailable(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.voidnotifyVersionConstraint(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.voidregister(Checker updater, UpdateType type, UpdateMethod method, int priority)voidregister(UpdatePostProcessor upp, UpdateType type, int fileType)Register a post-processor for this UpdateType and SU3File file type.voidregister(Updater updater, UpdateType type, UpdateMethod method, int priority)Call once for each type/method pair.voidrenderStatusHTML(Writer out)debug(package private) booleanshouldInstall()from NewsFetchervoidshutdown()UpdateManager interfacevoidshutdown(String[] args)ClientApp interfacevoidstart()UpdateManager interfacevoidstartup()ClientApp interfacevoidstopCheck(UpdateType type)Stop this checkvoidstopCheck(UpdateType type, String id)Stop this checkvoidstopChecks()Stop all checks in progressvoidstopUpdate(UpdateType type)Stop this downloadvoidstopUpdate(UpdateType type, String id)Stop this downloadvoidstopUpdates()Stop all downloads in progressvoidunregister(Checker updater, UpdateType type, UpdateMethod method)voidunregister(Updater updater, UpdateType type, UpdateMethod method)booleanupdate(UpdateType type)Non-blocking.booleanupdate(UpdateType type, long maxTime)Non-blocking.booleanupdate(UpdateType type, String id)Non-blocking.booleanupdate(UpdateType type, String id, long maxTime)Non-blocking.
-
-
-
Constructor Detail
-
ConsoleUpdateManager
public ConsoleUpdateManager(RouterContext ctx, ClientAppManager listener, String[] args)
- Parameters:
args- ignored
-
-
Method Detail
-
getInstance
public static ConsoleUpdateManager getInstance()
- Returns:
- null if not found
-
start
public void start()
UpdateManager interface- Specified by:
startin interfaceUpdateManager
-
startup
public void startup()
ClientApp interface
-
shutdown
public void shutdown()
UpdateManager interface- Specified by:
shutdownin interfaceUpdateManager
-
shutdown
public void shutdown(String[] args)
ClientApp interface
-
getState
public ClientAppState getState()
Description copied from interface:ClientAppThe current state of the ClientApp.
-
getName
public String getName()
Description copied from interface:ClientAppThe generic name of the ClientApp, used for registration, e.g. "console". Do not translate.
-
getDisplayName
public String getDisplayName()
Description copied from interface:ClientAppThe display name of the ClientApp, used in user interfaces. The app must translate.- Specified by:
getDisplayNamein interfaceClientApp- Returns:
- non-null
- Since:
- 0.9.12
-
getStatus
public String getStatus()
The status on any update current or last finished.- Specified by:
getStatusin interfaceUpdateManager- 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:
checkAvailablein interfaceUpdateManager- 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:
checkAvailablein interfaceUpdateManager- Parameters:
type- the UpdateType of this requestmaxWait- 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:
checkAvailablein interfaceUpdateManager- Parameters:
type- the UpdateType of this requestid- id of this requestmaxWait- 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:
isUpdateInProgressin interfaceUpdateManager- Returns:
- true iff router update is being downloaded
-
isUpdateInProgress
public boolean isUpdateInProgress(UpdateType type)
Is a download in progress?- Specified by:
isUpdateInProgressin interfaceUpdateManager- 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:
isUpdateInProgressin interfaceUpdateManager- Parameters:
type- the UpdateType of this requestid- 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:
updatein interfaceUpdateManager- 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:
updatein interfaceUpdateManager- Parameters:
type- the UpdateType of this requestid- 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:
updatein interfaceUpdateManager- Parameters:
maxTime- not honored by all Updaterstype- 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:
updatein interfaceUpdateManager- Parameters:
maxTime- not honored by all Updaterstype- the UpdateType of this requestid- id of this request- 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:
registerin interfaceUpdateManager
-
unregister
public void unregister(Updater updater, UpdateType type, UpdateMethod method)
- Specified by:
unregisterin interfaceUpdateManager
-
register
public void register(Checker updater, UpdateType type, UpdateMethod method, int priority)
- Specified by:
registerin interfaceUpdateManager
-
unregister
public void unregister(Checker updater, UpdateType type, UpdateMethod method)
- Specified by:
unregisterin interfaceUpdateManager
-
register
public void register(UpdatePostProcessor upp, UpdateType type, int fileType)
Register a post-processor for this UpdateType and SU3File file type.- Specified by:
registerin interfaceUpdateManager- Parameters:
type- only ROUTER_SIGNED_SU3 and ROUTER_DEV_SU3 are currently supportedfileType- 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:
notifyVersionAvailablein interfaceUpdateManager- Parameters:
newsSource- who told usid- plugin name for plugins, ignored otherwiseupdateSources- Where to get the new versionnewVersion- The new version availableminVersion- The minimum installed version to be able to update to newVersionmethod- 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:
notifyVersionAvailablein interfaceUpdateManager- Parameters:
newsSource- who told usid- plugin name for plugins, ignored otherwisesourceMap- Mapping of methods to sourcesnewVersion- The new version availableminVersion- 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:
notifyVersionConstraintin interfaceUpdateManager- Parameters:
newsSource- who told usid- plugin name for plugins, ignored otherwisenewVersion- The new version availablemessage- 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:
notifyCheckCompletein interfaceUpdateManagernewer- notifyVersionAvailable was calledsuccess- check succeeded (newer or not)
-
notifyProgress
public void notifyProgress(UpdateTask task, String status, long downloaded, long totalSize)
- Specified by:
notifyProgressin interfaceUpdateManager
-
notifyProgress
public void notifyProgress(UpdateTask task, String status)
- Specified by:
notifyProgressin interfaceUpdateManager- 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:
notifyAttemptFailedin interfaceUpdateManager- Parameters:
task- checker or updatert- may be null
-
notifyTaskFailed
public void notifyTaskFailed(UpdateTask task, String reason, Throwable t)
The task has finished and failed.- Specified by:
notifyTaskFailedin interfaceUpdateManager- Parameters:
task- checker or updatert- 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:
notifyCompletein interfaceUpdateManager- Parameters:
task- must be an Updater, not a CheckeractualVersion- may be higher (or lower?) than the version requestedfile- 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:
notifyInstalledin interfaceUpdateManager- Parameters:
id- subtype for plugins, or ""version- null to remove from installed- Since:
- public since 0.9.45
-
shouldInstall
boolean shouldInstall()
from NewsFetcher
-
getUpdateURLs
public List<URI> getUpdateURLs(UpdateType type, String id, UpdateMethod method)
Where to find various resources- Returns:
- non-null may be empty
-
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
-
renderStatusHTML
public void renderStatusHTML(Writer out) throws IOException
debug- Specified by:
renderStatusHTMLin interfaceUpdateManager- Throws:
IOException
-
-