Package kilim
Class Scheduler
- java.lang.Object
-
- kilim.Scheduler
-
- Direct Known Subclasses:
AffineScheduler,ForkJoinScheduler
public abstract class Scheduler extends java.lang.ObjectThis is a basic FIFO Executor. It maintains a list of runnable tasks and hands them out to WorkerThreads. Note that we don't maintain a list of all tasks, but we will at some point when we introduce monitoring/watchdog services. Paused tasks are not GC'd because their PauseReasons ought to be registered with some other live object.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classScheduler.BasicLoggerstatic interfaceScheduler.Logger
-
Field Summary
Fields Modifier and Type Field Description static Scheduler.LoggerdefaultLoggerstatic intdefaultNumberThreadsstatic SchedulerdefaultSchedulerprivate Scheduler.Loggerloggerstatic SchedulerpinnableSchedulerprotected java.util.concurrent.atomic.AtomicBooleanshutdownprivate static java.lang.ThreadLocal<Task>taskMgr_
-
Constructor Summary
Constructors Constructor Description Scheduler()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected static TaskgetCurrentTask()static SchedulergetDefaultPinnable()get and possibly instantiate a scheduler that is pinnablestatic SchedulergetDefaultScheduler()get and possibly instantiate a default schedulerprotected SchedulergetPinnable()abstract voididledown()block the thread till a moment at which all scheduled tasks have completed and then shutdown the scheduler does not prevent scheduling new tasks (from other threads) until the shutdown is complete so such a task could be partially executedabstract booleanisEmptyish()are the queues empty allows false positives, but not false negatives ie, if this method returns false, then at some moment during the call at least one queue was non-empty if it returns true then for each queue there was a moment during the call when it was emptybooleanisPinnable()booleanisShutdown()protected voidlog(java.lang.Object src, java.lang.Object obj)write to the logprotected static voidlogRelay(Scheduler sched, java.lang.Object src, java.lang.Object obj)a static accessor to allow log to be protectedstatic Schedulermake(int numThreads)return a new default Scheduler with default queue lengthabstract intnumThreads()abstract voidschedule(int index, Task t)schedule a task to runvoidschedule(Task t)Schedule a task to run.abstract voidscheduleTimer(Timer t)protected static voidsetCurrentTask(Task t)static voidsetDefaultPinnable(Scheduler s)static voidsetDefaultScheduler(Scheduler s)voidsetLogger(Scheduler.Logger logger)set a loggervoidshutdown()
-
-
-
Field Detail
-
defaultScheduler
public static volatile Scheduler defaultScheduler
-
pinnableScheduler
public static volatile Scheduler pinnableScheduler
-
defaultNumberThreads
public static int defaultNumberThreads
-
taskMgr_
private static final java.lang.ThreadLocal<Task> taskMgr_
-
defaultLogger
public static Scheduler.Logger defaultLogger
-
shutdown
protected java.util.concurrent.atomic.AtomicBoolean shutdown
-
logger
private Scheduler.Logger logger
-
-
Method Detail
-
getCurrentTask
protected static Task getCurrentTask()
-
setCurrentTask
protected static void setCurrentTask(Task t)
-
make
public static Scheduler make(int numThreads)
return a new default Scheduler with default queue length- Parameters:
numThreads- the number of threads to use, or use the default if less than one- Returns:
- the new Scheduler
-
isEmptyish
public abstract boolean isEmptyish()
are the queues empty allows false positives, but not false negatives ie, if this method returns false, then at some moment during the call at least one queue was non-empty if it returns true then for each queue there was a moment during the call when it was empty
-
numThreads
public abstract int numThreads()
-
isPinnable
public boolean isPinnable()
-
schedule
public void schedule(Task t)
Schedule a task to run. It is the task's job to ensure that it is not scheduled when it is runnable. the default index for assignment to an executor
-
schedule
public abstract void schedule(int index, Task t)schedule a task to run- Parameters:
index- the index of the executor to use, or less than zero to use the default (round robin) assignmentt- the task
-
scheduleTimer
public abstract void scheduleTimer(Timer t)
-
idledown
public abstract void idledown()
block the thread till a moment at which all scheduled tasks have completed and then shutdown the scheduler does not prevent scheduling new tasks (from other threads) until the shutdown is complete so such a task could be partially executed
-
shutdown
public void shutdown()
-
isShutdown
public boolean isShutdown()
-
logRelay
protected static void logRelay(Scheduler sched, java.lang.Object src, java.lang.Object obj)
a static accessor to allow log to be protected
-
log
protected void log(java.lang.Object src, java.lang.Object obj)write to the log- Parameters:
src- the source of the log objectobj- the object to log
-
setLogger
public void setLogger(Scheduler.Logger logger)
set a logger- Parameters:
logger- the logger
-
getDefaultScheduler
public static Scheduler getDefaultScheduler()
get and possibly instantiate a default scheduler
-
getDefaultPinnable
public static Scheduler getDefaultPinnable()
get and possibly instantiate a scheduler that is pinnable
-
getPinnable
protected Scheduler getPinnable()
-
setDefaultScheduler
public static void setDefaultScheduler(Scheduler s)
-
setDefaultPinnable
public static void setDefaultPinnable(Scheduler s)
-
-