Class ReplicatorMessageAdapter<A,B extends ReplicatedData>
- java.lang.Object
-
- org.apache.pekko.cluster.ddata.typed.javadsl.ReplicatorMessageAdapter<A,B>
-
- Type Parameters:
A- Message type of the requesting actor.B- Type of theReplicatedData.
public class ReplicatorMessageAdapter<A,B extends ReplicatedData> extends java.lang.ObjectWhen interacting with theReplicatorfrom an actor this class provides convenient methods that adapts the response messages to the requesting actor's message protocol.One
ReplicatorMessageAdapterinstance can be used for a givenReplicatedDatatype, e.g. anOrSet. Interaction with severalKeys can be used via the same adapter but they must all be of the sameReplicatedDatatype. For interaction with several differentReplicatedDatatypes, e.g. anOrSetand aGCounter, an adapter can be created for each type.For the default replicator in the
DistributedDataextension aReplicatorMessageAdaptercan be created withDistributedData.withReplicatorMessageAdapter.*Warning*:
ReplicatorMessageAdapteris not thread-safe and must only be used from the actor corresponding to the givenActorContext. It must not be accessed from threads other than the ordinary actor message processing thread, such asCompletionStagecallbacks. It must not be shared between several actor instances.param: context The
pekko.actor.typed.javadsl.ActorContextof the requesting actor. TheReplicatorMessageAdaptercan only be used in this actor. param: replicator The replicator to interact with, typicallyDistributedData.get(system).replicator. param: unexpectedAskTimeout The timeout to use foraskoperations. This should be longer than thetimeoutgiven inReplicator.WriteConsistencyandReplicator.ReadConsistency. The replicator will always send a reply within those timeouts so theunexpectedAskTimeoutshould not occur, but for cleanup in a failure situation it must still exist. IfaskUpdate,askGetoraskDeletetakes longer then thisunexpectedAskTimeoutaTimeoutExceptionwill be thrown by the requesting actor and may be handled by supervision.
-
-
Constructor Summary
Constructors Constructor Description ReplicatorMessageAdapter(ActorContext<A> context, ActorRef<Replicator.Command> replicator, java.time.Duration unexpectedAskTimeout)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaskDelete(java.util.function.Function<ActorRef<Replicator.DeleteResponse<B>>,Replicator.Delete<B>> createRequest, java.util.function.Function<Replicator.DeleteResponse<B>,A> responseAdapter)Send aReplicator.Deleterequest to the replicator.voidaskGet(java.util.function.Function<ActorRef<Replicator.GetResponse<B>>,Replicator.Get<B>> createRequest, java.util.function.Function<Replicator.GetResponse<B>,A> responseAdapter)Send aReplicator.Getrequest to the replicator.voidaskReplicaCount(java.util.function.Function<ActorRef<Replicator.ReplicaCount>,Replicator.GetReplicaCount> createRequest, java.util.function.Function<Replicator.ReplicaCount,A> responseAdapter)Send aReplicator.GetReplicaCountrequest to the replicator.voidaskUpdate(java.util.function.Function<ActorRef<Replicator.UpdateResponse<B>>,Replicator.Update<B>> createRequest, java.util.function.Function<Replicator.UpdateResponse<B>,A> responseAdapter)Send aReplicator.Updaterequest to the replicator.voidsubscribe(Key<B> key, Function<Replicator.SubscribeResponse<B>,A> responseAdapter)Subscribe to changes of the givenkey.voidunsubscribe(Key<B> key)Unsubscribe from a previous subscription of a givenkey.
-
-
-
Constructor Detail
-
ReplicatorMessageAdapter
public ReplicatorMessageAdapter(ActorContext<A> context, ActorRef<Replicator.Command> replicator, java.time.Duration unexpectedAskTimeout)
-
-
Method Detail
-
askDelete
public void askDelete(java.util.function.Function<ActorRef<Replicator.DeleteResponse<B>>,Replicator.Delete<B>> createRequest, java.util.function.Function<Replicator.DeleteResponse<B>,A> responseAdapter)
Send aReplicator.Deleterequest to the replicator. TheReplicator.DeleteResponsemessage is transformed to the message protocol of the requesting actor with the givenresponseAdapterfunction.Note that
createRequestis a function that creates theDeletemessage from the providedActorRef[DeleteResponse]that the the replicator will send the response message back through. Use thatActorRef[DeleteResponse]as thereplyToparameter in theDeletemessage.
-
askGet
public void askGet(java.util.function.Function<ActorRef<Replicator.GetResponse<B>>,Replicator.Get<B>> createRequest, java.util.function.Function<Replicator.GetResponse<B>,A> responseAdapter)
Send aReplicator.Getrequest to the replicator. TheReplicator.GetResponsemessage is transformed to the message protocol of the requesting actor with the givenresponseAdapterfunction.Note that
createRequestis a function that creates theGetmessage from the providedActorRef[GetResponse]that the the replicator will send the response message back through. Use thatActorRef[GetResponse]as thereplyToparameter in theGetmessage.
-
askReplicaCount
public void askReplicaCount(java.util.function.Function<ActorRef<Replicator.ReplicaCount>,Replicator.GetReplicaCount> createRequest, java.util.function.Function<Replicator.ReplicaCount,A> responseAdapter)
Send aReplicator.GetReplicaCountrequest to the replicator. TheReplicator.ReplicaCountmessage is transformed to the message protocol of the requesting actor with the givenresponseAdapterfunction.Note that
createRequestis a function that creates theGetReplicaCountmessage from the providedActorRef[ReplicaCount]that the the replicator will send the response message back through. Use thatActorRef[ReplicaCount]as thereplyToparameter in theGetReplicaCountmessage.
-
askUpdate
public void askUpdate(java.util.function.Function<ActorRef<Replicator.UpdateResponse<B>>,Replicator.Update<B>> createRequest, java.util.function.Function<Replicator.UpdateResponse<B>,A> responseAdapter)
Send aReplicator.Updaterequest to the replicator. TheReplicator.UpdateResponsemessage is transformed to the message protocol of the requesting actor with the givenresponseAdapterfunction.Note that
createRequestis a function that creates theUpdatemessage from the providedActorRef[UpdateResponse]that the the replicator will send the response message back through. Use thatActorRef[UpdateResponse]as thereplyToparameter in theUpdatemessage.
-
subscribe
public void subscribe(Key<B> key, Function<Replicator.SubscribeResponse<B>,A> responseAdapter)
Subscribe to changes of the givenkey. TheReplicator.ChangedandReplicator.Deletedmessages from the replicator are transformed to the message protocol of the requesting actor with the givenresponseAdapterfunction.
-
-