Interface Resizer

All Known Subinterfaces:
OptimalSizeExploringResizer
All Known Implementing Classes:
DefaultOptimalSizeExploringResizer, DefaultResizer

public interface Resizer
Pool routers with dynamically resizable number of routees are implemented by providing a Resizer implementation in the pekko.routing.Pool configuration.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    clamp(int proposedSize)
    Constrain a proposed total pool size to the bounds enforced by this resizer.
    boolean
    isTimeForResize(long messageCounter)
    Is it time for resizing.
    int
    resize(scala.collection.immutable.IndexedSeq<Routee> currentRoutees)
    Decide if the capacity of the router need to be changed.
  • Method Details

    • isTimeForResize

      boolean isTimeForResize(long messageCounter)
      Is it time for resizing. Typically implemented with modulo of nth message, but could be based on elapsed time or something else. The messageCounter starts with 0 for the initial resize and continues with 1 for the first message. Make sure to perform initial resize before first message (messageCounter == 0), because there is no guarantee that resize will be done when concurrent messages are in play.

      CAUTION: this method is invoked from the thread which tries to send a message to the pool, i.e. the ActorRef.!() method, hence it may be called concurrently.

    • resize

      int resize(scala.collection.immutable.IndexedSeq<Routee> currentRoutees)
      Decide if the capacity of the router need to be changed. Will be invoked when isTimeForResize returns true and no other resize is in progress.

      Return the number of routees to add or remove. Negative value will remove that number of routees. Positive value will add that number of routees. 0 will not change the routees.

      This method is invoked only in the context of the Router actor.

    • clamp

      int clamp(int proposedSize)
      Constrain a proposed total pool size to the bounds enforced by this resizer. Used by AdjustPoolSize management messages to respect resizer bounds. The default implementation only ensures the size is at least 1.

      Parameters:
      proposedSize - the proposed total number of routees
      Returns:
      the clamped pool size
      Since:
      2.0.0