Package org.nustaq.kontraktor.impl
Class DispatcherThread
java.lang.Object
java.lang.Thread
org.nustaq.kontraktor.impl.DispatcherThread
- All Implemented Interfaces:
Runnable
,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.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic AtomicInteger
protected boolean
static boolean
static int
static final int
static final int
static int
static int
protected boolean
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Constructor Summary
ConstructorsConstructorDescriptionDispatcherThread
(Scheduler scheduler) DispatcherThread
(Scheduler scheduler, boolean autoShutDown) -
Method Summary
Modifier and TypeMethodDescriptionvoid
int
accumulated queue sizes of all actorsActor[]
int
getLoad()
WARNING: call rarely, this method might have O(n) runtime with default unbounded queues.int
getQSize()
boolean
boolean
isEmpty()
boolean
boolean
boolean
pollQs()
boolean
pollQs
(int queues) boolean
protected CallEntry
pollQueues
(Actor[] actors, int queues) void
run()
void
add actors which have been marked to be scheduled on thisboolean
can be called from the dispacther thread itself onlyvoid
setAutoShutDown
(boolean autoShutDown) void
setIsolated
(boolean isIsolated) void
shutDown()
terminate operation after emptying Qvoid
terminate operation immediately.toString()
void
waitEmpty
(long nanos) blocking method, use for debugging only.Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, yield
-
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
-
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
-
autoShutDown
protected volatile boolean autoShutDown
-
-
Constructor Details
-
DispatcherThread
-
DispatcherThread
-
-
Method Details
-
toString
-
isIsolated
public boolean isIsolated() -
setIsolated
public void setIsolated(boolean isIsolated) -
addActor
-
isAutoShutDown
public boolean isAutoShutDown() -
setAutoShutDown
public void setAutoShutDown(boolean autoShutDown) -
run
public void run() -
schedulePendingAdds
public void schedulePendingAdds()add actors which have been marked to be scheduled on this -
pollQueues
-
pollQs
public boolean pollQs()- Returns:
- false if no message could be polled
-
pollQs
public boolean pollQs(int queues) -
pollQs
- 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
-
getActors
- Returns:
- a copy of actors used
-
schedules
can be called from the dispacther thread itself only- Parameters:
receiverRef
-- Returns:
-
getReport
- Specified by:
getReport
in interfaceMonitorable
-
getSubMonitorables
- Specified by:
getSubMonitorables
in interfaceMonitorable
-