Class CrdtManager

java.lang.Object
com.loomcache.server.datastructures.crdt.CrdtManager

public class CrdtManager extends Object
Manager for CRDT instances across the distributed cache.

The CrdtManager maintains a registry of all CRDT instances and handles merge operations during replication. It tracks statistics about CRDT usage and manages convergence of state across replicas.

Key responsibilities:

  • Registry for all CRDT instances
  • Tracking CRDT types and instance counts
  • Handling merge operations during replication
  • Collecting and reporting statistics
Since:
1.3
  • Constructor Details

    • CrdtManager

      public CrdtManager(String nodeId, int instanceNumber)
  • Method Details

    • registerPNCounter

      public void registerPNCounter(String name, PNCounter counter)
      Register a PN-Counter instance.
      Parameters:
      name - the unique name of the CRDT instance
      counter - the PN-Counter instance
      Throws:
      IllegalArgumentException - if name already exists
    • getPNCounter

      public @Nullable PNCounter getPNCounter(String name)
      Get a registered PN-Counter.
      Parameters:
      name - the name of the CRDT instance
      Returns:
      the PN-Counter, or null if not found
    • registerGSet

      public <E> void registerGSet(String name, GSet<E> set)
      Register a G-Set instance.
      Parameters:
      name - the unique name of the CRDT instance
      set - the G-Set instance
      Throws:
      IllegalArgumentException - if name already exists
    • getGSet

      public <E> @Nullable GSet<E> getGSet(String name)
      Get a registered G-Set.
      Parameters:
      name - the name of the CRDT instance
      Returns:
      the G-Set, or null if not found
    • registerORSet

      public <E> void registerORSet(String name, ORSet<E> set)
      Register an OR-Set instance.
      Parameters:
      name - the unique name of the CRDT instance
      set - the OR-Set instance
      Throws:
      IllegalArgumentException - if name already exists
    • getORSet

      public <E> @Nullable ORSet<E> getORSet(String name)
      Get a registered OR-Set.
      Parameters:
      name - the name of the CRDT instance
      Returns:
      the OR-Set, or null if not found
    • registerLWWRegister

      public <V> void registerLWWRegister(String name, LWWRegister<V> register)
      Register an LWW-Register instance.
      Parameters:
      name - the unique name of the CRDT instance
      register - the LWW-Register instance
      Throws:
      IllegalArgumentException - if name already exists
    • getLWWRegister

      public <V> @Nullable LWWRegister<V> getLWWRegister(String name)
      Get a registered LWW-Register.
      Parameters:
      name - the name of the CRDT instance
      Returns:
      the LWW-Register, or null if not found
    • getInstanceCount

      public int getInstanceCount()
      Get the number of registered CRDT instances.
      Returns:
      the total number of instances
    • getTotalMerges

      public long getTotalMerges()
      Get the total number of merge operations performed.
      Returns:
      the merge count
    • recordMerge

      public void recordMerge()
      Increment the merge counter (called by replication logic).
    • getStats

      public CrdtStats getStats()
      Get current statistics about CRDT usage.
      Returns:
      a CrdtStats record with usage information
    • reset

      public void reset()
      Clear all registered CRDT instances.