Class ReplicatorMessageAdapter<A,B extends ReplicatedData>
- java.lang.Object
-
- akka.cluster.ddata.typed.scaladsl.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[String]. 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. anOrSet[String]and 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 asFuturecallbacks. It must not be shared between several actor instances.param: context The
ActorContextof the requesting actor. TheReplicatorMessageAdaptercan only be used in this actor. param: replicator The replicator to interact with, typicallyDistributedData(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, scala.concurrent.duration.FiniteDuration unexpectedAskTimeout)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <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(Key<B> key, scala.Function1<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, scala.concurrent.duration.FiniteDuration unexpectedAskTimeout)
-
-
Method Detail
-
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.Changed,Replicator.DeletedandReplicator.Expiredmessages from the replicator are transformed to the message protocol of the requesting actor with the givenresponseAdapterfunction.
-
unsubscribe
public void unsubscribe(Key<B> key)
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.
-
-