Class CacheReplicator

java.lang.Object
org.frontcache.replication.CacheReplicator

public class CacheReplicator extends Object
Replicates cache entries from a source edge to a target edge.

Algorithm:

  1. Fetch the target's key set into memory (O(target size) memory).
  2. Stream the source's keys. For each key not present on the target, fetch the full WebResponse from the source and push it to the target.
  3. Entries already present on the target are skipped (idempotent).

The replicator is designed to run in a background thread. Progress is reported via a ReplicationProgressListener. Cancellation is supported via cancel() — the next iteration checks the flag and stops cleanly.

Thread-safety: a single replicator instance must not be shared across threads. The cancelled flag is volatile so a cancelling thread is visible to the replication thread without explicit synchronisation.

  • Constructor Details

    • CacheReplicator

      public CacheReplicator(FrontCacheClient source, FrontCacheClient target)
      Parameters:
      source - the edge to read entries from
      target - the edge to write entries to
  • Method Details

    • setWorkerCount

      public void setWorkerCount(int workerCount)
      Overrides how many entries are transferred concurrently. Values below 1 are clamped to 1, which restores the pre-2.9.0 strictly-sequential behaviour.
    • run

      Runs the replication. Blocks until completion, cancellation, or failure.

      Safe to call only once per instance. Subsequent calls return immediately with the previous result.

      Parameters:
      listener - optional progress listener; may be null
      Returns:
      the final ReplicationResult
    • getCurrentResult

      public ReplicationResult getCurrentResult()
      Returns the current result snapshot (safe to call while running).
    • isRunning

      public boolean isRunning()
      True if a replication run is currently in progress.
    • cancel

      public void cancel()
      Requests cancellation of the running replication. The replicator checks this flag between entries and stops at the next opportunity. No-op if no replication is running.