Class SchemaProjectionWorker

java.lang.Object
org.gcube.informationsystem.resourceregistry.types.SchemaProjectionWorker

public class SchemaProjectionWorker extends Object
Keeps everything derived from the Type schema up to date, in the background.

A single thread owns every rebuild. Requests never rebuild anything: they report a miss and read through to the database, which is what makes an ordinary miss cost O(1) instead of O(all types).

Three ways a rebuild is triggered, deliberately overlapping:

  • Startup — one rebuild once the service is up, so the cache is warm without any request having paid for it.
  • Notification — a ClusterEventType.SCHEMA_CHANGE event, raised by this instance or by any other. This is the low-latency path.
  • Reconciliation — a periodic comparison of the version last built against the version currently recorded. Neither notification channel guarantees delivery, so without this a lost event would leave this instance stale indefinitely. It is a safety net, hence its long interval.

Debouncing is essential, not an optimization. A system restore or a bulk model registration emits one event per Type — hundreds of them, within seconds. Rebuilding per event would make the cost of the mechanism scale with the size of the change rather than with the fact that a change happened. The worker therefore waits for a quiet period before rebuilding, so a burst collapses into a single rebuild.

Author:
Luca Frosini (ISTI - CNR)
  • Method Details

    • getInstance

      public static SchemaProjectionWorker getInstance()
      Returns the singleton instance of SchemaProjectionWorker.
      Returns:
      the singleton instance
    • start

      public void start()
      Subscribes to schema-change events and starts the background thread, which immediately performs the startup rebuild. Idempotent.
    • shutdown

      public void shutdown()
      Stops the background thread. Idempotent.
    • getBuiltVersion

      public long getBuiltVersion()
      Returns the schema version the current projections were built from.
      Returns:
      the built version, or SchemaVersionCounter.UNKNOWN_VERSION if nothing has been built yet