Class Hoarde<T extends Actor>

java.lang.Object
org.nustaq.kontraktor.util.Hoarde<T>

public class Hoarde<T extends Actor>
extends java.lang.Object
Created by ruedi on 07.09.14. a utility class allowing to address/manage multiple actors of same type
  • Constructor Summary

    Constructors 
    Constructor Description
    Hoarde​(int numActors, java.lang.Class<T> actor)
    create a hoarde with each actor having a dedicated thread
    Hoarde​(int numActors, java.lang.Class<T> actor, Scheduler sched)
    create a hoarde scheduled on given scheduler
  • Method Summary

    Modifier and Type Method Description
    Hoarde<T> each​(java.util.function.BiConsumer<T,​java.lang.Integer> init)
    same as other each but with index
    Hoarde<T> each​(java.util.function.Consumer<T> tocall)
    iterate over each actor and execute tocall.
    T getActor​(int i)  
    int getSize()  
    <X> IPromise<T>[] map​(java.util.function.BiFunction<T,​java.lang.Integer,​IPromise<X>> init)  
    IPromise ordered​(java.util.function.Function<T,​IPromise> toCall)
    calls given function round robin. typical use: hoarde.ordered( actor -> actor.decode(byte[]) ).onResult( decodedObj -> businesslogic(decodedObj) ); after

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Hoarde

      public Hoarde​(int numActors, java.lang.Class<T> actor)
      create a hoarde with each actor having a dedicated thread
      Parameters:
      numActors -
      actor -
    • Hoarde

      public Hoarde​(int numActors, java.lang.Class<T> actor, Scheduler sched)
      create a hoarde scheduled on given scheduler
      Parameters:
      numActors -
      actor -
      sched -
  • Method Details

    • map

      public <X> IPromise<T>[] map​(java.util.function.BiFunction<T,​java.lang.Integer,​IPromise<X>> init)
    • each

      public Hoarde<T> each​(java.util.function.Consumer<T> tocall)
      iterate over each actor and execute tocall. E.g. hoarde.each( actor -> actor.init() )
      Parameters:
      tocall -
      Returns:
    • each

      public Hoarde<T> each​(java.util.function.BiConsumer<T,​java.lang.Integer> init)
      same as other each but with index
      Parameters:
      init -
      Returns:
    • ordered

      public IPromise ordered​(java.util.function.Function<T,​IPromise> toCall)
      calls given function round robin. typical use: hoarde.ordered( actor -> actor.decode(byte[]) ).onResult( decodedObj -> businesslogic(decodedObj) ); after
      Parameters:
      toCall -
      Returns:
    • getSize

      public int getSize()
    • getActor

      public T getActor​(int i)