abstract class Retrier[Req, Msg, Ack, Key] extends AnyRef
Helper class for actors that need to retry some of the messages they send to other actors until a certain acknowledgement message (ACK) is received. Messages can be sent individually or in batches.
This class is instantiated by providing functions that extract an identifier from sent messages
and from ACK messages. This can be an arbitrary identifier, as long as it uniquely associates a
received ACK with the original sent message. Optional per-message filtering functions can be
given, as well as the frequency of the retries and an optional timeout. Finally, the onComplete
method, which is executed after a message or group of messages is acknowledged, must be
implemented.
A Retrier can be used as follows:
case class ChangeData(reqId: Long, data: String) case class ChangeDataAck(reqId: Long) case class Replicate(reqId: Long, data: String) case class ReplicateAck(reqId: Long) class Master(val replica: ActorRef) extends Actor { import Retrier._ val retrier = new Retrier[(ActorRef, ChangeData), Replicate, ReplicateAck, Long](_.reqId, _.reqId) { def onComplete(req: (ActorRef, ChangeData)) = req._1 ! ChangeDataAck(req._2.reqId) } def receive: Receive = ({ case msg @ ChangeData(reqId, data) => // change data internally here retrier.dispatch((sender, msg), Replicate(reqId, data), replica) }: Receive).orRetryWith(retrier) }
In the previous example, every time a Master actor receives a ChangeData message, it
sends a Replicate message to a replica actor and only responds to the original sender after an
acknowledgement from the replica is received. The Replicate message is retried periodically.
- Req
the type of the triggering request
- Msg
the type of the messages to be sent and retried
- Ack
the type of the ACK messages
- Key
the type of identifier or object that links a sent message to its ACK
- Annotations
- @deprecated
- Deprecated
(Since version 2017/07/13) This will be removed in a future version
- Alphabetic
- By Inheritance
- Retrier
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
-
new
Retrier(msgKeyFunc: (Msg) ⇒ Key, ackKeyFunc: (Ack) ⇒ Key, isAck: (Ack) ⇒ Boolean = _: Ack => true, shouldRetry: (Msg) ⇒ Boolean = _: Msg => true, retryDelay: FiniteDuration = 100.millis, timeout: Option[FiniteDuration] = None)(implicit arg0: ClassTag[Msg], arg1: ClassTag[Ack], context: ActorContext, self: ActorRef)
- msgKeyFunc
a function that extracts a key out of a sent message
- ackKeyFunc
a function that extracts a key out of an acknowledgement message
- isAck
a function that defines which messages of type
Ackshould be considered acknowledgments- shouldRetry
a function that defines if a message should be retried or not
- retryDelay
the retry delay
- timeout
an optional timeout
- context
the actor context
- self
the actor for which this
Retrierwas created
Abstract Value Members
-
abstract
def
onComplete(request: Req): Unit
Hook executed when a message or group of messages is acknowledged.
Hook executed when a message or group of messages is acknowledged.
- request
the triggering request
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
ackAll(to: ActorRef): Unit
Acknowledges immediately all messages sent to an actor.
Acknowledges immediately all messages sent to an actor.
- to
the destination of the messages to be acknowledged
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
def
dispatch(request: Req, msgs: Set[(Msg, ActorRef)]): Unit
Dispatches a set of messages to their destinations as a batch.
Dispatches a set of messages to their destinations as a batch. The
onCompletemethod will only be called once all sent messages are acknowledged. Retries are executed per message; a timeout ceases all retries in the batch and causes theonFailuremethod to fire.- request
the request that triggered this dispatch. Used only for identifying this batch when the
onCompleteandonFailuremethods are called.- msgs
the set of messages to sent and respective destinations
-
def
dispatch(request: Req, msg: Msg, to: ActorRef): Unit
Dispatches a single message.
Dispatches a single message. The
onCompletemethod will be called once all the message is acknowledged. If a timeout occurs,onFailuremethod is fired.- request
the request that triggered this dispatch. Used only for identifying this batch when the
onCompleteandonFailuremethods are called.- msg
the message to send
- to
the destination of the message
- implicit val dispatcher: ExecutionContextExecutor
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
onFailure(request: Req): Unit
Hook executed when a timeout occurs in a message or group of messages.
Hook executed when a timeout occurs in a message or group of messages.
- request
the triggering request
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
def
withRetry(rec: Receive): Receive
Augments a
Receiveaction with retry-specific message handling.Augments a
Receiveaction with retry-specific message handling.- rec
the
Receiveaction to augment- returns
a new
Receivecapable of handling retry-specific messages.