Interface PNCounter

All Superinterfaces:
Count, GCount, GCounter, PNCount
All Known Subinterfaces:
DeltaCounter
All Known Implementing Classes:
StateBasedPNCounter, StateBasedPNDeltaCounter

@NotThreadSafe public interface PNCounter extends PNCount, GCounter
A simple counter that maintains a single changing value by separately tracking the positive and negative changes. It is inspired by the conflict-free replicated data type (CRDT) P-N Counter. The semantics ensure the value converges toward the global number of increments minus the number of decrements. The global total can be calculated by merging all the replicated instances, without regard to order of merging.
  • Method Details

    • increment

      PNCounter increment()
      Increment the counter and get the result.
      Specified by:
      increment in interface GCounter
      Returns:
      this instance so methods can be chained together; never null
    • decrement

      PNCounter decrement()
      Decrement the counter and get the result.
      Returns:
      this instance so methods can be chained together; never null
    • decrementAndGet

      long decrementAndGet()
      Decrement the counter and get the result.
      Returns:
      the current result after decrementing
    • getAndDecrement

      long getAndDecrement()
      Decrement the counter and get the result.
      Returns:
      the current result before decrementing
    • merge

      PNCounter merge(Count other)
      Merge the supplied counter into this counter.
      Specified by:
      merge in interface GCounter
      Parameters:
      other - the other counter to merge into this one; may be null
      Returns:
      this counter so that methods can be chained