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

Class OpCounter

  • All Implemented Interfaces:
    GenericCRDT, OperationCRDT


    public class OpCounter
    extends OperationBasedCRDT
    An operation-based 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).
    • Field Detail

      • serializer

        public static pt.unl.fct.di.novasys.network.ISerializer<OpCounter> serializer
        A serializer that serializes the CRDT into (and from) a ByteBuf.
    • Constructor Detail

      • OpCounter

        public OpCounter()
        Creates a operation-based counter. The counter is initialized to zero.
      • OpCounter

        public OpCounter(int value)
        Creates a operation-based counter. The counter is initialized to the passed value.
        Parameters:
        value - the initial value of the counter
      • OpCounter

        public OpCounter(String crdtID)
        Creates a operation-based counter by passing the CRDT identifier. The counter is initialized to zero.
        Parameters:
        crdtID - the CRDT identifier.
      • OpCounter

        public OpCounter(String crdtID,
                         int value)
        Creates a operation-based counter by passing the CRDT identifier and a initialization value.
        Parameters:
        crdtID - the CRDT indentifier
        value - 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 CounterOperation increment(int amount)
        Increments the value of the counter, and returns an operation to be propagated to other replicas.
        Parameters:
        amount - amount to be incremented
        Returns:
        a CounterOperation that stores the type of operation, value and the CRDT identifer.
      • decrement

        public CounterOperation decrement(int amount)
        Decrements the value of the counter, and returns an operation to be propagated to other replicas.
        Parameters:
        amount - amount to be decremented
        Returns:
        a CounterOperation that stores the type of operation, value and the CRDT identifer.
      • 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.