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

Class StatePNCounter

  • All Implemented Interfaces:
    GenericCRDT, StateCRDT


    public class StatePNCounter
    extends StateBasedCRDT
    A delta-based PN counter CRDT. The CRDT has two distinct collections for storing the increments and decrements.
    • Constructor Detail

      • StatePNCounter

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

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

        public StatePNCounter(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
      • StatePNCounter

        public StatePNCounter(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 void increment(int amount)
        Increments the value of the counter.
        Parameters:
        amount - amount to be incremented
      • decrement

        public void decrement(int amount)
        Decrements the value of the counter.
        Parameters:
        amount - amount to be incremented
      • merge

        public StateBasedCRDT merge(StateBasedCRDT crdt)
        Description copied from interface: StateCRDT
        Handles the merging of this CRDT with other state-based CRDT received from the network. Only the local replica CRDT is updated
        Specified by:
        merge in interface StateCRDT
        Specified by:
        merge in class StateBasedCRDT
        Parameters:
        crdt - the CRDT to merge
        Returns:
        the newly merged CRDT
      • 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.