Class StatisticsWorker
java.lang.Object
org.gcube.informationsystem.resourceregistry.statistics.StatisticsWorker
Computes the groups of the public statistics in the background and keeps the last result of
each, which is what
GET /statistics returns: a public request never touches the
database.
The light groups (contexts, types, queryTemplates) are counts over
data the registry already caches and are refreshed every LIGHT_INTERVAL_MINUTES
minutes; the heavy ones (instances, connectivity) scan every instance and are
refreshed every HEAVY_INTERVAL_HOURS hours, in one pass.
The worker never delays the startup of the service nor a request: it runs on its own thread,
which checks every TICK_MINUTES minute which groups are due. A group is due when its
interval has elapsed or its last computation failed, so a computation that fails at startup,
before the database is ready, is retried at the next check; a failed computation keeps the
previous result of the group.
- Author:
- Luca Frosini (ISTI - CNR)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe name of the field each group carries with the time it was computed.static final String[]The groups, in the order of the document.static final longThe refresh interval of the heavy groups.static final longThe refresh interval of the light groups.static final longHow often the worker checks which groups are due. -
Method Summary
Modifier and TypeMethodDescriptionbooleanComputes theinstancesandconnectivitygroups, in one scan.booleanComputes thecontexts,typesandqueryTemplatesgroups.org.gcube.com.fasterxml.jackson.databind.node.ObjectNodedocument()Returns the statistics document: every group, withcomputedAtnull for a group whose first computation has not ended yet.static StatisticsWorkerReturns the singleton instance ofStatisticsWorker.voidshutdown()Stops the background thread.voidstart()Starts the background thread, which computes every group at its first check.
-
Field Details
-
LIGHT_INTERVAL_MINUTES
public static final long LIGHT_INTERVAL_MINUTESThe refresh interval of the light groups.- See Also:
-
HEAVY_INTERVAL_HOURS
public static final long HEAVY_INTERVAL_HOURSThe refresh interval of the heavy groups.- See Also:
-
TICK_MINUTES
public static final long TICK_MINUTESHow often the worker checks which groups are due.- See Also:
-
COMPUTED_AT_PROPERTY
The name of the field each group carries with the time it was computed.- See Also:
-
GROUPS
The groups, in the order of the document.
-
-
Method Details
-
getInstance
Returns the singleton instance ofStatisticsWorker.- Returns:
- the singleton instance
-
start
public void start()Starts the background thread, which computes every group at its first check. Idempotent. -
shutdown
public void shutdown()Stops the background thread. Idempotent. -
computeLightGroups
public boolean computeLightGroups()Computes thecontexts,typesandqueryTemplatesgroups.- Returns:
trueif every group was computed
-
computeHeavyGroups
public boolean computeHeavyGroups()Computes theinstancesandconnectivitygroups, in one scan.- Returns:
trueif both groups were computed
-
document
public org.gcube.com.fasterxml.jackson.databind.node.ObjectNode document()Returns the statistics document: every group, withcomputedAtnull for a group whose first computation has not ended yet.- Returns:
- the document
-