BCounter

class BCounter : DeltaCRDT

A delta-based CRDT bounded-counter (non-negative, initially 0).

Following design from V. Balegas et al., "Extending Eventually Consistent Cloud Databases for Enforcing Numeric Invariants," 2015 IEEE 34th Symposium on Reliable Distributed Systems (SRDS), Montreal, QC, 2015, pp. 31-36, doi: 10.1109/SRDS.2015.32.

Its JSON serialization respects the following schema:

{
"type": "BCounter",
"metadata": {
"increment": [
({ClientUId.toJson()}, [
(( ClientUId.toJson(), {
"first": $value, // $value is an integer
"second": Timestamp.toJson()
}, )*( ClientUId.toJson(), {
"first": $value, // $value is an integer
"second": Timestamp.toJson()
} ))?
])?
],
"decrement": [
({ ClientUId.toJson(), {
"first": $value, // $value is an integer
"second": Timestamp.toJson()
}, )*( ClientUId.toJson(), {
"first": $value, // $value is an integer
"second": Timestamp.toJson()
} })?
]
},
"value": $value // $value is an integer
}

Constructors

BCounter
Link copied to clipboard
common
fun BCounter()
Default constructor.
BCounter
Link copied to clipboard
common
fun BCounter(env: Environment)

Types

Companion
Link copied to clipboard
common
object Companion

Functions

decrement
Link copied to clipboard
common
fun decrement(amount: Int): BCounter
Decrements the counter by the given amount.
equals
Link copied to clipboard
common
open operator fun equals(other: Any?): Boolean
generateDelta
Link copied to clipboard
common
open override fun generateDelta(vv: VersionVector): BCounter
Return a delta from a given version vector vv to current state.
get
Link copied to clipboard
common
fun get(): Int
Gets the value of the counter.
hashCode
Link copied to clipboard
common
open fun hashCode(): Int
increment
Link copied to clipboard
common
fun increment(amount: Int): BCounter
Increments the counter by the given amount.
localRights
Link copied to clipboard
common
fun localRights(uid: ClientUId): Int
Gets the local rights of the counter.
merge
Link copied to clipboard
common
open override fun merge(delta: DeltaCRDT)
Merge a given delta into this DeltaCRDTThe merge is unidirectional: only the local replica is modified.
toJson
Link copied to clipboard
common
open override fun toJson(): String
Serialize this DeltaCRDT to a JSON string.
toString
Link copied to clipboard
common
open fun toString(): String
transfer
Link copied to clipboard
common
fun transfer(amount: Int, to: ClientUId): BCounter
Transfers a given amount of rights from the local replica to some otherThrow IllegalArgumentException if localRights are not sufficient.