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 parametersvoid
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 downloadString
getUpdateDownloaded(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 resourcesboolean
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 finishedvoid
notifyComplete(UpdateTask task, String status)
An expiring statusboolean
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 availablevoid
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, 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)
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 NewsFetchervoid
shutdown()
UpdateManager interfacevoid
shutdown(String[] args)
ClientApp interfacevoid
start()
UpdateManager interfacevoid
startup()
ClientApp interfacevoid
stopCheck(UpdateType type)
Stop this checkvoid
stopCheck(UpdateType type, String id)
Stop this checkvoid
stopChecks()
Stop all checks in progressvoid
stopUpdate(UpdateType type)
Stop this downloadvoid
stopUpdate(UpdateType type, String id)
Stop this downloadvoid
stopUpdates()
Stop all downloads in progressvoid
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.
-
-
-
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:
start
in interfaceUpdateManager
-
startup
public void startup()
ClientApp interface
-
shutdown
public void shutdown()
UpdateManager interface- Specified by:
shutdown
in interfaceUpdateManager
-
shutdown
public void shutdown(String[] args)
ClientApp interface
-
getState
public ClientAppState getState()
Description copied from interface:ClientApp
The current state of the ClientApp.
-
getName
public String getName()
Description copied from interface:ClientApp
The generic name of the ClientApp, used for registration, e.g. "console". Do not translate.
-
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 interfaceClientApp
- Returns:
- non-null
- Since:
- 0.9.12
-
getStatus
public String getStatus()
The status on any update current or last finished.- Specified by:
getStatus
in 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:
checkAvailable
in 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:
checkAvailable
in 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:
checkAvailable
in 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:
isUpdateInProgress
in interfaceUpdateManager
- Returns:
- true iff router update is being downloaded
-
isUpdateInProgress
public boolean isUpdateInProgress(UpdateType type)
Is a download in progress?- Specified by:
isUpdateInProgress
in 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:
isUpdateInProgress
in 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:
update
in 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:
update
in 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:
update
in 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:
update
in 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:
register
in interfaceUpdateManager
-
unregister
public void unregister(Updater updater, UpdateType type, UpdateMethod method)
- Specified by:
unregister
in interfaceUpdateManager
-
register
public void register(Checker updater, UpdateType type, UpdateMethod method, int priority)
- Specified by:
register
in interfaceUpdateManager
-
unregister
public void unregister(Checker updater, UpdateType type, UpdateMethod method)
- Specified by:
unregister
in interfaceUpdateManager
-
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 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:
notifyVersionAvailable
in 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:
notifyVersionAvailable
in 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:
notifyVersionConstraint
in 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:
notifyCheckComplete
in interfaceUpdateManager
newer
- notifyVersionAvailable was calledsuccess
- check succeeded (newer or not)
-
notifyProgress
public void notifyProgress(UpdateTask task, String status, long downloaded, long totalSize)
- Specified by:
notifyProgress
in interfaceUpdateManager
-
notifyProgress
public void notifyProgress(UpdateTask task, String status)
- Specified by:
notifyProgress
in 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:
notifyAttemptFailed
in 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:
notifyTaskFailed
in 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:
notifyComplete
in 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:
notifyInstalled
in 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:
renderStatusHTML
in interfaceUpdateManager
- Throws:
IOException
-
-