- java.lang.Object
-
- swim.concurrent.Theater
-
- All Implemented Interfaces:
Thread.UncaughtExceptionHandler
,Executor
,MainStage
,Schedule
,Stage
public class Theater extends Object implements MainStage, Thread.UncaughtExceptionHandler
Stage
that executes timers, tasks, and continuations on aForkJoinPool
.
-
-
Constructor Summary
Constructors Constructor Description Theater()
Theater(int parallelism)
Theater(int parallelism, Schedule schedule)
Theater(String name)
Theater(String name, int parallelism)
Theater(String name, int parallelism, Schedule schedule)
Theater(String name, Schedule schedule)
Theater(Schedule schedule)
Theater(TheaterDef theaterDef)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Call<T>
call(Cont<T> cont)
Returns aCall
that completes thecont
inuation.protected <T> void
callDidBind(Cont<?> cont, T value)
Introspection callback invoked immediately after a call tocont.bind(value)
returns nominally.protected void
callDidFail(Cont<?> cont, Throwable error)
Introspection callback invoked immediately after a call tocont.bind(T)
fails by throwing anerror
.protected void
callDidTrap(Cont<?> cont, Throwable error)
Introspection callback invoked immediately after a call tocont.trap(error)
returns nominally.protected <T> void
callWillBind(Cont<T> cont, T value)
Introspection callback invoked immediately before a call tocont.bind(value)
.protected void
callWillCue(Cont<?> cont)
Introspection callback invoked before acont
call is cued for execution.protected void
callWillTrap(Cont<?> cont, Throwable error)
Introspection callback invoked immediately before a call tocont.trap(error)
.protected void
didFail(Throwable error)
Lifecycle callback invoked if thisTheater
encounters an internalerror
.protected void
didStart()
Lifecycle callback invoked before the thread pool starts up.protected void
didStop()
Lifecycle callback invoked after the thread pool shuts down.void
execute(Runnable runnable)
Schedules arunnable
for concurrent execution.String
name()
int
parallelism()
Schedule
schedule()
void
setSchedule(Schedule schedule)
TimerRef
setTimer(long millis, TimerFunction timer)
Schedulestimer
to execute aftermillis
milliseconds have elapsed.void
start()
Ensures that thisTheater
is up and running.void
stop()
Ensures that thisTheater
has been permanently stopped, shutting down the thread pool, if it's currently running.TaskRef
task(TaskFunction task)
Returns an uncuedTaskRef
bound to thetask
, which can later be used to cue thetask
.protected void
taskDidCancel(TaskFunction task)
Introspection callback invoked after a cuedtask
is canceled.protected void
taskDidFail(TaskFunction task, Throwable error)
Introspection callback invoked immediately aftertask.runTask()
fails by throwing anerror
.protected void
taskDidRun(TaskFunction task)
Introspection callback invoked immediately aftertask.runTask()
returns nominally.protected void
taskWillCue(TaskFunction task)
Introspection callback invoked before atask
is cued for execution.protected void
taskWillRun(TaskFunction task)
Introspection callback invoked immediately beforetask.runTask()
is executed.TimerRef
timer(TimerFunction timer)
Returns an unscheduledTimerRef
bound totimer
, which can later be used to scheduletimer
.void
uncaughtException(Thread thead, Throwable error)
-
-
-
Constructor Detail
-
Theater
public Theater(TheaterDef theaterDef)
-
Theater
public Theater(String name, int parallelism)
-
Theater
public Theater(String name)
-
Theater
public Theater(int parallelism, Schedule schedule)
-
Theater
public Theater(int parallelism)
-
Theater
public Theater(Schedule schedule)
-
Theater
public Theater()
-
-
Method Detail
-
name
public final String name()
-
parallelism
public final int parallelism()
-
schedule
public final Schedule schedule()
-
setSchedule
public void setSchedule(Schedule schedule)
-
start
public void start()
Ensures that thisTheater
is up and running.- Specified by:
start
in interfaceMainStage
- Throws:
IllegalStateException
- if thisTheater
has been stopped.
-
stop
public void stop()
Ensures that thisTheater
has been permanently stopped, shutting down the thread pool, if it's currently running. Upon return, thisTheater
is guaranteed to be in the stopped state.
-
execute
public void execute(Runnable runnable)
Description copied from interface:Stage
Schedules arunnable
for concurrent execution.
-
task
public TaskRef task(TaskFunction task)
Description copied from interface:Stage
Returns an uncuedTaskRef
bound to thetask
, which can later be used to cue thetask
.
-
call
public <T> Call<T> call(Cont<T> cont)
Description copied from interface:Stage
Returns aCall
that completes thecont
inuation.
-
timer
public TimerRef timer(TimerFunction timer)
Description copied from interface:Schedule
Returns an unscheduledTimerRef
bound totimer
, which can later be used to scheduletimer
.
-
setTimer
public TimerRef setTimer(long millis, TimerFunction timer)
Description copied from interface:Schedule
Schedulestimer
to execute aftermillis
milliseconds have elapsed. Returns aTimerRef
that can be used to check the status of, reschedule, and canceltimer
.
-
didStart
protected void didStart()
Lifecycle callback invoked before the thread pool starts up.
-
didStop
protected void didStop()
Lifecycle callback invoked after the thread pool shuts down.
-
didFail
protected void didFail(Throwable error)
Lifecycle callback invoked if thisTheater
encounters an internalerror
.
-
taskWillCue
protected void taskWillCue(TaskFunction task)
Introspection callback invoked before atask
is cued for execution.
-
taskDidCancel
protected void taskDidCancel(TaskFunction task)
Introspection callback invoked after a cuedtask
is canceled.
-
taskWillRun
protected void taskWillRun(TaskFunction task)
Introspection callback invoked immediately beforetask.runTask()
is executed.
-
taskDidRun
protected void taskDidRun(TaskFunction task)
Introspection callback invoked immediately aftertask.runTask()
returns nominally.
-
taskDidFail
protected void taskDidFail(TaskFunction task, Throwable error)
Introspection callback invoked immediately aftertask.runTask()
fails by throwing anerror
.
-
callWillCue
protected void callWillCue(Cont<?> cont)
Introspection callback invoked before acont
call is cued for execution.
-
callWillBind
protected <T> void callWillBind(Cont<T> cont, T value)
Introspection callback invoked immediately before a call tocont.bind(value)
.
-
callDidBind
protected <T> void callDidBind(Cont<?> cont, T value)
Introspection callback invoked immediately after a call tocont.bind(value)
returns nominally.
-
callWillTrap
protected void callWillTrap(Cont<?> cont, Throwable error)
Introspection callback invoked immediately before a call tocont.trap(error)
.
-
callDidTrap
protected void callDidTrap(Cont<?> cont, Throwable error)
Introspection callback invoked immediately after a call tocont.trap(error)
returns nominally.
-
callDidFail
protected void callDidFail(Cont<?> cont, Throwable error)
Introspection callback invoked immediately after a call tocont.bind(T)
fails by throwing anerror
.
-
uncaughtException
public void uncaughtException(Thread thead, Throwable error)
- Specified by:
uncaughtException
in interfaceThread.UncaughtExceptionHandler
-
-