Class/Object

eu.shiftforward.apso.actor

Retrier

Related Docs: object Retrier | package actor

Permalink

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

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Retrier
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. 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)

    Permalink

    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 Ack should 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 Retrier was created

Abstract Value Members

  1. abstract def onComplete(request: Req): Unit

    Permalink

    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

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. def ackAll(to: ActorRef): Unit

    Permalink

    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

  5. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  6. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  7. def dispatch(request: Req, msgs: Set[(Msg, ActorRef)]): Unit

    Permalink

    Dispatches a set of messages to their destinations as a batch.

    Dispatches a set of messages to their destinations as a batch. The onComplete method 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 the onFailure method to fire.

    request

    the request that triggered this dispatch. Used only for identifying this batch when the onComplete and onFailure methods are called.

    msgs

    the set of messages to sent and respective destinations

  8. def dispatch(request: Req, msg: Msg, to: ActorRef): Unit

    Permalink

    Dispatches a single message.

    Dispatches a single message. The onComplete method will be called once all the message is acknowledged. If a timeout occurs, onFailure method is fired.

    request

    the request that triggered this dispatch. Used only for identifying this batch when the onComplete and onFailure methods are called.

    msg

    the message to send

    to

    the destination of the message

  9. implicit val dispatcher: ExecutionContextExecutor

    Permalink
  10. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  11. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  12. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  13. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  14. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  15. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  16. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  17. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  18. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  19. def onFailure(request: Req): Unit

    Permalink

    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

  20. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  21. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  22. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  23. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  24. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  25. def withRetry(rec: Receive): Receive

    Permalink

    Augments a Receive action with retry-specific message handling.

    Augments a Receive action with retry-specific message handling.

    rec

    the Receive action to augment

    returns

    a new Receive capable of handling retry-specific messages.

Inherited from AnyRef

Inherited from Any

Ungrouped