- java.lang.Object
-
- swim.concurrent.Theater
-
- All Implemented Interfaces:
Thread.UncaughtExceptionHandler,Executor,MainStage,Schedule,Stage
public class Theater extends Object implements MainStage, Thread.UncaughtExceptionHandler
Stagethat 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 aCallthat completes thecontinuation.protected <T> voidcallDidBind(Cont<?> cont, T value)Introspection callback invoked immediately after a call tocont.bind(value)returns nominally.protected voidcallDidFail(Cont<?> cont, Throwable error)Introspection callback invoked immediately after a call tocont.bind(T)fails by throwing anerror.protected voidcallDidTrap(Cont<?> cont, Throwable error)Introspection callback invoked immediately after a call tocont.trap(error)returns nominally.protected <T> voidcallWillBind(Cont<T> cont, T value)Introspection callback invoked immediately before a call tocont.bind(value).protected voidcallWillCue(Cont<?> cont)Introspection callback invoked before acontcall is cued for execution.protected voidcallWillTrap(Cont<?> cont, Throwable error)Introspection callback invoked immediately before a call tocont.trap(error).protected voiddidFail(Throwable error)Lifecycle callback invoked if thisTheaterencounters an internalerror.protected voiddidStart()Lifecycle callback invoked before the thread pool starts up.protected voiddidStop()Lifecycle callback invoked after the thread pool shuts down.voidexecute(Runnable runnable)Schedules arunnablefor concurrent execution.Stringname()intparallelism()Scheduleschedule()voidsetSchedule(Schedule schedule)TimerRefsetTimer(long millis, TimerFunction timer)Schedulestimerto execute aftermillismilliseconds have elapsed.voidstart()Ensures that thisTheateris up and running.voidstop()Ensures that thisTheaterhas been permanently stopped, shutting down the thread pool, if it's currently running.TaskReftask(TaskFunction task)Returns an uncuedTaskRefbound to thetask, which can later be used to cue thetask.protected voidtaskDidCancel(TaskFunction task)Introspection callback invoked after a cuedtaskis canceled.protected voidtaskDidFail(TaskFunction task, Throwable error)Introspection callback invoked immediately aftertask.runTask()fails by throwing anerror.protected voidtaskDidRun(TaskFunction task)Introspection callback invoked immediately aftertask.runTask()returns nominally.protected voidtaskWillCue(TaskFunction task)Introspection callback invoked before ataskis cued for execution.protected voidtaskWillRun(TaskFunction task)Introspection callback invoked immediately beforetask.runTask()is executed.TimerReftimer(TimerFunction timer)Returns an unscheduledTimerRefbound totimer, which can later be used to scheduletimer.voiduncaughtException(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 thisTheateris up and running.- Specified by:
startin interfaceMainStage- Throws:
IllegalStateException- if thisTheaterhas been stopped.
-
stop
public void stop()
Ensures that thisTheaterhas been permanently stopped, shutting down the thread pool, if it's currently running. Upon return, thisTheateris guaranteed to be in the stopped state.
-
execute
public void execute(Runnable runnable)
Description copied from interface:StageSchedules arunnablefor concurrent execution.
-
task
public TaskRef task(TaskFunction task)
Description copied from interface:StageReturns an uncuedTaskRefbound to thetask, which can later be used to cue thetask.
-
call
public <T> Call<T> call(Cont<T> cont)
Description copied from interface:StageReturns aCallthat completes thecontinuation.
-
timer
public TimerRef timer(TimerFunction timer)
Description copied from interface:ScheduleReturns an unscheduledTimerRefbound totimer, which can later be used to scheduletimer.
-
setTimer
public TimerRef setTimer(long millis, TimerFunction timer)
Description copied from interface:ScheduleSchedulestimerto execute aftermillismilliseconds have elapsed. Returns aTimerRefthat 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 thisTheaterencounters an internalerror.
-
taskWillCue
protected void taskWillCue(TaskFunction task)
Introspection callback invoked before ataskis cued for execution.
-
taskDidCancel
protected void taskDidCancel(TaskFunction task)
Introspection callback invoked after a cuedtaskis 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 acontcall 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:
uncaughtExceptionin interfaceThread.UncaughtExceptionHandler
-
-