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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classDistributedData.AbstractDDataProvider<R extends org.apache.pekko.cluster.ddata.ReplicatedData,T extends DistributedData<R>> Extension provider for Ditto distributed data. -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDistributedData(DistributedDataConfig config, org.apache.pekko.actor.ActorRefFactory factory, Executor ddataExecutor) Create a wrapper of distributed data replicator. -
Method Summary
Modifier and TypeMethodDescriptionstatic DistributedDataConfigcreateConfig(org.apache.pekko.actor.ActorSystem actorSystem, CharSequence replicatorName, CharSequence replicatorRole) Create a distributed data config with Pekko's default options.get(org.apache.pekko.cluster.ddata.Key<R> key, org.apache.pekko.cluster.ddata.Replicator.ReadConsistency readConsistency) Asynchronously retrieves the replicated data.Get the config of this distributed data.protected abstract Rprotected abstract org.apache.pekko.cluster.ddata.Key<R> getKey(int shardNumber) Creates/gets a key for the passedshardNumber.org.apache.pekko.actor.ActorRefvoidsubscribeForChanges(org.apache.pekko.actor.ActorRef subscriber) Request updates when the distributed data changes.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.
-
Field Details
-
readTimeout
Default timeout of read operations. -
writeTimeout
Default timeout of write operations. -
replicator
protected final org.apache.pekko.actor.ActorRef replicatorReference 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- ifconfigReaderisnull.
-
-
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 isnull.
-
getKey
Creates/gets a key for the passedshardNumber.- 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
- 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
Get the config of this distributed data.- Returns:
- The config.
- Since:
- 3.0.0
-