Package org.apache.pekko.cluster.ddata
Class PNCounter
- java.lang.Object
-
- org.apache.pekko.cluster.ddata.PNCounter
-
- All Implemented Interfaces:
java.io.Serializable,DeltaReplicatedData,RemovedNodePruning,ReplicatedData,ReplicatedDataSerialization,ReplicatedDelta
public final class PNCounter extends java.lang.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:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description PNCounter$colon$plus(long n, SelfUniqueAddress node)Increment the counter with the deltanspecified.PNCounter$colon$plus(scala.math.BigInt n, SelfUniqueAddress node)Increment the counter with the deltanspecified.PNCounter$minus(long n, Cluster node)Deprecated.Use `decrement` that takes a `SelfUniqueAddress` parameter instead.PNCounter$minus(scala.math.BigInt n, Cluster node)Deprecated.Use `decrement` that takes a `SelfUniqueAddress` parameter instead.PNCounter$plus(long n, Cluster node)Deprecated.Use `:+` that takes a `SelfUniqueAddress` parameter instead.PNCounter$plus(scala.math.BigInt n, Cluster node)Deprecated.Use `:+` that takes a `SelfUniqueAddress` parameter instead.static PNCounterapply()static PNCountercreate()Java APIPNCounterdecrement(long n, SelfUniqueAddress node)Decrement the counter with the deltanspecified.PNCounterdecrement(Cluster node, long n)Deprecated.Use `decrement` that takes a `SelfUniqueAddress` parameter instead.PNCounterdecrement(Cluster node, java.math.BigInteger n)Deprecated.Use `decrement` that takes a `SelfUniqueAddress` parameter instead.PNCounterdecrement(Cluster node, scala.math.BigInt n)Deprecated.Use `decrement` that takes a `SelfUniqueAddress` parameter instead.PNCounterdecrement(SelfUniqueAddress node, long n)Decrement the counter with the deltanspecified.PNCounterdecrement(SelfUniqueAddress node, java.math.BigInteger n)Java API: Decrement the counter with the deltanspecified.PNCounterdecrement(SelfUniqueAddress node, scala.math.BigInt n)Scala API: Decrement the counter with the deltanspecified.PNCounterdecrement(scala.math.BigInt n, SelfUniqueAddress node)Decrement the counter with the deltanspecified.longdecrement$default$2()scala.Option<PNCounter>delta()The accumulated delta of mutator operations since previousDeltaReplicatedData.resetDelta().static PNCounterempty()booleanequals(java.lang.Object o)java.math.BigIntegergetValue()Java API: Current total value of the counter.inthashCode()PNCounterincrement(long n, SelfUniqueAddress node)Scala API: Increment the counter with the deltanspecified.PNCounterincrement(Cluster node, long n)Deprecated.Use `increment` that takes a `SelfUniqueAddress` parameter instead.PNCounterincrement(Cluster node, java.math.BigInteger n)Deprecated.Use `increment` that takes a `SelfUniqueAddress` parameter instead.PNCounterincrement(Cluster node, scala.math.BigInt n)Deprecated.Use `increment` that takes a `SelfUniqueAddress` parameter instead.PNCounterincrement(SelfUniqueAddress node, long n)Java API: Increment the counter with the deltanspecified.PNCounterincrement(SelfUniqueAddress node, java.math.BigInteger n)Java API: Increment the counter with the deltanspecified.PNCounterincrement(scala.math.BigInt n, SelfUniqueAddress node)Increment the counter with the deltanspecified.longincrement$default$2()PNCountermerge(PNCounter that)PNCountermergeDelta(PNCounter thatDelta)scala.collection.immutable.Set<UniqueAddress>modifiedByNodes()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.PNCounterprune(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.PNCounterpruningCleanup(UniqueAddress removedNode)Remove data entries from a node that has been removed from the cluster and already been pruned.PNCounterresetDelta()Reset collection of deltas from mutator operations.java.lang.StringtoString()static scala.Option<scala.math.BigInt>unapply(PNCounter c)Extract theGCounter.value().scala.math.BigIntvalue()Scala API: Current total value of the counter.PNCounterzero()The empty full state.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.pekko.cluster.ddata.DeltaReplicatedData
mergeDelta
-
Methods inherited from interface org.apache.pekko.cluster.ddata.ReplicatedData
merge
-
-
-
-
Method Detail
-
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 theGCounter.value().
-
value
public scala.math.BigInt value()
Scala API: Current total value of the counter.
-
getValue
public java.math.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 deltanspecified. If the delta is negative then it will decrement instead of increment.
-
$plus
public PNCounter $plus(long n, Cluster node)
Deprecated.Use `:+` that takes a `SelfUniqueAddress` parameter instead. Since Akka 2.5.20.
-
$colon$plus
public PNCounter $colon$plus(scala.math.BigInt n, SelfUniqueAddress node)
Increment the counter with the deltanspecified. If the delta is negative then it will decrement instead of increment.
-
$plus
public PNCounter $plus(scala.math.BigInt n, Cluster node)
Deprecated.Use `:+` that takes a `SelfUniqueAddress` parameter instead. Since Akka 2.5.20.
-
increment
public PNCounter increment(long n, SelfUniqueAddress node)
Scala API: Increment the counter with the deltanspecified. If the delta is negative then it will decrement instead of increment.
-
increment
public PNCounter increment(Cluster node, long n)
Deprecated.Use `increment` that takes a `SelfUniqueAddress` parameter instead. Since Akka 2.5.20.
-
increment
public PNCounter increment(scala.math.BigInt n, SelfUniqueAddress node)
Increment the counter with the deltanspecified. If the delta is negative then it will decrement instead of increment.
-
increment
public PNCounter increment(Cluster node, scala.math.BigInt n)
Deprecated.Use `increment` that takes a `SelfUniqueAddress` parameter instead. Since Akka 2.5.20.
-
increment
public PNCounter increment(SelfUniqueAddress node, java.math.BigInteger n)
Java API: Increment the counter with the deltanspecified. 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 deltanspecified. If the delta is negative then it will decrement instead of increment.
-
increment
public PNCounter increment(Cluster node, java.math.BigInteger n)
Deprecated.Use `increment` that takes a `SelfUniqueAddress` parameter instead. Since Akka 2.5.20.
-
decrement
public PNCounter decrement(long n, SelfUniqueAddress node)
Decrement the counter with the deltanspecified. If the delta is negative then it will increment instead of decrement.
-
$minus
public PNCounter $minus(long n, Cluster node)
Deprecated.Use `decrement` that takes a `SelfUniqueAddress` parameter instead. Since Akka 2.5.20.
-
decrement
public PNCounter decrement(scala.math.BigInt n, SelfUniqueAddress node)
Decrement the counter with the deltanspecified. If the delta is negative then it will increment instead of decrement.
-
$minus
public PNCounter $minus(scala.math.BigInt n, Cluster node)
Deprecated.Use `decrement` that takes a `SelfUniqueAddress` parameter instead. Since Akka 2.5.20.
-
decrement
public PNCounter decrement(SelfUniqueAddress node, long n)
Decrement the counter with the deltanspecified. If the deltanis negative then it will increment instead of decrement.
-
decrement
public PNCounter decrement(Cluster node, long n)
Deprecated.Use `decrement` that takes a `SelfUniqueAddress` parameter instead. Since Akka 2.5.20.
-
decrement
public PNCounter decrement(SelfUniqueAddress node, scala.math.BigInt n)
Scala API: Decrement the counter with the deltanspecified. If the deltanis negative then it will increment instead of decrement.
-
decrement
public PNCounter decrement(Cluster node, scala.math.BigInt n)
Deprecated.Use `decrement` that takes a `SelfUniqueAddress` parameter instead. Since Akka 2.5.20.
-
decrement
public PNCounter decrement(SelfUniqueAddress node, java.math.BigInteger n)
Java API: Decrement the counter with the deltanspecified. If the deltanis negative then it will increment instead of decrement.
-
decrement
public PNCounter decrement(Cluster node, java.math.BigInteger n)
Deprecated.Use `decrement` that takes a `SelfUniqueAddress` parameter instead. Since Akka 2.5.20.
-
increment$default$2
public long increment$default$2()
-
decrement$default$2
public long decrement$default$2()
-
delta
public scala.Option<PNCounter> 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
-
zero
public PNCounter 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
public PNCounter 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
public scala.collection.immutable.Set<UniqueAddress> 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
public boolean needPruningFrom(UniqueAddress removedNode)
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
public PNCounter prune(UniqueAddress removedNode, UniqueAddress collapseInto)
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
public PNCounter pruningCleanup(UniqueAddress removedNode)
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
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-