Class PoolRouter<T>
- java.lang.Object
-
- akka.actor.typed.Behavior<T>
-
- akka.actor.typed.internal.BehaviorImpl.DeferredBehavior<T>
-
- akka.actor.typed.javadsl.PoolRouter<T>
-
public abstract class PoolRouter<T> extends BehaviorImpl.DeferredBehavior<T>
Provides builder style configuration options for pool routersNot for user extension. Use
Routers.pool(int, akka.actor.typed.Behavior<T>)
to create
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class akka.actor.typed.Behavior
Behavior.BehaviorDecorators<Inner>, Behavior.BehaviorDecorators$
-
-
Constructor Summary
Constructors Constructor Description PoolRouter()
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description abstract PoolRouter<T>
withBroadcastPredicate(java.util.function.Predicate<T> pred)
Any message that the predicate returns true for will be broadcast to all routees.abstract PoolRouter<T>
withConsistentHashingRouting(int virtualNodesFactor, java.util.function.Function<T,java.lang.String> mapping)
Route messages by using consistent hashing.abstract PoolRouter<T>
withPoolSize(int poolSize)
Set a new pool size from the one set at constructionabstract PoolRouter<T>
withRandomRouting()
Route messages by randomly selecting the routee from the available routees.abstract PoolRouter<T>
withRoundRobinRouting()
Route messages through round robin, providing a fair distribution of messages across the routees.abstract PoolRouter<T>
withRouteeProps(Props routeeProps)
Set the props used to spawn the pool's routees-
Methods inherited from class akka.actor.typed.internal.BehaviorImpl.DeferredBehavior
apply
-
Methods inherited from class akka.actor.typed.Behavior
BehaviorDecorators, canonicalize, existsInStack, interpretMessage, interpretSignal, isAlive, isDeferred, isUnhandled, narrow, start, validateAsInitial
-
-
-
-
Method Detail
-
withBroadcastPredicate
public abstract PoolRouter<T> withBroadcastPredicate(java.util.function.Predicate<T> pred)
Any message that the predicate returns true for will be broadcast to all routees.
-
withConsistentHashingRouting
public abstract PoolRouter<T> withConsistentHashingRouting(int virtualNodesFactor, java.util.function.Function<T,java.lang.String> mapping)
Route messages by using consistent hashing.From wikipedia: Consistent hashing is based on mapping each object to a point on a circle (or equivalently, mapping each object to a real angle). The system maps each available machine (or other storage bucket) to many pseudo-randomly distributed points on the same circle.
- Parameters:
virtualNodesFactor
- This factor has to be greater or equal to 1. Assuming that the reader knows what consistent hashing is (if not, please refer: https://www.tom-e-white.com/2007/11/consistent-hashing.html or wiki). This number is responsible for creating additional, virtual addresses for a provided set of routees, so that in the total number of points on hashing ring will be equal to numberOfRoutees * virtualNodesFactor (if virtualNodesFactor is equal to 1, then no additional points will be created).Those virtual nodes are being created by additionally rehashing routees to evenly distribute them across hashing ring. Consider increasing this number when you have a small number of routees. For bigger loads one can aim in having around 100-200 total addresses.
mapping
- Hash key extractor. This function will be used in consistent hashing process. Result of this operation should possibly uniquely distinguish messages.
-
withPoolSize
public abstract PoolRouter<T> withPoolSize(int poolSize)
Set a new pool size from the one set at construction
-
withRandomRouting
public abstract PoolRouter<T> withRandomRouting()
Route messages by randomly selecting the routee from the available routees.Random routing makes it less likely that every
poolsize
message from a single producer ends up in the same mailbox of a slow actor.
-
withRoundRobinRouting
public abstract PoolRouter<T> withRoundRobinRouting()
Route messages through round robin, providing a fair distribution of messages across the routees.Round robin gives fair routing where every available routee gets the same amount of messages
This is the default for pool routers.
-
withRouteeProps
public abstract PoolRouter<T> withRouteeProps(Props routeeProps)
Set the props used to spawn the pool's routees
-
-