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[String]. 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[String] 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 Future callbacks.
It must not be shared between several actor instances.
param: context The pekko.actor.typed.scaladsl.ActorContext of the requesting actor. The ReplicatorMessageAdapter can
only be used in this actor.
param: replicator The replicator to interact with, typically DistributedData(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, scala.concurrent.duration.FiniteDuration unexpectedAskTimeout) -
Method Summary
Modifier and TypeMethodDescriptionstatic <A,B extends ReplicatedData>
ReplicatorMessageAdapter<A,B> apply(ActorContext<A> context, ActorRef<Replicator.Command> replicator, scala.concurrent.duration.FiniteDuration unexpectedAskTimeout) voidaskDelete(scala.Function1<ActorRef<Replicator.DeleteResponse<B>>, Replicator.Delete<B>> createRequest, scala.Function1<Replicator.DeleteResponse<B>, A> responseAdapter) Send aReplicator.Deleterequest to the replicator.voidaskGet(scala.Function1<ActorRef<Replicator.GetResponse<B>>, Replicator.Get<B>> createRequest, scala.Function1<Replicator.GetResponse<B>, A> responseAdapter) Send aReplicator.Getrequest to the replicator.voidaskReplicaCount(scala.Function1<ActorRef<Replicator.ReplicaCount>, Replicator.GetReplicaCount> createRequest, scala.Function1<Replicator.ReplicaCount, A> responseAdapter) Send aReplicator.GetReplicaCountrequest to the replicator.voidaskUpdate(scala.Function1<ActorRef<Replicator.UpdateResponse<B>>, Replicator.Update<B>> createRequest, scala.Function1<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, scala.concurrent.duration.FiniteDuration unexpectedAskTimeout)
-
-
Method Details
-
apply
public static <A,B extends ReplicatedData> ReplicatorMessageAdapter<A,B> apply(ActorContext<A> context, ActorRef<Replicator.Command> replicator, scala.concurrent.duration.FiniteDuration unexpectedAskTimeout) -
subscribe
public void subscribe(Key<B> key, scala.Function1<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. -
unsubscribe
Unsubscribe from a previous subscription of a givenkey.- See Also:
-
ReplicatorMessageAdapter.subscribe
-
askUpdate
public void askUpdate(scala.Function1<ActorRef<Replicator.UpdateResponse<B>>, Replicator.Update<B>> createRequest, scala.Function1<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. -
askGet
public void askGet(scala.Function1<ActorRef<Replicator.GetResponse<B>>, Replicator.Get<B>> createRequest, scala.Function1<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. -
askDelete
public void askDelete(scala.Function1<ActorRef<Replicator.DeleteResponse<B>>, Replicator.Delete<B>> createRequest, scala.Function1<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. -
askReplicaCount
public void askReplicaCount(scala.Function1<ActorRef<Replicator.ReplicaCount>, Replicator.GetReplicaCount> createRequest, scala.Function1<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.
-