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

Class DeltaCRDTLWWMap

  • All Implemented Interfaces:
    DeltaCRDT, GenericCRDT


    public class DeltaCRDTLWWMap
    extends DeltaBasedCRDT
    A delta-based map with a last-writer-wins policy (LWW) for storing generic CRDTS. The key represents a pair (crdtType,String) and the value as a CRDT of that type. This map is also implemented as a generic CRDT, thus enabling a map of maps of CRDTs (and so forth). The generateDelta method contains the following semantics: all of the entries of the map that correspond to a delta-based CRDT are included in the delta, while the others are excluded. It provides methods to put and get for elements. Additionally, it is possible to iterate over the different elements of the map. It is not possible to delete elements from this map (this functionality is provided in DeltaORMap).
    • Field Detail

      • serializer

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

      • DeltaCRDTLWWMap

        public DeltaCRDTLWWMap(ReplicaID replicaID)
      • DeltaCRDTLWWMap

        public DeltaCRDTLWWMap(VVState state)
    • Method Detail

      • put

        public DeltaCRDTLWWMap put(CRDTTypeKeyPair key,
                                   GenericCRDT crdt)
        Puts a CRDT into the map, with a given key. The CRDT is only updated if it doesn't exist, or if the timestamp associated with the previous value is older than the current one.
        Parameters:
        key - key of the value
        crdt - CRDT to be inserted
        Returns:
        a delta representing the operation in question
      • get

        public GenericCRDT get(CRDTTypeKeyPair key)
        Gets the CRDT associated with the given key.
        Parameters:
        key - key to be searched
        Returns:
        the CRDT associated with the key or null if it doesn't exist.
      • 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
      • 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
      • generateDelta

        public DeltaCRDTLWWMap generateDelta(VersionVector vv)
        Calculates a delta from a given version for the current state. Since the map supports different CRDT types, the delta is generated for all entries.
        Specified by:
        generateDelta in interface DeltaCRDT
        Specified by:
        generateDelta in class DeltaBasedCRDT
        Parameters:
        vv - a version version to calculate the delta from
        Returns:
        a delta for the current state
      • generateDelta

        public DeltaCRDTLWWMap generateDelta(VersionVector vv,
                                             CRDTsTypes.FLAVOR flavor)
        Calculates a delta from a given version for the current state. This method only generates the delta for the CRDTs flavor passed as argument (i.e., operation, state or delta)
        Parameters:
        vv - a version version to calculate the delta from
        flavor - types of CRDTs to take in account while creating the delta
        Returns:
        a delta for the current state
      • mergeDelta

        public DeltaCRDTLWWMap mergeDelta(DeltaBasedCRDT crdt)
        Applies a delta to the current state. This method is analogous to a merge of states. A merge is only done per entry of the map, and not accounting the inner state of each CRDT (thus being oblivion of the flavor of CRDT being used).
        Specified by:
        mergeDelta in interface DeltaCRDT
        Specified by:
        mergeDelta in class DeltaBasedCRDT
        Parameters:
        crdt - a crdt representing the delta
        Returns:
        the current state
        Throws:
        CRDTNotValidException - if the crdt passed as argument is invalid

Copyright © 2024. All rights reserved.