pt.unl.fct.di.novasys.babel.crdts.delta.implementations

Class DeltaPNCounter

  • All Implemented Interfaces:
    DeltaCRDT, GenericCRDT


    public class DeltaPNCounter
    extends DeltaBasedCRDT
    A delta-based PN counter CRDT. It enables the increment and decrement of the value and doesn't impose any restrictions into the possible values (unlike a B-Counter). The CRDT has two distinct collections for storing the increments and decrements.
    • Constructor Detail

      • DeltaPNCounter

        public DeltaPNCounter(ReplicaID replicaID)
        Creates a delta-based counter by passing the replica identifier. The counter is initialized to zero.
        Parameters:
        replicaID - replica identifier
      • DeltaPNCounter

        public DeltaPNCounter(VVState state)
        Creates a delta-based counter by passing the current replica state. The counter is initialized to zero.
        Parameters:
        state - replica state
      • DeltaPNCounter

        public DeltaPNCounter(ReplicaID replicaID,
                              int initialValue)
        Creates a delta-based counter by passing the replica identifier. The counter is initialized to the passed value.
        Parameters:
        replicaID - replica identifier
        initialValue - the initial value of the counter
      • DeltaPNCounter

        public DeltaPNCounter(VVState state,
                              int initialValue)
        Creates a delta-based counter by passing the current replica state. The is initialized to the passed value.
        Parameters:
        state - replica state
        initialValue - the initial value of the counter
    • Method Detail

      • copy

        public GenericCRDT copy()
        Description copied from interface: GenericCRDT
        Creates a copy of the CRDT. Modifications on the copy don't modify the original.
        Returns:
        a copy of the CRDT
      • value

        public int value()
        Gets the value of the counter
        Returns:
        the value of the counter
      • increment

        public DeltaPNCounter increment(int amount)
        Increments the value of the counter and returns a delta representing the operation.
        Parameters:
        amount - the amount to increment
        Returns:
        a delta representing the operation
      • decrement

        public DeltaPNCounter decrement(int amount)
        Decrements the value of the counter and returns a delta representing the operation.
        Parameters:
        amount - the amount to decrement
        Returns:
        a delta representing the operation
      • serialize

        public void serialize(io.netty.buffer.ByteBuf in)
                       throws IOException
        Description copied from interface: GenericCRDT
        Serializes the CRDT into a ByteBuf
        Parameters:
        in - ByteBuf to serialize the CRDT to
        Throws:
        IOException - if an error occurs while serializing

Copyright © 2024. All rights reserved.