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

Class DeltaLWWMap

  • All Implemented Interfaces:
    DeltaCRDT, GenericCRDT


    public class DeltaLWWMap
    extends DeltaBasedCRDT
    A delta-based map with a last-writer-wins policy (LWW). The map supports generic types implemented as SerializableTypes. It provides methods to put, delete and get for elements. Additionally, it is possible to iterate over the different elements of the map.
    • Field Detail

      • serializer

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

      • DeltaLWWMap

        public DeltaLWWMap(ReplicaID replicaID)
        Creates a delta last-writer-wins map with a given replicaID.
        Parameters:
        replicaID - the replica identifier
      • DeltaLWWMap

        public DeltaLWWMap(VVState state)
        Creates a delta last-writer-wins map with a given replica state.
        Parameters:
        state - replica current state
      • DeltaLWWMap

        public DeltaLWWMap(ReplicaID replicaID,
                           Map<String,SerializableType> initialValues)
        Creates a delta last-writer-wins map with a given replicaID and a map of initial values.
        Parameters:
        replicaID - the replica identifier
        initialValues - a map of initial values for the CRDT
      • DeltaLWWMap

        public DeltaLWWMap(VVState state,
                           Map<String,SerializableType> initialValues)
        Creates a delta last-writer-wins map with a given replica state and a map of initial valeus.
        Parameters:
        state - replica current state
        initialValues - a map of initial values for the CRDT
    • 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
      • put

        public DeltaLWWMap put(String key,
                               SerializableType value)
        Puts a value into the map, with a given key. The value 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
        value - element to be inserted
        Returns:
        a delta representing the operation in question
      • get

        public SerializableType get(String key)
        Gets the element associated with the given key.
        Parameters:
        key - key to be searched
        Returns:
        the value associated with the key or null if it doesn't exist.
      • delete

        public DeltaLWWMap delete(String key)
        Deletes the value associated with key. The value is deleted by associating a null value to the given key.
        Parameters:
        key - key to be deleted
        Returns:
        a delta representing the operation in question
      • 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.