Package org.apache.pekko.cluster.ddata
Class PNCounter
java.lang.Object
org.apache.pekko.cluster.ddata.PNCounter
- All Implemented Interfaces:
Serializable,DeltaReplicatedData,RemovedNodePruning,ReplicatedData,ReplicatedDataSerialization,ReplicatedDelta
public final class PNCounter
extends Object
implements DeltaReplicatedData, ReplicatedDelta, ReplicatedDataSerialization, RemovedNodePruning
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 Summary
Modifier and TypeMethodDescription$colon$plus(long n, SelfUniqueAddress node) Increment the counter with the deltanspecified.$colon$plus(scala.math.BigInt n, SelfUniqueAddress node) Increment the counter with the deltanspecified.static PNCounterapply()static PNCountercreate()Java APIdecrement(long n, SelfUniqueAddress node) Decrement the counter with the deltanspecified.decrement(SelfUniqueAddress node, long n) Decrement the counter with the deltanspecified.decrement(SelfUniqueAddress node, BigInteger n) Java API: Decrement the counter with the deltanspecified.decrement(SelfUniqueAddress node, scala.math.BigInt n) Scala API: Decrement the counter with the deltanspecified.decrement(scala.math.BigInt n, SelfUniqueAddress node) Decrement the counter with the deltanspecified.scala.Option<PNCounter>delta()The accumulated delta of mutator operations since previousDeltaReplicatedData.resetDelta().static PNCounterempty()booleangetValue()Java API: Current total value of the counter.inthashCode()increment(long n, SelfUniqueAddress node) Scala API: Increment the counter with the deltanspecified.increment(SelfUniqueAddress node, long n) Java API: Increment the counter with the deltanspecified.increment(SelfUniqueAddress node, BigInteger n) Java API: Increment the counter with the deltanspecified.increment(scala.math.BigInt n, SelfUniqueAddress node) Increment the counter with the deltanspecified.mergeDelta(PNCounter thatDelta) scala.collection.immutable.Set<UniqueAddress>The nodes that have changed the state for this data and would need pruning when such node is no longer part of the cluster.booleanneedPruningFrom(UniqueAddress removedNode) Does it have any state changes from a specific node, which has been removed from the cluster.prune(UniqueAddress removedNode, UniqueAddress collapseInto) When theremovednode has been removed from the cluster the state changes from that node will be pruned by collapsing the data entries to another node.pruningCleanup(UniqueAddress removedNode) Remove data entries from a node that has been removed from the cluster and already been pruned.Reset collection of deltas from mutator operations.toString()static scala.Option<scala.math.BigInt>Extract theGCounter.value().scala.math.BigIntvalue()Scala API: Current total value of the counter.zero()The empty full state.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.pekko.cluster.ddata.DeltaReplicatedData
mergeDeltaMethods inherited from interface org.apache.pekko.cluster.ddata.ReplicatedData
merge
-
Method Details
-
empty
-
apply
-
create
Java API -
unapply
Extract theGCounter.value(). -
value
public scala.math.BigInt value()Scala API: Current total value of the counter. -
getValue
Java API: Current total value of the counter. -
$colon$plus
Increment the counter with the deltanspecified. If the delta is negative then it will decrement instead of increment. -
$colon$plus
Increment the counter with the deltanspecified. If the delta is negative then it will decrement instead of increment. -
increment
Scala API: Increment the counter with the deltanspecified. If the delta is negative then it will decrement instead of increment. -
increment
Increment the counter with the deltanspecified. If the delta is negative then it will decrement instead of increment. -
increment
Java API: Increment the counter with the deltanspecified. If the delta is negative then it will decrement instead of increment. -
increment
Java API: Increment the counter with the deltanspecified. If the delta is negative then it will decrement instead of increment. -
decrement
Decrement the counter with the deltanspecified. If the delta is negative then it will increment instead of decrement. -
decrement
Decrement the counter with the deltanspecified. If the delta is negative then it will increment instead of decrement. -
decrement
Decrement the counter with the deltanspecified. If the deltanis negative then it will increment instead of decrement. -
decrement
Scala API: Decrement the counter with the deltanspecified. If the deltanis negative then it will increment instead of decrement. -
decrement
Java API: Decrement the counter with the deltanspecified. If the deltanis negative then it will increment instead of decrement. -
merge
-
delta
Description copied from interface:DeltaReplicatedDataThe accumulated delta of mutator operations since previousDeltaReplicatedData.resetDelta(). When theReplicatorinvokes themodifyfunction of theUpdatemessage 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 theReplicatorwith theDeltaReplicatedData.delta()accessor. Themodifyfunction shall still return the full state in the same way asReplicatedDatawithout support for deltas.- Specified by:
deltain interfaceDeltaReplicatedData
-
mergeDelta
-
zero
Description copied from interface:ReplicatedDeltaThe 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 thezeroto create the initial full state.- Specified by:
zeroin interfaceReplicatedDelta
-
resetDelta
Description copied from interface:DeltaReplicatedDataReset collection of deltas from mutator operations. When theReplicatorinvokes themodifyfunction of theUpdatemessage 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 theReplicatorwith theDeltaReplicatedData.delta()accessor. When theReplicatorhas grabbed thedeltait will invoke this method to get a clean data instance without the delta.- Specified by:
resetDeltain interfaceDeltaReplicatedData
-
modifiedByNodes
Description copied from interface:RemovedNodePruningThe 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:
modifiedByNodesin interfaceRemovedNodePruning
-
needPruningFrom
Description copied from interface:RemovedNodePruningDoes it have any state changes from a specific node, which has been removed from the cluster.- Specified by:
needPruningFromin interfaceRemovedNodePruning
-
prune
Description copied from interface:RemovedNodePruningWhen theremovednode 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:
prunein interfaceRemovedNodePruning
-
pruningCleanup
Description copied from interface:RemovedNodePruningRemove data entries from a node that has been removed from the cluster and already been pruned.- Specified by:
pruningCleanupin interfaceRemovedNodePruning
-
toString
-
equals
-
hashCode
public int hashCode()
-