akka.contrib.throttle

TimerBasedThrottler

class TimerBasedThrottler extends Actor with Throttler with FSM[State, Data]

A akka.contrib.throttle.Throttler that uses a timer to control the message delivery rate.

Example

For example, if you set a rate like "3 messages in 1 second", the throttler will send the first three messages immediately to the target actor but will need to impose a delay before sending out further messages:

// A simple actor that prints whatever it receives
val printer = system.actorOf(Props(new Actor {
  def receive = {
    case x => println(x)
  }
}))
// The throttler for this example, setting the rate
val throttler = system.actorOf(Props(new TimerBasedThrottler(3 msgsPer (1.second))))
// Set the target
throttler ! SetTarget(Some(printer))
// These three messages will be sent to the printer immediately
throttler ! "1"
throttler ! "2"
throttler ! "3"
// These two will wait at least until 1 second has passed
throttler ! "4"
throttler ! "5"

Implementation notes

This throttler implementation internally installs a timer that repeats every rate.durationInMillis and enables rate.numberOfCalls additional calls to take place. A TimerBasedThrottler uses very few system resources, provided the rate's duration is not too fine-grained (which would cause a lot of timer invocations); for example, it does not store the calling history as other throttlers may need to do.

However, a TimerBasedThrottler only provides weak guarantees on the rate (see also this blog post):

For some applications, these guarantees may not be sufficient.

Known issues

See also

akka.contrib.throttle.Throttler

Linear Supertypes
FSM[TimerBasedThrottler.State, Data], ActorLogging, Listeners, Throttler, Actor, AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. TimerBasedThrottler
  2. FSM
  3. ActorLogging
  4. Listeners
  5. Throttler
  6. Actor
  7. AnyRef
  8. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new TimerBasedThrottler(rate: Rate)

Type Members

  1. case class Event extends Product with Serializable

    Definition Classes
    FSM
  2. type Receive = PartialFunction[Any, Unit]

    Definition Classes
    Actor
  3. type State = actor.FSM.State[TimerBasedThrottler.State, Data]

    Definition Classes
    FSM
  4. type StateFunction = PartialFunction[Event, State]

    Definition Classes
    FSM
  5. case class StopEvent extends Product with Serializable

    Definition Classes
    FSM
  6. type Timeout = Option[FiniteDuration]

    Definition Classes
    FSM
  7. final class TransformHelper extends AnyRef

    Definition Classes
    FSM
  8. type TransitionHandler = PartialFunction[(TimerBasedThrottler.State, TimerBasedThrottler.State), Unit]

    Definition Classes
    FSM

Value Members

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

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. val ->: actor.FSM.->.type

    Definition Classes
    FSM
  5. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  6. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  7. val StateTimeout: actor.FSM.StateTimeout.type

    Definition Classes
    FSM
  8. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  9. final def cancelTimer(name: String): Unit

    Definition Classes
    FSM
  10. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  11. implicit val context: ActorContext

    Attributes
    protected[akka]
    Definition Classes
    Actor
  12. final def eq(arg0: AnyRef): Boolean

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

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

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

    Definition Classes
    AnyRef → Any
  16. def gossip(msg: Any)(implicit sender: ActorRef): Unit

    Attributes
    protected
    Definition Classes
    Listeners
  17. final def goto(nextStateName: TimerBasedThrottler.State): State

    Definition Classes
    FSM
  18. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  19. final def initialize: Unit

    Definition Classes
    FSM
  20. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  21. def listenerManagement: actor.Actor.Receive

    Attributes
    protected
    Definition Classes
    Listeners
  22. val listeners: Set[ActorRef]

    Attributes
    protected
    Definition Classes
    Listeners
  23. val log: LoggingAdapter

    Definition Classes
    ActorLogging
  24. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  25. final def nextStateData: Data

    Definition Classes
    FSM
  26. final def notify(): Unit

    Definition Classes
    AnyRef
  27. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  28. final def onTermination(terminationHandler: PartialFunction[StopEvent, Unit]): Unit

    Definition Classes
    FSM
  29. final def onTransition(transitionHandler: TransitionHandler): Unit

    Definition Classes
    FSM
  30. def postRestart(reason: Throwable): Unit

    Definition Classes
    Actor
  31. def postStop(): Unit

    Definition Classes
    FSM
  32. def preRestart(reason: Throwable, message: Option[Any]): Unit

    Definition Classes
    Actor
  33. def preStart(): Unit

    Definition Classes
    Actor
  34. var rate: Rate

  35. def receive: Receive

    Definition Classes
    FSM
  36. implicit final val self: ActorRef

    Definition Classes
    Actor
  37. final def sender: ActorRef

    Definition Classes
    Actor
  38. final def setStateTimeout(state: TimerBasedThrottler.State, timeout: Timeout): Unit

    Definition Classes
    FSM
  39. final def setTimer(name: String, msg: Any, timeout: FiniteDuration, repeat: Boolean): State

    Definition Classes
    FSM
  40. final def startWith(stateName: TimerBasedThrottler.State, stateData: Data, timeout: Timeout): Unit

    Definition Classes
    FSM
  41. final def stateData: Data

    Definition Classes
    FSM
  42. final def stateName: TimerBasedThrottler.State

    Definition Classes
    FSM
  43. final def stay(): State

    Definition Classes
    FSM
  44. final def stop(reason: Reason, stateData: Data): State

    Definition Classes
    FSM
  45. final def stop(reason: Reason): State

    Definition Classes
    FSM
  46. final def stop(): State

    Definition Classes
    FSM
  47. def supervisorStrategy: SupervisorStrategy

    Definition Classes
    Actor
  48. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  49. final def timerActive_?(name: String): Boolean

    Definition Classes
    FSM
  50. def toString(): String

    Definition Classes
    AnyRef → Any
  51. implicit final def total2pf(transitionHandler: (TimerBasedThrottler.State, TimerBasedThrottler.State) ⇒ Unit): TransitionHandler

    Definition Classes
    FSM
  52. final def transform(func: StateFunction): TransformHelper

    Definition Classes
    FSM
  53. def unhandled(message: Any): Unit

    Definition Classes
    Actor
  54. final def wait(): Unit

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

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

    Definition Classes
    AnyRef
    Annotations
    @throws()
  57. final def when(stateName: TimerBasedThrottler.State, stateTimeout: FiniteDuration)(stateFunction: StateFunction): Unit

    Definition Classes
    FSM
  58. final def whenUnhandled(stateFunction: StateFunction): Unit

    Definition Classes
    FSM

Inherited from FSM[TimerBasedThrottler.State, Data]

Inherited from ActorLogging

Inherited from Listeners

Inherited from Throttler

Inherited from Actor

Inherited from AnyRef

Inherited from Any

Ungrouped