Class WebEngineStats
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:
connect(String, WebEngineStatus, Instant)counts a new session: one more connect and one more active session;move(WebEngineStats.Group, String, WebEngineStatus, Instant)moves a session that was classified again, at a reconnect, to the row of its new verdict: the active counts follow, and NO connect is counted a second time;disconnect(WebEngineStats.Group)ends a session: one less active.
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
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordThe connects of one day in one group, asdrainDays()hands them to the history.static final recordThe key of a group row, and what a session holds while it is counted: handed back tomove(WebEngineStats.Group, String, WebEngineStatus, Instant)anddisconnect(WebEngineStats.Group).static final recordOne group row of a snapshot.static final recordThe counts at one moment, detached from the live instance.static final recordThe two counts of a status or a row.Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe 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.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionvoidaddConnects(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 whatresetConnects(Instant)took away on top of what was counted since.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.voiddisconnect(WebEngineStats.Group group) Ends a counted session: one less active session in its status and its group row.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.getSince()Gets when counting started.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.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.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.voidrestoreDays(List<WebEngineStats.DayCount> counts) Gives day counts back after a failed write: whatdrainDays()took is counted again, on top of what connected since.snapshot()Gets the counts as they are now.
Field Details
MAX_ROWS
public static final int MAX_ROWSThe 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
Creates the counts, all zero.- Parameters:
since- When counting starts: the server start.
Method Details
getSince
Gets when counting started.- Returns:
- The server start, or the moment of the last reset of the since-start counters.
connect
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)anddisconnect(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, asconnect(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
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
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
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
Gives day counts back after a failed write: whatdrainDays()took is counted again, on top of what connected since.- Parameters:
counts- The day counts to give back.
resetConnects
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
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 whatresetConnects(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
Gets the counts as they are now.- Returns:
- The snapshot, unmodifiable.