Package sonia.scm.repository.spi
Interface SyncAsyncExecutor
public interface SyncAsyncExecutor
Tasks submitted to this executor will be run synchronously up to a given time, after which they will be queued and
processed asynchronously. After a maximum amount of time consumed by these tasks, they will be skipped. Note that
this only works for short-living tasks.
Get instances of this using a SyncAsyncExecutorProvider
.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptiondefault SyncAsyncExecutor.ExecutionType
Execute the given task (either synchronously or asynchronously).default SyncAsyncExecutor.ExecutionType
Execute the giventask
(either synchronously or asynchronously).default SyncAsyncExecutor.ExecutionType
Execute the giventask
(either synchronously or asynchronously).execute
(Consumer<SyncAsyncExecutor.ExecutionType> task, Runnable abortionFallback) Execute the giventask
(either synchronously or asynchronously).boolean
When all submitted tasks have been executed synchronously, this will returntrue
.
-
Method Details
-
execute
Execute the given task (either synchronously or asynchronously). If this task is skipped due to timeouts, nothing will be done.- Parameters:
task
- TheRunnable
to be executed.- Returns:
- Either
SyncAsyncExecutor.ExecutionType.SYNCHRONOUS
when the givenRunnable
has been executed immediately orSyncAsyncExecutor.ExecutionType.ASYNCHRONOUS
, when the task was queued to be executed asynchronously in the future.
-
execute
Execute the giventask
(either synchronously or asynchronously). If this task is skipped due to timeouts, theabortionFallback
will be called.- Parameters:
task
- TheRunnable
to be executed.abortionFallback
- This will only be run, when this and all remaining tasks are aborted. This task should only consume a negligible amount of time.- Returns:
- Either
SyncAsyncExecutor.ExecutionType.SYNCHRONOUS
when the givenRunnable
has been executed immediately orSyncAsyncExecutor.ExecutionType.ASYNCHRONOUS
, when the task was queued to be executed asynchronously in the future.
-
execute
Execute the giventask
(either synchronously or asynchronously). If this task is skipped due to timeouts, nothing will be done.- Parameters:
task
- TheConsumer
to be executed. The parameter given to this is eitherSyncAsyncExecutor.ExecutionType.SYNCHRONOUS
when the givenConsumer
is executed immediately orSyncAsyncExecutor.ExecutionType.ASYNCHRONOUS
, when the task had been queued and now is executed asynchronously.- Returns:
- Either
SyncAsyncExecutor.ExecutionType.SYNCHRONOUS
when the givenRunnable
has been executed immediately orSyncAsyncExecutor.ExecutionType.ASYNCHRONOUS
, when the task was queued to be executed asynchronously in the future.
-
execute
SyncAsyncExecutor.ExecutionType execute(Consumer<SyncAsyncExecutor.ExecutionType> task, Runnable abortionFallback) Execute the giventask
(either synchronously or asynchronously). If this task is skipped due to timeouts, theabortionFallback
will be called.- Parameters:
task
- TheConsumer
to be executed. The parameter given to this is eitherSyncAsyncExecutor.ExecutionType.SYNCHRONOUS
when the givenConsumer
is executed immediately orSyncAsyncExecutor.ExecutionType.ASYNCHRONOUS
, when the task had been queued and now is executed asynchronously.abortionFallback
- This will only be run, when this and all remaining tasks are aborted. This task should only consume a negligible amount of time.- Returns:
- Either
SyncAsyncExecutor.ExecutionType.SYNCHRONOUS
when the givenRunnable
has been executed immediately orSyncAsyncExecutor.ExecutionType.ASYNCHRONOUS
, when the task was queued to be executed asynchronously in the future.
-
hasExecutedAllSynchronously
boolean hasExecutedAllSynchronously()When all submitted tasks have been executed synchronously, this will returntrue
. If at least one task has been enqueued to be executed asynchronously, this returnsfalse
(even when none of the enqueued tasks have been run, yet).
-