Class MdcScheduledExecutorService
java.lang.Object
com.sportradar.unifiedodds.sdk.internal.impl.util.MdcScheduledExecutorService
- All Implemented Interfaces:
Executor,ExecutorService,ScheduledExecutorService
-
Constructor Summary
ConstructorsConstructorDescriptionMdcScheduledExecutorService(ScheduledExecutorService scheduledExecutor, Map<String, String> fixedContext) Initializes a new instance of theMdcScheduledExecutorServiceclass -
Method Summary
Modifier and TypeMethodDescriptionbooleanawaitTermination(long timeout, TimeUnit unit) Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.voidExecutes the given command at some time in the future.invokeAll(Collection<? extends Callable<T>> tasks) Executes the given tasks, returning a list of Futures holding their status and results when all complete.invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) Executes the given tasks, returning a list of Futures holding their status and results when all complete or the timeout expires, whichever happens first.<T> TinvokeAny(Collection<? extends Callable<T>> tasks) Executes the given tasks, returning the result of one that has completed successfully (i.e., without throwing an exception), if any do.<T> TinvokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) Executes the given tasks, returning the result of one that has completed successfully (i.e., without throwing an exception), if any do before the given timeout elapses.booleanReturns true if this executor has been shut down.booleanReturns true if all tasks have completed following shut down.Creates and executes a one-shot action that becomes enabled after the given delay.<V> ScheduledFuture<V>Creates and executes a ScheduledFuture that becomes enabled after the given delay.scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period; that is executions will commence after initialDelay then initialDelay+period, then initialDelay + 2 * period, and so on.scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given delay between the termination of one execution and the commencement of the next.voidshutdown()Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.Future<?>Submits a Runnable task for execution and returns a Future representing that task.<T> Future<T>Submits a Runnable task for execution and returns a Future representing that task.<T> Future<T>Submits a value-returning task for execution and returns a Future representing the pending results of the task.
-
Constructor Details
-
MdcScheduledExecutorService
public MdcScheduledExecutorService(ScheduledExecutorService scheduledExecutor, Map<String, String> fixedContext) Initializes a new instance of theMdcScheduledExecutorServiceclass- Parameters:
scheduledExecutor- AScheduledExecutorServicewrapped by the currentMdcScheduledExecutorServiceinstancefixedContext- The MDC fixed context used by current executor
-
-
Method Details
-
schedule
Creates and executes a one-shot action that becomes enabled after the given delay.- Specified by:
schedulein interfaceScheduledExecutorService- Parameters:
command- the task to executedelay- the time from now to delay executionunit- the time unit of the delay parameter- Returns:
- a ScheduledFuture representing pending completion of the task and whose get() method will return null upon completion
- Throws:
RejectedExecutionException- if the task cannot be scheduled for executionNullPointerException- if command is null
-
schedule
Creates and executes a ScheduledFuture that becomes enabled after the given delay.- Specified by:
schedulein interfaceScheduledExecutorService- Parameters:
callable- the function to executedelay- the time from now to delay executionunit- the time unit of the delay parameter- Returns:
- a ScheduledFuture that can be used to extract result or cancel
- Throws:
RejectedExecutionException- if the task cannot be scheduled for executionNullPointerException- if callable is null
-
scheduleAtFixedRate
public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period; that is executions will commence after initialDelay then initialDelay+period, then initialDelay + 2 * period, and so on. If any execution of the task encounters an exception, subsequent executions are suppressed. Otherwise, the task will only terminate via cancellation or termination of the executor. If any execution of this task takes longer than its period, then subsequent executions may start late, but will not concurrently execute.- Specified by:
scheduleAtFixedRatein interfaceScheduledExecutorService- Parameters:
command- the task to executeinitialDelay- the time to delay first executionperiod- the period between successive executionsunit- the time unit of the initialDelay and period parameters- Returns:
- a ScheduledFuture representing pending completion of the task, and whose get() method will throw an exception upon cancellation
- Throws:
RejectedExecutionException- if the task cannot be scheduled for executionNullPointerException- if command is nullIllegalArgumentException- if period less than or equal to zero
-
scheduleWithFixedDelay
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given delay between the termination of one execution and the commencement of the next. If any execution of the task encounters an exception, subsequent executions are suppressed. Otherwise, the task will only terminate via cancellation or termination of the executor.- Specified by:
scheduleWithFixedDelayin interfaceScheduledExecutorService- Parameters:
command- the task to executeinitialDelay- the time to delay first executiondelay- the delay between the termination of one execution and the commencement of the nextunit- the time unit of the initialDelay and delay parameters- Returns:
- a ScheduledFuture representing pending completion of the task, and whose get() method will throw an exception upon cancellation
- Throws:
RejectedExecutionException- if the task cannot be scheduled for executionNullPointerException- if command is nullIllegalArgumentException- if delay less than or equal to zero
-
shutdown
public void shutdown()Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted. Invocation has no additional effect if already shut down.This method does not wait for previously submitted tasks to complete execution. Use
awaitTerminationto do that.- Specified by:
shutdownin interfaceExecutorService- Throws:
SecurityException- if a security manager exists and shutting down this ExecutorService may manipulate threads that the caller is not permitted to modify because it does not holdRuntimePermission("modifyThread"), or the security manager's checkAccess method denies access.
-
shutdownNow
Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.This method does not wait for actively executing tasks to terminate. Use
awaitTerminationto do that.There are no guarantees beyond best-effort attempts to stop processing actively executing tasks. For example, typical implementations will cancel via
Thread.interrupt(), so any task that fails to respond to interrupts may never terminate.- Specified by:
shutdownNowin interfaceExecutorService- Returns:
- list of tasks that never commenced execution
- Throws:
SecurityException- if a security manager exists and shutting down this ExecutorService may manipulate threads that the caller is not permitted to modify because it does not holdRuntimePermission("modifyThread"), or the security manager's checkAccess method denies access.
-
isShutdown
public boolean isShutdown()Returns true if this executor has been shut down.- Specified by:
isShutdownin interfaceExecutorService- Returns:
- true if this executor has been shut down
-
isTerminated
public boolean isTerminated()Returns true if all tasks have completed following shut down. Note that isTerminated is never true unless either shutdown or shutdownNow was called first.- Specified by:
isTerminatedin interfaceExecutorService- Returns:
- true if all tasks have completed following shut down
-
awaitTermination
Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.- Specified by:
awaitTerminationin interfaceExecutorService- Parameters:
timeout- the maximum time to waitunit- the time unit of the timeout argument- Returns:
- true if this executor terminated and false if the timeout elapsed before termination
- Throws:
InterruptedException- if interrupted while waiting
-
submit
Submits a value-returning task for execution and returns a Future representing the pending results of the task. The Future's get method will return the task's result upon successful completion. If you would like to immediately block waiting for a task, you can use constructions of the form result = exec.submit(aCallable).get();Note: The
Executorsclass includes a set of methods that can convert some other common closure-like objects, for example,PrivilegedActiontoCallableform so they can be submitted.- Specified by:
submitin interfaceExecutorService- Parameters:
task- the task to submit- Returns:
- a Future representing pending completion of the task
- Throws:
RejectedExecutionException- if the task cannot be scheduled for executionNullPointerException- if the task is null
-
submit
Submits a Runnable task for execution and returns a Future representing that task. The Future's get method will return the given result upon successful completion.- Specified by:
submitin interfaceExecutorService- Parameters:
task- the task to submitresult- the result to return- Returns:
- a Future representing pending completion of the task
- Throws:
RejectedExecutionException- if the task cannot be scheduled for executionNullPointerException- if the task is null
-
submit
Submits a Runnable task for execution and returns a Future representing that task. The Future's get method will return null upon successful completion.- Specified by:
submitin interfaceExecutorService- Parameters:
task- the task to submit- Returns:
- a Future representing pending completion of the task
- Throws:
RejectedExecutionException- if the task cannot be scheduled for executionNullPointerException- if the task is null
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException Executes the given tasks, returning a list of Futures holding their status and results when all complete.Future.isDone()is true for each element of the returned list. Note that a completed task could have terminated either normally or by throwing an exception. The results of this method are undefined if the given collection is modified while this operation is in progress.- Specified by:
invokeAllin interfaceExecutorService- Parameters:
tasks- the collection of tasks- Returns:
- A list of Futures representing the tasks, in the same sequential order as produced by the iterator for the given task list, each of which has completed.
- Throws:
InterruptedException- if interrupted while waiting, in which case unfinished tasks are cancelled.NullPointerException- if tasks or any of its elements are nullRejectedExecutionException- if any task cannot be scheduled for execution
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException Executes the given tasks, returning a list of Futures holding their status and results when all complete or the timeout expires, whichever happens first.Future.isDone()is true for each element of the returned list. Upon return, tasks that have not completed are cancelled. Note that a completed task could have terminated either normally or by throwing an exception. The results of this method are undefined if the given collection is modified while this operation is in progress.- Specified by:
invokeAllin interfaceExecutorService- Parameters:
tasks- the collection of taskstimeout- the maximum time to waitunit- the time unit of the timeout argument- Returns:
- a list of Futures representing the tasks, in the same sequential order as produced by the iterator for the given task list. If the operation did not time out, each task will have completed. If it did time out, some of these tasks will not have completed.
- Throws:
InterruptedException- if interrupted while waiting, in which case unfinished tasks are cancelledNullPointerException- if tasks, any of its elements, or unit are nullRejectedExecutionException- if any task cannot be scheduled for execution
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException Executes the given tasks, returning the result of one that has completed successfully (i.e., without throwing an exception), if any do. Upon normal or exceptional return, tasks that have not completed are cancelled. The results of this method are undefined if the given collection is modified while this operation is in progress.- Specified by:
invokeAnyin interfaceExecutorService- Parameters:
tasks- the collection of tasks- Returns:
- the result returned by one of the tasks
- Throws:
InterruptedException- if interrupted while waitingNullPointerException- if tasks or any element task subject to execution is nullIllegalArgumentException- if tasks is emptyExecutionException- if no task successfully completesRejectedExecutionException- if tasks cannot be scheduled for execution
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException Executes the given tasks, returning the result of one that has completed successfully (i.e., without throwing an exception), if any do before the given timeout elapses. Upon normal or exceptional return, tasks that have not completed are cancelled. The results of this method are undefined if the given collection is modified while this operation is in progress.- Specified by:
invokeAnyin interfaceExecutorService- Parameters:
tasks- the collection of taskstimeout- the maximum time to waitunit- the time unit of the timeout argument- Returns:
- the result returned by one of the tasks.
- Throws:
InterruptedException- if interrupted while waitingNullPointerException- if tasks, or unit, or any element task subject to execution is nullTimeoutException- if the given timeout elapses before any task successfully completesExecutionException- if no task successfully completesRejectedExecutionException- if tasks cannot be scheduled for execution
-
execute
Executes the given command at some time in the future. The command may execute in a new thread, in a pooled thread, or in the calling thread, at the discretion of the Executor implementation.- Specified by:
executein interfaceExecutor- Parameters:
command- the runnable task- Throws:
RejectedExecutionException- if this task cannot be accepted for execution.NullPointerException- if command is null
-