Interface DeltaCounter

All Superinterfaces:
Count, DeltaCount, GCount, GCounter, PNCount, PNCounter
All Known Implementing Classes:
StateBasedPNDeltaCounter

@NotThreadSafe public interface DeltaCounter extends PNCounter, DeltaCount
A simple counter that maintains a single changing value by separately tracking the positive and negative changes, and by tracking recent changes in this value since last reset. 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

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

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

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

      void reset()
      Start a new interval and reset the DeltaCount.getChanges() to initial values.