Top Description Inners Fields Constructors Methods
reactor.core.scheduler

pack-priv final Class ExecutorScheduler

extends Object
implements Scheduler, Scannable
Class Inheritance
All Implemented Interfaces
reactor.core.Scannable, reactor.core.scheduler.Scheduler, reactor.core.Disposable
Imports
java.util.Objects, .Queue, java.util.concurrent.ConcurrentLinkedQueue, .Executor, .ExecutorService, java.util.concurrent.atomic.AtomicBoolean, .AtomicIntegerFieldUpdater, reactor.core.Disposable, .Disposables, .Exceptions, .Scannable, reactor.util.annotation.Nullable

Wraps a java.util.concurrent.Executor and provides the Scheduler API over it.

It supports both non-trampolined worker (for cases where the trampolining happens externally) and trampolined worker. This scheduler is NOT time-capable (can't schedule with delay / periodically).

Author
Stephane Maldini

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
ExecutorScheduler.ExecutorPlainRunnable

A non-tracked runnable that wraps a task and offers cancel support in the form of not executing the task.

pack-priv static class
ExecutorScheduler.ExecutorSchedulerTrampolineWorker

A trampolining worker that tracks tasks.

pack-priv static class
ExecutorScheduler.ExecutorSchedulerWorker

A non-trampolining worker that tracks tasks.

pack-priv static class
ExecutorScheduler.ExecutorTrackedRunnable

A Runnable that wraps a task and has reference back to its parent worker to remove itself once completed or cancelled

pack-priv static interface
ExecutorScheduler.WorkerDelete

Common interface between the tracking workers to signal the need for removal.

Field Summary

Modifier and TypeField and Description
pack-priv final Executor
pack-priv volatile boolean
pack-priv final boolean

Constructor Summary

AccessConstructor and Description
pack-priv
ExecutorScheduler(Executor executor, boolean trampoline)

Method Summary

Modifier and TypeMethod and Description
public Scheduler.Worker
createWorker()

Implements reactor.core.scheduler.Scheduler.createWorker.

Creates a worker of this Scheduler.
public void
dispose()

Overrides default reactor.core.scheduler.Scheduler.dispose.

Instructs this Scheduler to release all resources and reject any new tasks to be executed.
public boolean
isDisposed()

Overrides default reactor.core.Disposable.isDisposed.

Optionally return true when the resource or task is disposed.
public Object
scanUnsafe(Scannable.Attr<T>
a Attr to resolve for the component.
key
)

Implements reactor.core.Scannable.scanUnsafe.

This method is used internally by components to define their key-value mappings in a single place.
public Disposable
schedule(Runnable
the task to execute
task
)

Implements reactor.core.scheduler.Scheduler.schedule.

Schedules the non-delayed execution of the given task on this scheduler.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

executorback to summary
pack-priv final Executor executor
terminatedback to summary
pack-priv volatile boolean terminated
trampolineback to summary
pack-priv final boolean trampoline

Constructor Detail

ExecutorSchedulerback to summary
pack-priv ExecutorScheduler(Executor executor, boolean trampoline)

Method Detail

createWorkerback to summary
public Scheduler.Worker createWorker()

Implements reactor.core.scheduler.Scheduler.createWorker.

Doc from reactor.core.scheduler.Scheduler.createWorker.

Creates a worker of this Scheduler.

Once the Worker is no longer in use, one should call dispose() on it to release any resources the particular Scheduler may have used. It depends on the implementation, but Scheduler Workers should usually run tasks in FIFO order. Some implementations may entirely delegate the scheduling to an underlying structure (like an ExecutorService).

Returns:Scheduler.Worker

the Worker instance.

Annotations
@Override
disposeback to summary
public void dispose()

Overrides default reactor.core.scheduler.Scheduler.dispose.

Doc from reactor.core.scheduler.Scheduler.dispose.

Instructs this Scheduler to release all resources and reject any new tasks to be executed.

The operation is thread-safe.

The Scheduler may choose to ignore this instruction.

When used in combination with disposeGracefully() there are no guarantees that all resources will be forcefully shutdown. When a graceful disposal has started, the references to the underlying java.util.concurrent.Executors might have already been lost.

Annotations
@Override
isDisposedback to summary
public boolean isDisposed()

Overrides default reactor.core.Disposable.isDisposed.

Doc from reactor.core.Disposable.isDisposed.

Optionally return true when the resource or task is disposed.

Implementations are not required to track disposition and as such may never return true even when disposed. However, they MUST only return true when there's a guarantee the resource or task is disposed.

Returns:boolean

true when there's a guarantee the resource or task is disposed.

Annotations
@Override
scanUnsafeback to summary
public Object scanUnsafe(Scannable.Attr<T> key)

Implements reactor.core.Scannable.scanUnsafe.

Doc from reactor.core.Scannable.scanUnsafe.

This method is used internally by components to define their key-value mappings in a single place. Although it is ignoring the generic type of the Attr key, implementors should take care to return values of the correct type, and return null if no specific value is available.

For public consumption of attributes, prefer using scan(Attr), which will return a typed value and fall back to the key's default if the component didn't define any mapping.

Parameters
key:Scannable.Attr<T>

a Attr to resolve for the component.

Returns:Object

the value associated to the key for that specific component, or null if none.

Annotations
@Override
scheduleback to summary
public Disposable schedule(Runnable task)

Implements reactor.core.scheduler.Scheduler.schedule.

Doc from reactor.core.scheduler.Scheduler.schedule.

Schedules the non-delayed execution of the given task on this scheduler.

This method is safe to be called from multiple threads but there are no ordering guarantees between tasks.

Parameters
task:Runnable

the task to execute

Returns:Disposable

the Disposable instance that let's one cancel this particular task. If the Scheduler has been shut down, throw a RejectedExecutionException.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
reactor.core.scheduler back to summary

pack-priv final Class ExecutorScheduler.ExecutorPlainRunnable

extends AtomicBoolean
implements Runnable, Disposable
Class Inheritance
All Implemented Interfaces
reactor.core.Disposable, java.lang.Runnable

A non-tracked runnable that wraps a task and offers cancel support in the form of not executing the task.

Since Executor doesn't have cancellation support of its own, the ExecutorRunnable will stay in the Executor's queue and be always executed.

Field Summary

Modifier and TypeField and Description
private static final long
pack-priv final Runnable

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
dispose()

Implements reactor.core.Disposable.dispose.

Cancel or dispose the underlying task or resource.
public boolean
isDisposed()

Overrides default reactor.core.Disposable.isDisposed.

Optionally return true when the resource or task is disposed.
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.
Inherited from java.util.concurrent.atomic.AtomicBoolean:
compareAndExchangecompareAndExchangeAcquirecompareAndExchangeReleasecompareAndSetgetgetAcquiregetAndSetgetOpaquegetPlainlazySetsetsetOpaquesetPlainsetReleasetoStringweakCompareAndSetweakCompareAndSetAcquireweakCompareAndSetPlainweakCompareAndSetReleaseweakCompareAndSetVolatile

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.util.concurrent.atomic.AtomicBoolean.serialVersionUID.

taskback to summary
pack-priv final Runnable task

Constructor Detail

ExecutorPlainRunnableback to summary
pack-priv ExecutorPlainRunnable(Runnable task)

Method Detail

disposeback to summary
public void dispose()

Implements reactor.core.Disposable.dispose.

Doc from reactor.core.Disposable.dispose.

Cancel or dispose the underlying task or resource.

Implementations are required to make this method idempotent.

Annotations
@Override
isDisposedback to summary
public boolean isDisposed()

Overrides default reactor.core.Disposable.isDisposed.

Doc from reactor.core.Disposable.isDisposed.

Optionally return true when the resource or task is disposed.

Implementations are not required to track disposition and as such may never return true even when disposed. However, they MUST only return true when there's a guarantee the resource or task is disposed.

Returns:boolean

true when there's a guarantee the resource or task is disposed.

Annotations
@Override
runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override
reactor.core.scheduler back to summary

pack-priv final Class ExecutorScheduler.ExecutorSchedulerTrampolineWorker

extends Object
implements Worker, WorkerDelete, Runnable, Scannable
Class Inheritance
  • java.lang.Object
  • reactor.core.scheduler.ExecutorScheduler.ExecutorSchedulerTrampolineWorker
All Implemented Interfaces
reactor.core.Scannable, java.lang.Runnable, reactor.core.scheduler.ExecutorScheduler.WorkerDelete, reactor.core.scheduler.Scheduler.Worker, reactor.core.Disposable

A trampolining worker that tracks tasks.

Field Summary

Modifier and TypeField and Description
pack-priv final Executor
pack-priv final Queue<ExecutorScheduler.ExecutorTrackedRunnable>
pack-priv volatile boolean
pack-priv volatile int
pack-priv static final AtomicIntegerFieldUpdater<ExecutorScheduler.ExecutorSchedulerTrampolineWorker>
private final boolean

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
public void
dispose()

Implements reactor.core.Disposable.dispose.

Cancel or dispose the underlying task or resource.
public boolean
isDisposed()

Overrides default reactor.core.Disposable.isDisposed.

Optionally return true when the resource or task is disposed.
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.
public Object
scanUnsafe(Scannable.Attr<T>
a Attr to resolve for the component.
key
)

Implements reactor.core.Scannable.scanUnsafe.

This method is used internally by components to define their key-value mappings in a single place.
public Disposable
schedule(Runnable
the task to schedule
task
)

Implements reactor.core.scheduler.Scheduler.Worker.schedule.

Schedules the task for immediate execution on this worker.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

executorback to summary
pack-priv final Executor executor
queueback to summary
pack-priv final Queue<ExecutorScheduler.ExecutorTrackedRunnable> queue
terminatedback to summary
pack-priv volatile boolean terminated
wipback to summary
pack-priv volatile int wip
WIPback to summary
pack-priv static final AtomicIntegerFieldUpdater<ExecutorScheduler.ExecutorSchedulerTrampolineWorker> WIP
wrapScheduleback to summary
private final boolean wrapSchedule

Constructor Detail

ExecutorSchedulerTrampolineWorkerback to summary
pack-priv ExecutorSchedulerTrampolineWorker(Executor executor)

Method Detail

deleteback to summary
public void delete(ExecutorScheduler.ExecutorTrackedRunnable r)

Implements reactor.core.scheduler.ExecutorScheduler.WorkerDelete.delete.

Annotations
@Override
disposeback to summary
public void dispose()

Implements reactor.core.Disposable.dispose.

Doc from reactor.core.Disposable.dispose.

Cancel or dispose the underlying task or resource.

Implementations are required to make this method idempotent.

Annotations
@Override
isDisposedback to summary
public boolean isDisposed()

Overrides default reactor.core.Disposable.isDisposed.

Doc from reactor.core.Disposable.isDisposed.

Optionally return true when the resource or task is disposed.

Implementations are not required to track disposition and as such may never return true even when disposed. However, they MUST only return true when there's a guarantee the resource or task is disposed.

Returns:boolean

true when there's a guarantee the resource or task is disposed.

Annotations
@Override
runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override
scanUnsafeback to summary
public Object scanUnsafe(Scannable.Attr<T> key)

Implements reactor.core.Scannable.scanUnsafe.

Doc from reactor.core.Scannable.scanUnsafe.

This method is used internally by components to define their key-value mappings in a single place. Although it is ignoring the generic type of the Attr key, implementors should take care to return values of the correct type, and return null if no specific value is available.

For public consumption of attributes, prefer using scan(Attr), which will return a typed value and fall back to the key's default if the component didn't define any mapping.

Parameters
key:Scannable.Attr<T>

a Attr to resolve for the component.

Returns:Object

the value associated to the key for that specific component, or null if none.

Annotations
@Override
scheduleback to summary
public Disposable schedule(Runnable task)

Implements reactor.core.scheduler.Scheduler.Worker.schedule.

Doc from reactor.core.scheduler.Scheduler.Worker.schedule.

Schedules the task for immediate execution on this worker.

Parameters
task:Runnable

the task to schedule

Returns:Disposable

the Disposable instance that let's one cancel this particular task. If the Scheduler has been shut down, a RejectedExecutionException is thrown.

Annotations
@Override
reactor.core.scheduler back to summary

pack-priv final Class ExecutorScheduler.ExecutorSchedulerWorker

extends Object
implements Worker, WorkerDelete, Scannable
Class Inheritance
  • java.lang.Object
  • reactor.core.scheduler.ExecutorScheduler.ExecutorSchedulerWorker
All Implemented Interfaces
reactor.core.Scannable, reactor.core.scheduler.ExecutorScheduler.WorkerDelete, reactor.core.scheduler.Scheduler.Worker, reactor.core.Disposable

A non-trampolining worker that tracks tasks.

Field Summary

Modifier and TypeField and Description
pack-priv final Executor
pack-priv final Disposable.Composite
private final boolean

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
public void
dispose()

Implements reactor.core.Disposable.dispose.

Cancel or dispose the underlying task or resource.
public boolean
isDisposed()

Overrides default reactor.core.Disposable.isDisposed.

Optionally return true when the resource or task is disposed.
public Object
scanUnsafe(Scannable.Attr<T>
a Attr to resolve for the component.
key
)

Implements reactor.core.Scannable.scanUnsafe.

This method is used internally by components to define their key-value mappings in a single place.
public Disposable
schedule(Runnable
the task to schedule
task
)

Implements reactor.core.scheduler.Scheduler.Worker.schedule.

Schedules the task for immediate execution on this worker.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

executorback to summary
pack-priv final Executor executor
tasksback to summary
pack-priv final Disposable.Composite tasks
wrapScheduleback to summary
private final boolean wrapSchedule

Constructor Detail

ExecutorSchedulerWorkerback to summary
pack-priv ExecutorSchedulerWorker(Executor executor)

Method Detail

deleteback to summary
public void delete(ExecutorScheduler.ExecutorTrackedRunnable r)

Implements reactor.core.scheduler.ExecutorScheduler.WorkerDelete.delete.

Annotations
@Override
disposeback to summary
public void dispose()

Implements reactor.core.Disposable.dispose.

Doc from reactor.core.Disposable.dispose.

Cancel or dispose the underlying task or resource.

Implementations are required to make this method idempotent.

Annotations
@Override
isDisposedback to summary
public boolean isDisposed()

Overrides default reactor.core.Disposable.isDisposed.

Doc from reactor.core.Disposable.isDisposed.

Optionally return true when the resource or task is disposed.

Implementations are not required to track disposition and as such may never return true even when disposed. However, they MUST only return true when there's a guarantee the resource or task is disposed.

Returns:boolean

true when there's a guarantee the resource or task is disposed.

Annotations
@Override
scanUnsafeback to summary
public Object scanUnsafe(Scannable.Attr<T> key)

Implements reactor.core.Scannable.scanUnsafe.

Doc from reactor.core.Scannable.scanUnsafe.

This method is used internally by components to define their key-value mappings in a single place. Although it is ignoring the generic type of the Attr key, implementors should take care to return values of the correct type, and return null if no specific value is available.

For public consumption of attributes, prefer using scan(Attr), which will return a typed value and fall back to the key's default if the component didn't define any mapping.

Parameters
key:Scannable.Attr<T>

a Attr to resolve for the component.

Returns:Object

the value associated to the key for that specific component, or null if none.

Annotations
@Override
scheduleback to summary
public Disposable schedule(Runnable task)

Implements reactor.core.scheduler.Scheduler.Worker.schedule.

Doc from reactor.core.scheduler.Scheduler.Worker.schedule.

Schedules the task for immediate execution on this worker.

Parameters
task:Runnable

the task to schedule

Returns:Disposable

the Disposable instance that let's one cancel this particular task. If the Scheduler has been shut down, a RejectedExecutionException is thrown.

Annotations
@Override
reactor.core.scheduler back to summary

pack-priv final Class ExecutorScheduler.ExecutorTrackedRunnable

extends AtomicBoolean
implements Runnable, Disposable
Class Inheritance
All Implemented Interfaces
reactor.core.Disposable, java.lang.Runnable

A Runnable that wraps a task and has reference back to its parent worker to remove itself once completed or cancelled

Field Summary

Modifier and TypeField and Description
pack-priv final boolean
pack-priv final ExecutorScheduler.WorkerDelete
private static final long
pack-priv final Runnable

Constructor Summary

AccessConstructor and Description
pack-priv
ExecutorTrackedRunnable(Runnable task, ExecutorScheduler.WorkerDelete parent, boolean callRemoveOnFinish)

Method Summary

Modifier and TypeMethod and Description
public void
dispose()

Implements reactor.core.Disposable.dispose.

Cancel or dispose the underlying task or resource.
public boolean
isDisposed()

Overrides default reactor.core.Disposable.isDisposed.

Optionally return true when the resource or task is disposed.
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.
Inherited from java.util.concurrent.atomic.AtomicBoolean:
compareAndExchangecompareAndExchangeAcquirecompareAndExchangeReleasecompareAndSetgetgetAcquiregetAndSetgetOpaquegetPlainlazySetsetsetOpaquesetPlainsetReleasetoStringweakCompareAndSetweakCompareAndSetAcquireweakCompareAndSetPlainweakCompareAndSetReleaseweakCompareAndSetVolatile

Field Detail

callRemoveOnFinishback to summary
pack-priv final boolean callRemoveOnFinish
parentback to summary
pack-priv final ExecutorScheduler.WorkerDelete parent
serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.util.concurrent.atomic.AtomicBoolean.serialVersionUID.

taskback to summary
pack-priv final Runnable task

Constructor Detail

ExecutorTrackedRunnableback to summary
pack-priv ExecutorTrackedRunnable(Runnable task, ExecutorScheduler.WorkerDelete parent, boolean callRemoveOnFinish)

Method Detail

disposeback to summary
public void dispose()

Implements reactor.core.Disposable.dispose.

Doc from reactor.core.Disposable.dispose.

Cancel or dispose the underlying task or resource.

Implementations are required to make this method idempotent.

Annotations
@Override
isDisposedback to summary
public boolean isDisposed()

Overrides default reactor.core.Disposable.isDisposed.

Doc from reactor.core.Disposable.isDisposed.

Optionally return true when the resource or task is disposed.

Implementations are not required to track disposition and as such may never return true even when disposed. However, they MUST only return true when there's a guarantee the resource or task is disposed.

Returns:boolean

true when there's a guarantee the resource or task is disposed.

Annotations
@Override
runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override
reactor.core.scheduler back to summary

pack-priv Interface ExecutorScheduler.WorkerDelete

Known Direct Implementers
reactor.core.scheduler.ExecutorScheduler.ExecutorSchedulerWorker, reactor.core.scheduler.ExecutorScheduler.ExecutorSchedulerTrampolineWorker

Common interface between the tracking workers to signal the need for removal.

Method Summary

Modifier and TypeMethod and Description
public void

Method Detail

deleteback to summary
public void delete(ExecutorScheduler.ExecutorTrackedRunnable r)