Class PNCounter

java.lang.Object
org.apache.pekko.cluster.ddata.PNCounter
All Implemented Interfaces:
Serializable, DeltaReplicatedData, RemovedNodePruning, ReplicatedData, ReplicatedDataSerialization, ReplicatedDelta

Implements a 'Increment/Decrement Counter' CRDT, also called a 'PN-Counter'.

It is described in the paper A comprehensive study of Convergent and Commutative Replicated Data Types.

PN-Counters allow the counter to be incremented by tracking the increments (P) separate from the decrements (N). Both P and N are represented as two internal GCounters. Merge is handled by merging the internal P and N counters. The value of the counter is the value of the P counter minus the value of the N counter.

This class is immutable, i.e. "modifying" methods return a new instance.

See Also:
  • Method Details

    • empty

      public static PNCounter empty()
    • apply

      public static PNCounter apply()
    • create

      public static PNCounter create()
      Java API
    • unapply

      public static scala.Option<scala.math.BigInt> unapply(PNCounter c)
      Extract the GCounter.value().
    • value

      public scala.math.BigInt value()
      Scala API: Current total value of the counter.
    • getValue

      public BigInteger getValue()
      Java API: Current total value of the counter.
    • $colon$plus

      public PNCounter $colon$plus(long n, SelfUniqueAddress node)
      Increment the counter with the delta n specified. If the delta is negative then it will decrement instead of increment.
    • $colon$plus

      public PNCounter $colon$plus(scala.math.BigInt n, SelfUniqueAddress node)
      Increment the counter with the delta n specified. If the delta is negative then it will decrement instead of increment.
    • increment

      public PNCounter increment(long n, SelfUniqueAddress node)
      Scala API: Increment the counter with the delta n specified. If the delta is negative then it will decrement instead of increment.
    • increment

      public PNCounter increment(scala.math.BigInt n, SelfUniqueAddress node)
      Increment the counter with the delta n specified. If the delta is negative then it will decrement instead of increment.
    • increment

      public PNCounter increment(SelfUniqueAddress node, BigInteger n)
      Java API: Increment the counter with the delta n specified. If the delta is negative then it will decrement instead of increment.
    • increment

      public PNCounter increment(SelfUniqueAddress node, long n)
      Java API: Increment the counter with the delta n specified. If the delta is negative then it will decrement instead of increment.
    • decrement

      public PNCounter decrement(long n, SelfUniqueAddress node)
      Decrement the counter with the delta n specified. If the delta is negative then it will increment instead of decrement.
    • decrement

      public PNCounter decrement(scala.math.BigInt n, SelfUniqueAddress node)
      Decrement the counter with the delta n specified. If the delta is negative then it will increment instead of decrement.
    • decrement

      public PNCounter decrement(SelfUniqueAddress node, long n)
      Decrement the counter with the delta n specified. If the delta n is negative then it will increment instead of decrement.
    • decrement

      public PNCounter decrement(SelfUniqueAddress node, scala.math.BigInt n)
      Scala API: Decrement the counter with the delta n specified. If the delta n is negative then it will increment instead of decrement.
    • decrement

      public PNCounter decrement(SelfUniqueAddress node, BigInteger n)
      Java API: Decrement the counter with the delta n specified. If the delta n is negative then it will increment instead of decrement.
    • merge

      public PNCounter merge(PNCounter that)
    • delta

      public scala.Option<PNCounter> delta()
      Description copied from interface: DeltaReplicatedData
      The accumulated delta of mutator operations since previous DeltaReplicatedData.resetDelta(). When the Replicator invokes the modify function of the Update message and the user code is invoking one or more mutator operations the data is collecting the delta of the operations and makes it available for the Replicator with the DeltaReplicatedData.delta() accessor. The modify function shall still return the full state in the same way as ReplicatedData without support for deltas.
      Specified by:
      delta in interface DeltaReplicatedData
    • mergeDelta

      public PNCounter mergeDelta(PNCounter thatDelta)
    • zero

      public PNCounter zero()
      Description copied from interface: ReplicatedDelta
      The empty full state. This is used when a delta is received and no existing full state exists on the receiving side. Then the delta is merged into the zero to create the initial full state.
      Specified by:
      zero in interface ReplicatedDelta
    • resetDelta

      public PNCounter resetDelta()
      Description copied from interface: DeltaReplicatedData
      Reset collection of deltas from mutator operations. When the Replicator invokes the modify function of the Update message the delta is always "reset" and when the user code is invoking one or more mutator operations the data is collecting the delta of the operations and makes it available for the Replicator with the DeltaReplicatedData.delta() accessor. When the Replicator has grabbed the delta it will invoke this method to get a clean data instance without the delta.
      Specified by:
      resetDelta in interface DeltaReplicatedData
    • modifiedByNodes

      public scala.collection.immutable.Set<UniqueAddress> modifiedByNodes()
      Description copied from interface: RemovedNodePruning
      The nodes that have changed the state for this data and would need pruning when such node is no longer part of the cluster.
      Specified by:
      modifiedByNodes in interface RemovedNodePruning
    • needPruningFrom

      public boolean needPruningFrom(UniqueAddress removedNode)
      Description copied from interface: RemovedNodePruning
      Does it have any state changes from a specific node, which has been removed from the cluster.
      Specified by:
      needPruningFrom in interface RemovedNodePruning
    • prune

      public PNCounter prune(UniqueAddress removedNode, UniqueAddress collapseInto)
      Description copied from interface: RemovedNodePruning
      When the removed node has been removed from the cluster the state changes from that node will be pruned by collapsing the data entries to another node.
      Specified by:
      prune in interface RemovedNodePruning
    • pruningCleanup

      public PNCounter pruningCleanup(UniqueAddress removedNode)
      Description copied from interface: RemovedNodePruning
      Remove data entries from a node that has been removed from the cluster and already been pruned.
      Specified by:
      pruningCleanup in interface RemovedNodePruning
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object