Class WebEngineStats

java.lang.Object
com.iizix.server.webengine.WebEngineStats

public final class WebEngineStats extends Object
The counts of the web engines the client sessions of this server arrived on: how many are connected now and how many connected since the server started, per status and per group row (design CC-DESIGN-WEBVIEW-WARNING section 8.2, work order CC-WEBENGINE-SERVER). This is what ServerAdmin shows: the ruling asks for "how many sessions arrive unpatched".

In memory, since the server started (design D-11): the counts start at zero with the server, and in a hub cluster each server has its own counts. What survives a restart is the daily totals: every connect is also counted for its day in UTC, and WebEngineHistory takes those day counts (drainDays()) into the server database (CC-WEBENGINE-STATS-V51). The since-start counters can be reset by an administrator (resetConnects(Instant)) and the reset undone (addConnects(Map, Instant)); "active now" is live and never reset.

A group row is one combination of application, platform, product, OS major, engine major and status: "demo, Android, Android System WebView, 7, 119, ENDED". A session is counted in exactly one row, and in the totals of its status:

Bounded. The OS and engine majors of a row come from the client's user agent, which the peer controls, so the number of rows is capped at 1000: a session whose row would be one too many is counted in the shared overflow row of its status (application null) and in the totals, which are always exact.

Thread safe: every method takes the one monitor of the instance, held for a map lookup and a few additions. No clock inside: "now" is a parameter.

Author:
Christopher Mindus
  • Field Details

    • MAX_ROWS

      public static final int MAX_ROWS
      The most group rows kept; sessions beyond are counted in the overflow row of their status, of which there is one per status on top of these.
      See Also:
  • Constructor Details

    • WebEngineStats

      public WebEngineStats(Instant since)
      Creates the counts, all zero.
      Parameters:
      since - When counting starts: the server start.
  • Method Details

    • getSince

      public Instant getSince()
      Gets when counting started.
      Returns:
      The server start, or the moment of the last reset of the since-start counters.
    • connect

      public WebEngineStats.Group connect(String appID, WebEngineStatus status, Instant now)
      Counts a new session: one more connect and one more active session, in the totals of its status and in its group row.
      Parameters:
      appID - The application ID.
      status - The verdict of the session.
      now - Now.
      Returns:
      The group the session is counted in, to be handed to move(WebEngineStats.Group, String, WebEngineStatus, Instant) and disconnect(WebEngineStats.Group).
    • move

      public WebEngineStats.Group move(WebEngineStats.Group from, String appID, WebEngineStatus status, Instant now)
      Moves a counted session to the group of a new verdict, at a reconnect: the active counts follow, no connect is counted.
      Parameters:
      from - The group the session is counted in, as connect(String, WebEngineStatus, Instant) or this method returned it.
      appID - The application ID.
      status - The new verdict.
      now - Now.
      Returns:
      The group the session is counted in now.
    • disconnect

      public void disconnect(WebEngineStats.Group group)
      Ends a counted session: one less active session in its status and its group row.
      Parameters:
      group - The group the session is counted in, null for a session that never was.
    • drainDays

      public List<WebEngineStats.DayCount> drainDays()
      Takes the connects counted per day and group since the last call, and forgets them here: the history adds them to its stored daily totals.
      Returns:
      The day counts, in no particular order; empty when nothing connected.
    • peekDays

      public List<WebEngineStats.DayCount> peekDays()
      Reads the connects counted per day and group since the last drain, without forgetting them: what the history adds to its stored totals when it answers a period before the next drain.
      Returns:
      The day counts, in no particular order; empty when nothing connected.
    • restoreDays

      public void restoreDays(List<WebEngineStats.DayCount> counts)
      Gives day counts back after a failed write: what drainDays() took is counted again, on top of what connected since.
      Parameters:
      counts - The day counts to give back.
    • resetConnects

      public Map<WebEngineStats.Group, Long> resetConnects(Instant now)
      Resets the since-start counters: every connect count goes to zero, in the totals and in the rows, counting starts again now, and a row that has no active session left is dropped. The "active now" counts are not touched, and neither are the day counts not yet drained.
      Parameters:
      now - Now: when counting starts again.
      Returns:
      The connects taken away, per group, for the history's backup; empty when there were none.
    • addConnects

      public void addConnects(Map<WebEngineStats.Group, Long> connects, Instant since)
      Adds connects to the since-start counters, per group and in the totals of each group's status: the undo of a reset, which gives back what resetConnects(Instant) took away on top of what was counted since. A group without a row gets one, with no active session.
      Parameters:
      connects - The connects per group.
      since - When counting started before the reset, or null to leave it as it is.
    • snapshot

      public WebEngineStats.Snapshot snapshot()
      Gets the counts as they are now.
      Returns:
      The snapshot, unmodifiable.