Class DistributedData<R extends org.apache.pekko.cluster.ddata.ReplicatedData>

java.lang.Object
org.eclipse.ditto.internal.utils.ddata.DistributedData<R>
Type Parameters:
R - type of replicated data.
All Implemented Interfaces:
org.apache.pekko.actor.Extension

public abstract class DistributedData<R extends org.apache.pekko.cluster.ddata.ReplicatedData> extends Object implements org.apache.pekko.actor.Extension
Supertype of typed interfaces for distributed data. Each instance corresponds to one distributed data object. Each instance starts its own replicator so that it can have its own configuration regarding e. g. roles of cluster members to which the data gets replicated.
  • Field Details

    • readTimeout

      protected final Duration readTimeout
      Default timeout of read operations.
    • writeTimeout

      protected final Duration writeTimeout
      Default timeout of write operations.
    • replicator

      protected final org.apache.pekko.actor.ActorRef replicator
      Reference of the distributed data replicator.
    • numberOfShards

      protected final int numberOfShards
  • Constructor Details

    • DistributedData

      protected DistributedData(DistributedDataConfig config, org.apache.pekko.actor.ActorRefFactory factory, Executor ddataExecutor)
      Create a wrapper of distributed data replicator.
      Parameters:
      config - specific config for this replicator.
      factory - creator of this replicator.
      Throws:
      NullPointerException - if configReader is null.
  • Method Details

    • createConfig

      public static DistributedDataConfig createConfig(org.apache.pekko.actor.ActorSystem actorSystem, CharSequence replicatorName, CharSequence replicatorRole)
      Create a distributed data config with Pekko's default options.
      Parameters:
      replicatorName - the name of the replicator.
      replicatorRole - the cluster role of members with replicas of the distributed collection.
      Returns:
      a new config object.
      Throws:
      NullPointerException - if any argument is null.
    • getKey

      protected abstract org.apache.pekko.cluster.ddata.Key<R> getKey(int shardNumber)
      Creates/gets a key for the passed shardNumber.
      Parameters:
      shardNumber - the number of the shard to append to the key.
      Returns:
      key of the distributed collection. Should be unique among collections of the same type.
    • getInitialValue

      protected abstract R getInitialValue()
      Returns:
      initial value of the distributed data.
    • get

      public CompletionStage<Optional<R>> get(org.apache.pekko.cluster.ddata.Key<R> key, org.apache.pekko.cluster.ddata.Replicator.ReadConsistency readConsistency)
      Asynchronously retrieves the replicated data.
      Parameters:
      key - the key to get the replicated data for.
      readConsistency - how many replicas to consult.
      Returns:
      future of the replicated data that completes exceptionally on error.
    • update

      public CompletionStage<Void> update(org.apache.pekko.cluster.ddata.Key<R> key, org.apache.pekko.cluster.ddata.Replicator.WriteConsistency writeConsistency, Function<R,R> updateFunction)
      Modify the replicated data.
      Parameters:
      key - the key to update.
      writeConsistency - how many replicas to update.
      updateFunction - what to do to the replicas.
      Returns:
      future that completes when the update completes, exceptionally when any error is encountered.
    • subscribeForChanges

      public void subscribeForChanges(org.apache.pekko.actor.ActorRef subscriber)
      Request updates when the distributed data changes.
      Parameters:
      subscriber - whom to notify of changes.
    • getReplicator

      public org.apache.pekko.actor.ActorRef getReplicator()
      Returns:
      reference to the distributed data replicator.
    • getConfig

      public DistributedDataConfig getConfig()
      Get the config of this distributed data.
      Returns:
      The config.
      Since:
      3.0.0