Interface JobScheduler
- All Known Implementing Classes:
ImmediateJobScheduler,OperationInitializerJobScheduler,UpdateGraphJobScheduler
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceHelper interface foriterateSerial()anditerateParallel().static interfaceHelper interface foriterateSerial(io.deephaven.engine.context.ExecutionContext, io.deephaven.base.log.LogOutputAppendable, java.util.function.Supplier<CONTEXT_TYPE>, int, int, io.deephaven.engine.table.impl.util.JobScheduler.IterateResumeAction<CONTEXT_TYPE>, java.lang.Runnable, java.lang.Runnable, java.util.function.Consumer<java.lang.Exception>)anditerateParallel(io.deephaven.engine.context.ExecutionContext, io.deephaven.base.log.LogOutputAppendable, java.util.function.Supplier<CONTEXT_TYPE>, int, int, io.deephaven.engine.table.impl.util.JobScheduler.IterateAction<CONTEXT_TYPE>, java.lang.Runnable, java.lang.Runnable, java.util.function.Consumer<java.lang.Exception>).static final classstatic interfaceA default context for the scheduled job actions. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final JobScheduler.JobThreadContextstatic final Supplier<JobScheduler.JobThreadContext> static final ExceptionDelivered when a job fails with anErrorand even the wrapper for it cannot be allocated, which is to say when the heap is exhausted — the very failure this path exists for. -
Method Summary
Modifier and TypeMethodDescriptionstatic ExceptionasDeliverableException(@NotNull Throwable throwable) Convert a Throwable that escaped a scheduled job into something theConsumer<Exception>error handlers used throughout the scheduler can accept.The performance statistics of all runnables that have been completed off-thread, or null if all were executed in the current thread.default <CONTEXT_TYPE extends JobScheduler.JobThreadContext>
voiditerateParallel(@Nullable ExecutionContext executionContext, @Nullable LogOutputAppendable description, @NotNull Supplier<CONTEXT_TYPE> taskThreadContextFactory, int start, int count, @NotNull JobScheduler.IterateAction<CONTEXT_TYPE> action, @NotNull Runnable onComplete, @NotNull Runnable cleanup, @NotNull Consumer<Exception> onError) Provides a mechanism to iterate over a range of values in parallel using theJobSchedulerdefault <CONTEXT_TYPE extends JobScheduler.JobThreadContext>
voiditerateParallel(@Nullable ExecutionContext executionContext, @Nullable LogOutputAppendable description, @NotNull Supplier<CONTEXT_TYPE> taskThreadContextFactory, int start, int count, @NotNull JobScheduler.IterateResumeAction<CONTEXT_TYPE> action, @NotNull Runnable onComplete, @NotNull Runnable cleanup, @NotNull Consumer<Exception> onError) Provides a mechanism to iterate over a range of values in parallel using theJobScheduler.default <CONTEXT_TYPE extends JobScheduler.JobThreadContext>
voiditerateSerial(@Nullable ExecutionContext executionContext, @Nullable LogOutputAppendable description, @NotNull Supplier<CONTEXT_TYPE> taskThreadContextFactory, int start, int count, @NotNull JobScheduler.IterateResumeAction<CONTEXT_TYPE> action, @NotNull Runnable onComplete, @NotNull Runnable cleanup, @NotNull Consumer<Exception> onError) Provides a mechanism to iterate over a range of values serially using theJobScheduler.voidsubmit(ExecutionContext executionContext, Runnable runnable, LogOutputAppendable description, Consumer<Exception> onError) Cause runnable to be executed.intHow many threads exist in the job scheduler? The job submitters can use this value to determine how many sub-jobs to split work into.
-
Field Details
-
DEFAULT_CONTEXT
-
DEFAULT_CONTEXT_FACTORY
-
UNREPORTABLE_JOB_ERROR
Delivered when a job fails with anErrorand even the wrapper for it cannot be allocated, which is to say when the heap is exhausted — the very failure this path exists for. Allocated once, when this interface is initialized, so that delivering a failure never depends on being able to allocate.
-
-
Method Details
-
asDeliverableException
Convert a Throwable that escaped a scheduled job into something theConsumer<Exception>error handlers used throughout the scheduler can accept. Exceptions pass through unchanged; anError— anOutOfMemoryError, in practice — is wrapped, so that the thread waiting on the job's completion fails with a diagnostic instead of waiting forever for a completion that cannot happen.This never throws. The wrapper carries no stack trace of its own: filling one in is the largest allocation here, and the stack that matters belongs to the Error, which is kept as the cause. Should even that allocation fail,
UNREPORTABLE_JOB_ERRORis delivered instead — a caller that fails without a diagnostic is still far better than one that waits forever.- Parameters:
throwable- the Throwable that escaped the job- Returns:
throwableitself if it is an Exception, otherwise a wrapper holding it as its cause
-
submit
void submit(ExecutionContext executionContext, Runnable runnable, LogOutputAppendable description, Consumer<Exception> onError) Cause runnable to be executed.- Parameters:
executionContext- the execution context to run it underrunnable- the runnable to executedescription- a description for loggingonError- a routine to call if an exception occurs while running runnable
-
getAccumulatedPerformance
BasePerformanceEntry getAccumulatedPerformance()The performance statistics of all runnables that have been completed off-thread, or null if all were executed in the current thread.When initializing an operation, the
OperationInitializerJobSchedulerexecutes the completion callback as part of another task. Therefore, you must not read the accumulated performance from the completion callback when initializing an operation; as it could miss data from some of the tasks. Furthermore, even though the completion callback identifies the result as ready does not mean that the completion callback has actually completed. To guard against this theOperationInitializerJobSchedulerwaits for all jobs to be complete before returning theBasePerformanceEntry. Therefore, if you call this from a completion callback, then the operation will hang. -
threadCount
int threadCount()How many threads exist in the job scheduler? The job submitters can use this value to determine how many sub-jobs to split work into. -
iterateParallel
@FinalDefault default <CONTEXT_TYPE extends JobScheduler.JobThreadContext> void iterateParallel(@Nullable @Nullable ExecutionContext executionContext, @Nullable @Nullable LogOutputAppendable description, @NotNull @NotNull Supplier<CONTEXT_TYPE> taskThreadContextFactory, int start, int count, @NotNull @NotNull JobScheduler.IterateAction<CONTEXT_TYPE> action, @NotNull @NotNull Runnable onComplete, @NotNull @NotNull Runnable cleanup, @NotNull @NotNull Consumer<Exception> onError) Provides a mechanism to iterate over a range of values in parallel using theJobScheduler- Parameters:
executionContext- the execution context for this taskdescription- the description to use for loggingtaskThreadContextFactory- the factory that suppliescontextsfor the threads handling the sub-tasksstart- the integer value from which to start iteratingcount- the number of times this task should be calledaction- the task to perform, the current iteration index is provided as a parameteronComplete- this will be called when all iterations are completecleanup- called after onComplete successfully returns. If the invocation of the cleanup throws an exception, onError will not be called.onError- error handler for the scheduler to use while iterating, or if onComplete throws an exception.
-
iterateParallel
@FinalDefault default <CONTEXT_TYPE extends JobScheduler.JobThreadContext> void iterateParallel(@Nullable @Nullable ExecutionContext executionContext, @Nullable @Nullable LogOutputAppendable description, @NotNull @NotNull Supplier<CONTEXT_TYPE> taskThreadContextFactory, int start, int count, @NotNull @NotNull JobScheduler.IterateResumeAction<CONTEXT_TYPE> action, @NotNull @NotNull Runnable onComplete, @NotNull @NotNull Runnable cleanup, @NotNull @NotNull Consumer<Exception> onError) Provides a mechanism to iterate over a range of values in parallel using theJobScheduler. The advantage to using this over the other method is the resumption callable onactionthat will trigger the next execution. This allows the next iteration and the completion runnable to be delayed until dependent asynchronous serial or parallel scheduler jobs have completed.- Parameters:
executionContext- the execution context for this taskdescription- the description to use for loggingtaskThreadContextFactory- the factory that suppliescontextsfor the tasksstart- the integer value from which to start iteratingcount- the number of times this task should be calledaction- the task to perform, the current iteration index and a resume Runnable are parametersonComplete- this will be called when all iterations are completecleanup- called after onComplete successfully returns. If the invocation of the cleanup throws an exception, onError will not be called.onError- error handler for the scheduler to use while iterating, or if onComplete throws an exception.
-
iterateSerial
@FinalDefault default <CONTEXT_TYPE extends JobScheduler.JobThreadContext> void iterateSerial(@Nullable @Nullable ExecutionContext executionContext, @Nullable @Nullable LogOutputAppendable description, @NotNull @NotNull Supplier<CONTEXT_TYPE> taskThreadContextFactory, int start, int count, @NotNull @NotNull JobScheduler.IterateResumeAction<CONTEXT_TYPE> action, @NotNull @NotNull Runnable onComplete, @NotNull @NotNull Runnable cleanup, @NotNull @NotNull Consumer<Exception> onError) Provides a mechanism to iterate over a range of values serially using theJobScheduler. The advantage to using this over a simple iteration is the resumption callable onactionthat will trigger the next execution. This allows the next iteration and the completion runnable to be delayed until dependent asynchronous serial or parallel scheduler jobs have completed.- Parameters:
executionContext- the execution context for this taskdescription- the description to use for loggingtaskThreadContextFactory- the factory that suppliescontextsfor the tasksstart- the integer value from which to start iteratingcount- the number of times this task should be calledaction- the task to perform, the current iteration index and a resume Runnable are parametersonComplete- this will be called when all iterations are completecleanup- called after onComplete successfully returns. If the invocation of the cleanup throws an exception, onError will not be called.onError- error handler for the scheduler to use while iterating, or if onComplete throws an exception.
-