java.lang.Object
java.lang.Thread
net.i2p.util.I2PThread
net.i2p.util.I2PAppThread
net.i2p.router.update.UpdateRunner
- All Implemented Interfaces:
Runnable, UpdateTask, EepGet.StatusListener
- Direct Known Subclasses:
DevSU3UpdateChecker, DevSU3UpdateRunner, DummyHandler.DummyRunner, NewsFetcher, PluginUpdateChecker, PluginUpdateRunner, UnsignedUpdateChecker, UnsignedUpdateRunner
The downloader for router signed updates, and the base class for all the other Checkers and Runners.
Nested Class Summary
Nested classes/interfaces inherited from class I2PThread
I2PThread.OOMEventListenerModifier and TypeClassDescriptionstatic interfaceListener for out-of-memory events.Nested classes/interfaces inherited from class Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandlerField Summary
FieldsModifier and TypeFieldDescriptionprotected final ByteArrayOutputStream56 byte header, only used for suds.protected final RouterContextRouter context.protected URICurrent URI being fetched.private final StringCurrent router version for comparison.protected EepGetThe current EepGet instance.protected booleanTells the listeners what mode we are in - set to true in extending classes for checks.protected booleanWhether the runner is currently running.protected final LogClass logger.protected final UpdateMethodUpdate method.protected final ConsoleUpdateManagerUpdate manager.protected StringSet by the listeners on completion.protected final UpdateTypeUpdate type.protected final StringTemporary file for the update download.List of update URIs.protected static final longConnect timeout in ms.protected booleanWhether the update completed.protected static final longInactivity timeout with proxy in ms.protected static final longInactivity timeout without proxy in ms.Fields inherited from class Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITYConstructor Summary
ConstructorsConstructorDescriptionUpdateRunner(RouterContext ctx, ConsoleUpdateManager mgr, UpdateType type, List<URI> uris) Uses router version for partial checks.UpdateRunner(RouterContext ctx, ConsoleUpdateManager mgr, UpdateType type, List<URI> uris, String currentVersion) Constructor with explicit current version.UpdateRunner(RouterContext ctx, ConsoleUpdateManager mgr, UpdateType type, UpdateMethod method, List<URI> uris) Uses router version for partial checks.UpdateRunner(RouterContext ctx, ConsoleUpdateManager mgr, UpdateType type, UpdateMethod method, List<URI> uris, String currentVersion) Full constructor.Method Summary
Modifier and TypeMethodDescriptionprotected StringTranslate a string.protected StringTranslate a string with a parameter.voidattemptFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt, int numRetries, Exception cause) An attempt failed.voidattempting(String url) A retry is starting.voidbytesTransferred(long alreadyTransferred, int currentWrite, long bytesTransferred, long bytesRemaining, String url) Subclasses should override.getID()I d.Returns how the update is fetched, such as HTTP or torrent.getType()Returns what kind of update this runner handles.getURI()U r i.voidheaderReceived(String url, int attemptNum, String key, String val) HTTP response headers are not used to determine the update version.booleanWhether running.protected static StringWrap a URL in an anchor tag for display.voidrun()Runs the update, reporting any failure to the update manager.voidshutdown()Clears the running flag and interrupts any update in progress.toString()Handler summary for log messages.voidtransferComplete(long alreadyTransferred, long bytesTransferred, long bytesRemaining, String url, String outputFile, boolean notModified) Subclasses should override.voidtransferFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt) Subclasses should override.protected voidupdate()Loop through the entire list of update URLs.protected voidReport progress to the user.Methods inherited from class I2PAppThread
addOOMEventThreadListener, fireOOM, removeOOMEventThreadListenerModifier and TypeMethodDescriptionvoidRegister a new component that wants notification of OOM events.protected voidfireOOM(OutOfMemoryError oom) Notify listeners that an OutOfMemoryError occurred.voidUnregister a component that wants notification of OOM events.Methods inherited from class I2PThread
addOOMEventListener, removeOOMEventListener, startModifier and TypeMethodDescriptionstatic voidRegister a new component that wants notification of OOM events.static voidUnregister a component that wants notification of OOM events.voidstart()Overridden to provide useful info to users on OOM, and to prevent shutting down the whole JVM for what is most likely not a heap issue.Methods inherited from class Thread
activeCount, clone, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, startVirtualThread, threadId, yieldMethods inherited from interface UpdateTask
start
Field Details
_context
Router context._log
Class logger._mgr
Update manager._type
Update type._method
Update method._urls
_updateFile
Temporary file for the update download._isRunning
protected volatile boolean _isRunningWhether the runner is currently running.done
protected boolean doneWhether the update completed._get
The current EepGet instance._isPartial
protected boolean _isPartialTells the listeners what mode we are in - set to true in extending classes for checks._newVersion
Set by the listeners on completion._baos
56 byte header, only used for suds._currentURI
Current URI being fetched._currentVersion
Current router version for comparison.CONNECT_TIMEOUT
INACTIVITY_TIMEOUT
protected static final long INACTIVITY_TIMEOUTInactivity timeout with proxy in ms.- See Also:
NOPROXY_INACTIVITY_TIMEOUT
protected static final long NOPROXY_INACTIVITY_TIMEOUTInactivity timeout without proxy in ms.- See Also:
Constructor Details
UpdateRunner
Uses router version for partial checks.- Parameters:
ctx- the router context supplying the logger and temp directorymgr- the update manager notified of progress and resultstype- what is being updated, as an UpdateType constanturis- list of update URIs
UpdateRunner
public UpdateRunner(RouterContext ctx, ConsoleUpdateManager mgr, UpdateType type, UpdateMethod method, List<URI> uris) Uses router version for partial checks.- Parameters:
ctx- the router context supplying the logger and temp directorymgr- the update manager notified of progress and resultstype- what is being updated, as an UpdateType constantmethod- how to fetch the update, as an UpdateMethod constanturis- list of update URIs
UpdateRunner
public UpdateRunner(RouterContext ctx, ConsoleUpdateManager mgr, UpdateType type, List<URI> uris, String currentVersion) Constructor with explicit current version.- Parameters:
ctx- the router context supplying the logger and temp directorymgr- the update manager notified of progress and resultstype- what is being updated, as an UpdateType constanturis- list of update URIscurrentVersion- used for partial checks
UpdateRunner
public UpdateRunner(RouterContext ctx, ConsoleUpdateManager mgr, UpdateType type, UpdateMethod method, List<URI> uris, String currentVersion) Full constructor.- Parameters:
ctx- the router context supplying the logger and temp directorymgr- the update manager notified of progress and resultstype- what is being updated, as an UpdateType constantmethod- HTTP, HTTP_CLEARNET, or HTTPS_CLEARNETuris- list of update URIscurrentVersion- used for partial checks
Method Details
isRunning
public boolean isRunning()Whether running.- Specified by:
isRunningin interfaceUpdateTask- Returns:
- true while an update is in progress
shutdown
public void shutdown()Clears the running flag and interrupts any update in progress.- Specified by:
shutdownin interfaceUpdateTask
getType
Returns what kind of update this runner handles.- Specified by:
getTypein interfaceUpdateTask- Returns:
- the UpdateType this runner was created for
getMethod
Returns how the update is fetched, such as HTTP or torrent.- Specified by:
getMethodin interfaceUpdateTask- Returns:
- the UpdateMethod this runner was created for
getURI
getID
run
update
protected void update()Loop through the entire list of update URLs. For each one, first get the version from the first 56 bytes and see if it is newer than what we are running now. If it is, get the whole thing.attemptFailed
public void attemptFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt, int numRetries, Exception cause) An attempt failed. We do not abort here - EepGet retries on its own - so this only reports the failure to the user.- Specified by:
attemptFailedin interfaceEepGet.StatusListener- Parameters:
url- the address whose fetch attempt failedbytesTransferred- bytes received so far, counted across every attempt and including response headersbytesRemaining- bytes still owed, or -1 if unknowncurrentAttempt- zero-based index of the attempt that failednumRetries- total attempts this fetch is allowedcause- the exception that ended the attempt- See Also:
bytesTransferred
public void bytesTransferred(long alreadyTransferred, int currentWrite, long bytesTransferred, long bytesRemaining, String url) Subclasses should override.- Specified by:
bytesTransferredin interfaceEepGet.StatusListener- Parameters:
alreadyTransferred- total of all attempts, not including currentWrite If nonzero on the first call, a partial file of that length was found, _and_ the server supports resume. If zero on a subsequent call after some bytes are transferred (and presumably after an attemptFailed), the server does _not_ support resume and we had to start over. To track _actual_ transfer if the output file could already exist, the listener should keep its own counter, or subtract the initial alreadyTransferred value. And watch out for alreadyTransferred resetting if a resume failed...currentWrite- since last call to the listenerbytesTransferred- includes headers, retries, redirects, discarded partial downloads, ...bytesRemaining- on this attempt only, currentWrite already subtracted - or -1 if chunked encoding or server does not return a lengthurl- the URL being fetched
transferComplete
public void transferComplete(long alreadyTransferred, long bytesTransferred, long bytesRemaining, String url, String outputFile, boolean notModified) Subclasses should override.- Specified by:
transferCompletein interfaceEepGet.StatusListener- Parameters:
alreadyTransferred- total bytes transferredbytesTransferred- total incl headersbytesRemaining- bytes still owed by the server, or -1 if chunked encoding or no Content-Length was returnedurl- the address the transfer was readingoutputFile- null if unknown (output stream constructor)notModified- whether 304- See Also:
transferFailed
public void transferFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt) Subclasses should override.- Specified by:
transferFailedin interfaceEepGet.StatusListener- Parameters:
url- the address whose transfer failedbytesTransferred- bytes received so far, counted across every attempt and including response headersbytesRemaining- bytes still owed, or -1 if unknowncurrentAttempt- zero-based index of the attempt that failed- See Also:
headerReceived
HTTP response headers are not used to determine the update version.- Specified by:
headerReceivedin interfaceEepGet.StatusListener- Parameters:
url- the address the header arrived onattemptNum- zero-based index of the attempt the header arrived onkey- header keyval- header value
attempting
A retry is starting. Retries are counted byEepGet, which reports the final failure throughtransferFailed(String, long, long, int), so there is nothing to do.- Specified by:
attemptingin interfaceEepGet.StatusListener- Parameters:
url- the URL being attempted
updateStatus
Report progress to the user.- Parameters:
s- the progress line to show, already translated
linkify
_t
_t
toString