Class CacheReplicator
java.lang.Object
org.frontcache.replication.CacheReplicator
Replicates cache entries from a source edge to a target edge.
Algorithm:
- Fetch the target's key set into memory (O(target size) memory).
- Stream the source's keys. For each key not present on the target,
fetch the full
WebResponsefrom the source and push it to the target. - 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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcancel()Requests cancellation of the running replication.Returns the current result snapshot (safe to call while running).booleanTrue if a replication run is currently in progress.run(ReplicationProgressListener listener) Runs the replication.voidsetWorkerCount(int workerCount) Overrides how many entries are transferred concurrently.
-
Constructor Details
-
CacheReplicator
- Parameters:
source- the edge to read entries fromtarget- 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 benull- Returns:
- the final
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.
-