net.i2p.router.update

## Class UpdateRunner

- 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, NewsFetcher, PluginUpdateChecker, PluginUpdateRunner, UnsignedUpdateChecker, UnsignedUpdateRunner

      class UpdateRunner
      extends I2PAppThread
      implements UpdateTask, EepGet.StatusListener

  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 net.i2p.util.I2PThread

      `I2PThread.OOMEventListener`

    - ### Nested classes/interfaces inherited from class java.lang.Thread

      `Thread.State, Thread.UncaughtExceptionHandler`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected ByteArrayOutputStream` | `_baos` 56 byte header, only used for suds
    `protected RouterContext` | `_context`
    `protected URI` | `_currentURI`
    `protected EepGet` | `_get`
    `protected boolean` | `_isPartial` tells the listeners what mode we are in - set to true in extending classes for checks
    `protected boolean` | `_isRunning`
    `protected Log` | `_log`
    `protected UpdateMethod` | `_method`
    `protected ConsoleUpdateManager` | `_mgr`
    `protected String` | `_newVersion` set by the listeners on completion
    `protected UpdateType` | `_type`
    `protected String` | `_updateFile`
    `protected List<URI>` | `_urls`
    `protected static long` | `CONNECT_TIMEOUT`
    `protected boolean` | `done`
    `protected static long` | `INACTIVITY_TIMEOUT`
    `protected static long` | `NOPROXY_INACTIVITY_TIMEOUT`

    - ### Fields inherited from class java.lang.Thread

      `MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `UpdateRunner(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)`
    `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)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected String` | `_t(String s)` translate a string
    `protected String` | `_t(String s, Object o)` translate a string with a parameter
    `void` | `attemptFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt, int numRetries, Exception cause)`
    `void` | `attempting(String url)`
    `void` | `bytesTransferred(long alreadyTransferred, int currentWrite, long bytesTransferred, long bytesRemaining, String url)` subclasses should override
    `String` | `getID()` Valid for plugins
    `UpdateMethod` | `getMethod()` Get the update method.
    `UpdateType` | `getType()` Get the update type.
    `URI` | `getURI()` The current URI being checked or downloaded from.
    `void` | `headerReceived(String url, int attemptNum, String key, String val)` Note: Headers are not processed, and this is not called, for most error response codes, unless setWriteErrorToOutput() is called before fetch().
    `boolean` | `isRunning()` Check if the task is currently running.
    `protected static String` | `linkify(String url)`
    `void` | `run()`
    `void` | `shutdown()` Shutdown the task.
    `String` | `toString()`
    `void` | `transferComplete(long alreadyTransferred, long bytesTransferred, long bytesRemaining, String url, String outputFile, boolean notModified)` subclasses should override
    `void` | `transferFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt)` subclasses should override
    `protected void` | `update()` Loop through the entire list of update URLs.
    `protected void` | `updateStatus(String s)`

    - ### Methods inherited from class net.i2p.util.I2PAppThread

      `addOOMEventThreadListener, fireOOM, removeOOMEventThreadListener`

    - ### Methods inherited from class net.i2p.util.I2PThread

      `addOOMEventListener, removeOOMEventListener, start`

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

      `activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, stop, stop, suspend, yield`

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

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

    - ### Methods inherited from interface net.i2p.update.UpdateTask

      `start`

- - ### Field Detail

    - #### _baos

          protected final ByteArrayOutputStream _baos

      56 byte header, only used for suds

    - #### _context

          protected final RouterContext _context

    - #### _currentURI

          protected URI _currentURI

    - #### _get

          protected EepGet _get

    - #### _isPartial

          protected boolean _isPartial

      tells the listeners what mode we are in - set to true in extending classes for checks

    - #### _isRunning

          protected volatile boolean _isRunning

    - #### _log

          protected final Log _log

    - #### _method

          protected final UpdateMethod _method

    - #### _mgr

          protected final ConsoleUpdateManager _mgr

    - #### _newVersion

          protected String _newVersion

      set by the listeners on completion

    - #### _type

          protected final UpdateType _type

    - #### _updateFile

          protected final String _updateFile

    - #### _urls

          protected final List<URI> _urls

    - #### CONNECT_TIMEOUT

          protected static final long CONNECT_TIMEOUT

      See Also:
        Constant Field Values

    - #### done

          protected boolean done

    - #### INACTIVITY_TIMEOUT

          protected static final long INACTIVITY_TIMEOUT

      See Also:
        Constant Field Values

    - #### NOPROXY_INACTIVITY_TIMEOUT

          protected static final long NOPROXY_INACTIVITY_TIMEOUT

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### UpdateRunner

          public UpdateRunner(RouterContext ctx,
                              ConsoleUpdateManager mgr,
                              UpdateType type,
                              List<URI> uris)

      Uses router version for partial checks

    - #### UpdateRunner

          public UpdateRunner(RouterContext ctx,
                              ConsoleUpdateManager mgr,
                              UpdateType type,
                              List<URI> uris,
                              String currentVersion)

      Parameters:
        `currentVersion` - used for partial checks

    - #### UpdateRunner

          public UpdateRunner(RouterContext ctx,
                              ConsoleUpdateManager mgr,
                              UpdateType type,
                              UpdateMethod method,
                              List<URI> uris)

      Uses router version for partial checks

    - #### UpdateRunner

          public UpdateRunner(RouterContext ctx,
                              ConsoleUpdateManager mgr,
                              UpdateType type,
                              UpdateMethod method,
                              List<URI> uris,
                              String currentVersion)

      Parameters:
        `method` - HTTP, HTTP_CLEARNET, or HTTPS_CLEARNET
        `currentVersion` - used for partial checks

  - ### Method Detail

    - #### _t

          protected String _t(String s)

      translate a string

    - #### _t

          protected String _t(String s,
                              Object o)

      translate a string with a parameter

    - #### attemptFailed

          public void attemptFailed(String url,
                                    long bytesTransferred,
                                    long bytesRemaining,
                                    int currentAttempt,
                                    int numRetries,
                                    Exception cause)

      Specified by:
        `attemptFailed` in interface `EepGet.StatusListener`
      See Also:
        `EepGet.StatusListener.bytesTransferred(long, int, long, long, java.lang.String)`

    - #### attempting

          public void attempting(String url)

      Specified by:
        `attempting` in interface `EepGet.StatusListener`

    - #### bytesTransferred

          public void bytesTransferred(long alreadyTransferred,
                                       int currentWrite,
                                       long bytesTransferred,
                                       long bytesRemaining,
                                       String url)

      subclasses should override
      Specified by:
        `bytesTransferred` in interface `EepGet.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 listener
        `bytesTransferred` - 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 length

    - #### getID

          public String getID()

      Description copied from interface: `UpdateTask`
      Valid for plugins
      Specified by:
        `getID` in interface `UpdateTask`
      Returns:
        plugin ID

    - #### getMethod

          public UpdateMethod getMethod()

      Description copied from interface: `UpdateTask`
      Get the update method.
      Specified by:
        `getMethod` in interface `UpdateTask`
      Returns:
        update method

    - #### getType

          public UpdateType getType()

      Description copied from interface: `UpdateTask`
      Get the update type.
      Specified by:
        `getType` in interface `UpdateTask`
      Returns:
        update type

    - #### getURI

          public URI getURI()

      Description copied from interface: `UpdateTask`
      The current URI being checked or downloaded from. Can change if there are multiple URIs to try.
      Specified by:
        `getURI` in interface `UpdateTask`
      Returns:
        current URI

    - #### headerReceived

          public void headerReceived(String url,
                                     int attemptNum,
                                     String key,
                                     String val)

      Description copied from interface: `EepGet.StatusListener`
      Note: Headers are not processed, and this is not called, for most error response codes, unless setWriteErrorToOutput() is called before fetch(). To be changed?
      Specified by:
        `headerReceived` in interface `EepGet.StatusListener`

    - #### isRunning

          public boolean isRunning()

      Description copied from interface: `UpdateTask`
      Check if the task is currently running.
      Specified by:
        `isRunning` in interface `UpdateTask`
      Returns:
        true if running

    - #### linkify

          protected static String linkify(String url)

    - #### run

          public void run()

      Specified by:
        `run` in interface `Runnable`
      Overrides:
        `run` in class `I2PThread`

    - #### shutdown

          public void shutdown()

      Description copied from interface: `UpdateTask`
      Shutdown the task.
      Specified by:
        `shutdown` in interface `UpdateTask`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Thread`

    - #### transferComplete

          public void transferComplete(long alreadyTransferred,
                                       long bytesTransferred,
                                       long bytesRemaining,
                                       String url,
                                       String outputFile,
                                       boolean notModified)

      subclasses should override
      Specified by:
        `transferComplete` in interface `EepGet.StatusListener`
        `outputFile` - null if unknown (output stream constructor)
      See Also:
        `EepGet.StatusListener.bytesTransferred(long, int, long, long, java.lang.String)`

    - #### transferFailed

          public void transferFailed(String url,
                                     long bytesTransferred,
                                     long bytesRemaining,
                                     int currentAttempt)

      subclasses should override
      Specified by:
        `transferFailed` in interface `EepGet.StatusListener`
      See Also:
        `EepGet.StatusListener.bytesTransferred(long, int, long, long, java.lang.String)`

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

    - #### updateStatus

          protected void updateStatus(String s)