Class WebEngineRefresher

java.lang.Object
com.iizix.server.webengine.WebEngineRefresher
All Implemented Interfaces:
AutoCloseable

public final class WebEngineRefresher extends Object implements AutoCloseable
The weekly refresh of the Chrome majors' first-stable days in the web-engine support table, from Google's VersionHistory service (design CC-DESIGN-WEBVIEW-WARNING sections 5.2 and 5.3, decision D-6, work order CC-WEBENGINE-REFRESH).

What it refreshes: chromium.firstStable only, the day each Chrome major was first served on Android's stable channel. The Android and iOS "ended" facts never come from here: they ship with the server's releases and the override file (design D-7).

How: one request for the newest major Google serves on android/stable, then one request per major newer than the bundled table's newest, each asking for that major's first release served to a non-zero fraction of devices - the rule that dates the bundled table (BuildUtil/scripts/Update-WebEngineTable.ps1). A weekly run therefore costs two or three small requests. The days fetched are added to the BUNDLED table's days, never to an earlier cache, so that nothing an older run wrote is carried on; the result is checked against every bound the table applies on load (WebEngineSupportTable) and written to the cache file "webengine"/"webengine-cache.json" in the server's current directory, through a temporary file and a move. The table in use is then loaded again (WebEngineAdvisor.loadTable(ServerSettings,Path)), with the cache as its second source.

Bounds: an answer that is not HTTP 200, is larger than 65536 bytes, ends early, takes longer than its timeouts, is not JSON or not the service's shape, names a major outside 50..999 or more than 100 majors past the bundled table, answers a request for one major with a release of another, a release served to nobody, or a day the table's bounds refuse, fails the WHOLE run: nothing is written, the table in use and the cache stay as they were, and the next attempt comes a day later (RETRY). Nothing here ever throws into the server.

The request carries nothing of the server, its sessions or its users: a GET of a public, anonymous URL through HttpClient, with a connect timeout and a request timeout of 10 s each and the whole exchange, body included, bounded by their sum; no cookie handler; no redirect followed; the system proxy selector, as IP2Location's downloads use; and no header beyond the client's own (its User-Agent is Java's default).

The log: one INFO line when the server starts, naming the URL and the cache file, or saying why nothing is refreshed; one WARNING for the first failure of a streak, FINE for the failures after it, and one INFO when a refresh succeeds after a streak. Every successful refresh shows as the advisor's "Web engine support table loaded" line.

When: FIRST_DELAY after the server starts when the cache is missing or at least INTERVAL old, otherwise when it reaches that age; then INTERVAL after a success and RETRY after a failure. The work runs on one virtual thread of a single-thread scheduler, as IP2Location's update checks do (co.mindus.ip2location). stop() interrupts a run in progress; a stopped run loads nothing and warns nothing.

Switches: the server setting ServerSettings.WEB_ENGINE_REFRESH (default on), read when the server starts. Nothing is refreshed while ServerSettings.WEB_ENGINE_DATA_FILE names a file: that file replaces the whole table, cache included.

Author:
Christopher Mindus
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The VersionHistory releases of Chrome on Android's stable channel.
    static final String
    The directory of the cache file, in the server's current directory.
    static final String
    The cache file.
    static final Duration
    The time from the server's start to the first refresh when the cache is missing or due: long enough that a server restarted again and again, or one started for a test that ends within minutes, asks nothing of the service.
    static final Duration
    The time from a successful refresh to the next.
    static final int
    The most majors past the bundled table's newest one run asks for: about four years of two-week milestones.
    static final int
    The largest answer read, in bytes.
    static final Duration
    The time from a failed refresh to the next attempt.
    static final int
    The connect timeout and the request timeout, in seconds, each.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Path
    cacheFileOf(ServerSettings settings, File currentDirectory)
    Gets the cache file of a server: "webengine"/"webengine-cache.json" in its current directory, when the refresh is on and no override file replaces the whole table.
    void
    Same as stop().
    start(ServerSettings settings, File currentDirectory)
    Starts the weekly refresh of a starting server, or says in one INFO line why it does not run.
    void
    Stops the refresh: no run is started any more, and a run in progress is interrupted and then loads nothing and warns nothing.
  • Field Details

    • API

      public static final String API
      The VersionHistory releases of Chrome on Android's stable channel.
      See Also:
    • CACHE_DIRECTORY

      public static final String CACHE_DIRECTORY
      The directory of the cache file, in the server's current directory.
      See Also:
    • CACHE_FILE

      public static final String CACHE_FILE
      The cache file.
      See Also:
    • INTERVAL

      public static final Duration INTERVAL
      The time from a successful refresh to the next.
    • RETRY

      public static final Duration RETRY
      The time from a failed refresh to the next attempt.
    • FIRST_DELAY

      public static final Duration FIRST_DELAY
      The time from the server's start to the first refresh when the cache is missing or due: long enough that a server restarted again and again, or one started for a test that ends within minutes, asks nothing of the service.
    • TIMEOUT_SECONDS

      public static final int TIMEOUT_SECONDS
      The connect timeout and the request timeout, in seconds, each.
      See Also:
    • MAX_RESPONSE_BYTES

      public static final int MAX_RESPONSE_BYTES
      The largest answer read, in bytes. An answer of one release is under 1 KB.
      See Also:
    • MAX_NEW_MAJORS

      public static final int MAX_NEW_MAJORS
      The most majors past the bundled table's newest one run asks for: about four years of two-week milestones.
      See Also:
  • Method Details

    • cacheFileOf

      public static Path cacheFileOf(ServerSettings settings, File currentDirectory)
      Gets the cache file of a server: "webengine"/"webengine-cache.json" in its current directory, when the refresh is on and no override file replaces the whole table.
      Parameters:
      settings - The server settings, null for none.
      currentDirectory - The server's current directory, null for none.
      Returns:
      The file, or null when no cache is to be read or written.
    • start

      public static WebEngineRefresher start(ServerSettings settings, File currentDirectory)
      Starts the weekly refresh of a starting server, or says in one INFO line why it does not run. Never throws.
      Parameters:
      settings - The server settings.
      currentDirectory - The server's current directory, where the cache is kept.
      Returns:
      The refresher, to stop() when the server stops; null when nothing is refreshed.
    • stop

      public void stop()
      Stops the refresh: no run is started any more, and a run in progress is interrupted and then loads nothing and warns nothing. Idempotent; never throws.
    • close

      public void close()
      Same as stop().
      Specified by:
      close in interface AutoCloseable