Class DispatcherThread

java.lang.Object
java.lang.Thread
org.nustaq.kontraktor.impl.DispatcherThread
All Implemented Interfaces:
Runnable, Monitorable

public class DispatcherThread extends Thread implements Monitorable
Implements the default dispatcher/scheduling of actors. For each actor created from "outside" (not from within another actor). A new DispatcherThread is created automatically. An actor created from within another actor inherits the dispatcher of the enclosing actor by default. Calls from actors sharing the same dispatcher are done directly (no queueing). Calls across actors in different dispatchers are put to the Channel of the receiving dispatcher. Note that cross-dispatcher calls are like 1000 times slower than inbound calls. Each dispatcher owns exactly one single thread. Note that dispatchers must be terminated if not needed any longer, as a thread is associated with them. For more sophisticated applications it might be appropriate to manually set up dispatchers (Actors.assignDispatcher()). The Actors.Channel method allows to specifiy a dedicated dispatcher on which to run the actor. This way it is possible to exactly balance and control the number of threads created and which thread operates a set of actors.
  • Field Details

    • DUMP_CATCHED

      public static boolean DUMP_CATCHED
    • SCHEDULE_TICK_NANOS

      public static int SCHEDULE_TICK_NANOS
    • QUEUE_PERCENTAGE_TRIGGERING_REBALANCE

      public static int QUEUE_PERCENTAGE_TRIGGERING_REBALANCE
    • MILLIS_AFTER_CREATION_BEFORE_REBALANCING

      public static int MILLIS_AFTER_CREATION_BEFORE_REBALANCING
    • activeDispatchers

      public static AtomicInteger activeDispatchers
    • POLL_ALL_Q

      public static final int POLL_ALL_Q
      See Also:
    • POLL_CB_Q

      public static final int POLL_CB_Q
      See Also:
    • shutDown

      protected boolean shutDown
    • __stack

      public ArrayList __stack
    • autoShutDown

      protected volatile boolean autoShutDown
  • Constructor Details

    • DispatcherThread

      public DispatcherThread(Scheduler scheduler)
    • DispatcherThread

      public DispatcherThread(Scheduler scheduler, boolean autoShutDown)
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Thread
    • isIsolated

      public boolean isIsolated()
    • setIsolated

      public void setIsolated(boolean isIsolated)
    • addActor

      public void addActor(Actor act)
    • isAutoShutDown

      public boolean isAutoShutDown()
    • setAutoShutDown

      public void setAutoShutDown(boolean autoShutDown)
    • run

      public void run()
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • schedulePendingAdds

      public void schedulePendingAdds()
      add actors which have been marked to be scheduled on this
    • pollQueues

      protected CallEntry pollQueues(Actor[] actors, int queues)
    • pollQs

      public boolean pollQs()
      Returns:
      false if no message could be polled
    • pollQs

      public boolean pollQs(int queues)
    • pollQs

      public boolean pollQs(Actor[] actors, int queues)
      Parameters:
      queues - - see constants
      Returns:
      false if no message could be polled
    • getLoad

      public int getLoad()
      WARNING: call rarely, this method might have O(n) runtime with default unbounded queues.
      Returns:
      percentage of queue fill of max actor
    • getAccumulatedQSizes

      public int getAccumulatedQSizes()
      accumulated queue sizes of all actors
      Returns:
    • getQSize

      public int getQSize()
      Returns:
      accumulated q size of all dispatched actors
    • isShutDown

      public boolean isShutDown()
      Returns:
      true if DispatcherThread is shut down
    • shutDown

      public void shutDown()
      terminate operation after emptying Q
    • shutDownImmediate

      public void shutDownImmediate()
      terminate operation immediately. Pending messages in Q are lost
    • isEmpty

      public boolean isEmpty()
    • waitEmpty

      public void waitEmpty(long nanos)
      blocking method, use for debugging only.
    • getScheduler

      public Scheduler getScheduler()
    • getActors

      public Actor[] getActors()
      Returns:
      a copy of actors used
    • schedules

      public boolean schedules(Object receiverRef)
      can be called from the dispacther thread itself only
      Parameters:
      receiverRef -
      Returns:
    • getReport

      public IPromise getReport()
      Specified by:
      getReport in interface Monitorable
    • getSubMonitorables

      public IPromise<Monitorable[]> getSubMonitorables()
      Specified by:
      getSubMonitorables in interface Monitorable