Class ReplicatorMessageAdapter<A,B extends ReplicatedData>
- java.lang.Object
-
- akka.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.Object
When interacting with theReplicator
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 givenReplicatedData
type, e.g. anOrSet
. Interaction with severalKey
s can be used via the same adapter but they must all be of the sameReplicatedData
type. For interaction with several differentReplicatedData
types, e.g. anOrSet
and aGCounter
, an adapter can be created for each type.For the default replicator in the
DistributedData
extension aReplicatorMessageAdapter
can be created withDistributedData.withReplicatorMessageAdapter
.*Warning*:
ReplicatorMessageAdapter
is 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 asCompletionStage
callbacks. It must not be shared between several actor instances.param: context The
ActorContext
of the requesting actor. TheReplicatorMessageAdapter
can only be used in this actor. param: replicator The replicator to interact with, typicallyDistributedData.get(system).replicator
. param: unexpectedAskTimeout The timeout to use forask
operations. This should be longer than thetimeout
given inReplicator.WriteConsistency
andReplicator.ReadConsistency
. The replicator will always send a reply within those timeouts so theunexpectedAskTimeout
should not occur, but for cleanup in a failure situation it must still exist. IfaskUpdate
,askGet
oraskDelete
takes longer then thisunexpectedAskTimeout
aTimeoutException
will 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 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.Delete
request to the replicator.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.Get
request to the replicator.void
askReplicaCount(java.util.function.Function<ActorRef<Replicator.ReplicaCount>,Replicator.GetReplicaCount> createRequest, java.util.function.Function<Replicator.ReplicaCount,A> responseAdapter)
Send aReplicator.GetReplicaCount
request to the replicator.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.Update
request to the replicator.void
subscribe(Key<B> key, Function<Replicator.SubscribeResponse<B>,A> responseAdapter)
Subscribe to changes of the givenkey
.void
unsubscribe(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.Delete
request to the replicator. TheReplicator.DeleteResponse
message is transformed to the message protocol of the requesting actor with the givenresponseAdapter
function.Note that
createRequest
is a function that creates theDelete
message from the providedActorRef[DeleteResponse]
that the the replicator will send the response message back through. Use thatActorRef[DeleteResponse]
as thereplyTo
parameter in theDelete
message.
-
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.Get
request to the replicator. TheReplicator.GetResponse
message is transformed to the message protocol of the requesting actor with the givenresponseAdapter
function.Note that
createRequest
is a function that creates theGet
message from the providedActorRef[GetResponse]
that the the replicator will send the response message back through. Use thatActorRef[GetResponse]
as thereplyTo
parameter in theGet
message.
-
askReplicaCount
public void askReplicaCount(java.util.function.Function<ActorRef<Replicator.ReplicaCount>,Replicator.GetReplicaCount> createRequest, java.util.function.Function<Replicator.ReplicaCount,A> responseAdapter)
Send aReplicator.GetReplicaCount
request to the replicator. TheReplicator.ReplicaCount
message is transformed to the message protocol of the requesting actor with the givenresponseAdapter
function.Note that
createRequest
is a function that creates theGetReplicaCount
message from the providedActorRef[ReplicaCount]
that the the replicator will send the response message back through. Use thatActorRef[ReplicaCount]
as thereplyTo
parameter in theGetReplicaCount
message.
-
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.Update
request to the replicator. TheReplicator.UpdateResponse
message is transformed to the message protocol of the requesting actor with the givenresponseAdapter
function.Note that
createRequest
is a function that creates theUpdate
message from the providedActorRef[UpdateResponse]
that the the replicator will send the response message back through. Use thatActorRef[UpdateResponse]
as thereplyTo
parameter in theUpdate
message.
-
subscribe
public void subscribe(Key<B> key, Function<Replicator.SubscribeResponse<B>,A> responseAdapter)
Subscribe to changes of the givenkey
. TheReplicator.Changed
andReplicator.Deleted
messages from the replicator are transformed to the message protocol of the requesting actor with the givenresponseAdapter
function.
-
-