Class ReplicatorMessageAdapter<A,B extends ReplicatedData>
- Type Parameters:
A- Message type of the requesting actor.B- Type of theReplicatedData.
Replicator from an actor this class provides convenient
methods that adapts the response messages to the requesting actor's message protocol.
One ReplicatorMessageAdapter instance can be used for a given ReplicatedData type,
e.g. an OrSet. Interaction with several Keys can be used via the same adapter
but they must all be of the same ReplicatedData type. For interaction with several different
ReplicatedData types, e.g. an OrSet and a GCounter, an adapter can be created
for each type.
For the default replicator in the DistributedData extension a ReplicatorMessageAdapter
can be created with DistributedData.withReplicatorMessageAdapter.
*Warning*: ReplicatorMessageAdapter is not thread-safe and must only be used from the actor
corresponding to the given ActorContext. It must not be accessed from threads other
than the ordinary actor message processing thread, such as CompletionStage
callbacks. It must not be shared between several actor instances.
param: context The pekko.actor.typed.javadsl.ActorContext of the requesting actor. The ReplicatorMessageAdapter can
only be used in this actor.
param: replicator The replicator to interact with, typically DistributedData.get(system).replicator.
param: unexpectedAskTimeout The timeout to use for ask operations. This should be longer than
the timeout given in Replicator.WriteConsistency and
Replicator.ReadConsistency. The replicator will always send
a reply within those timeouts so the unexpectedAskTimeout should
not occur, but for cleanup in a failure situation it must still exist.
If askUpdate, askGet or askDelete takes longer then this
unexpectedAskTimeout a TimeoutException
will be thrown by the requesting actor and may be handled by supervision.
-
Constructor Summary
ConstructorsConstructorDescriptionReplicatorMessageAdapter(ActorContext<A> context, ActorRef<Replicator.Command> replicator, Duration unexpectedAskTimeout) -
Method Summary
Modifier and TypeMethodDescriptionvoidaskDelete(Function<ActorRef<Replicator.DeleteResponse<B>>, Replicator.Delete<B>> createRequest, Function<Replicator.DeleteResponse<B>, A> responseAdapter) Send aReplicator.Deleterequest to the replicator.voidaskGet(Function<ActorRef<Replicator.GetResponse<B>>, Replicator.Get<B>> createRequest, Function<Replicator.GetResponse<B>, A> responseAdapter) Send aReplicator.Getrequest to the replicator.voidaskReplicaCount(Function<ActorRef<Replicator.ReplicaCount>, Replicator.GetReplicaCount> createRequest, Function<Replicator.ReplicaCount, A> responseAdapter) Send aReplicator.GetReplicaCountrequest to the replicator.voidaskUpdate(Function<ActorRef<Replicator.UpdateResponse<B>>, Replicator.Update<B>> createRequest, Function<Replicator.UpdateResponse<B>, A> responseAdapter) Send aReplicator.Updaterequest to the replicator.voidSubscribe to changes of the givenkey.voidunsubscribe(Key<B> key) Unsubscribe from a previous subscription of a givenkey.
-
Constructor Details
-
ReplicatorMessageAdapter
public ReplicatorMessageAdapter(ActorContext<A> context, ActorRef<Replicator.Command> replicator, Duration unexpectedAskTimeout)
-
-
Method Details
-
askDelete
public void askDelete(Function<ActorRef<Replicator.DeleteResponse<B>>, Replicator.Delete<B>> createRequest, 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(Function<ActorRef<Replicator.GetResponse<B>>, Replicator.Get<B>> createRequest, 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(Function<ActorRef<Replicator.ReplicaCount>, Replicator.GetReplicaCount> createRequest, 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(Function<ActorRef<Replicator.UpdateResponse<B>>, Replicator.Update<B>> createRequest, 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
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. -
unsubscribe
Unsubscribe from a previous subscription of a givenkey.- See Also:
-
ReplicatorMessageAdapter.subscribe
-