Top Description Fields Constructors Methods
reactor.core.scheduler

pack-priv final Class ParallelScheduler

extends Object
implements Scheduler, Supplier<ScheduledExecutorService>, SchedulerState.DisposeAwaiter<ScheduledExecutorService[]>, Scannable
Class Inheritance
All Implemented Interfaces
reactor.core.Scannable, reactor.core.scheduler.SchedulerState.DisposeAwaiter, java.util.function.Supplier, reactor.core.scheduler.Scheduler, reactor.core.Disposable
Imports
java.util.concurrent.Executors, .ScheduledExecutorService, .ScheduledThreadPoolExecutor, .ThreadFactory, .TimeUnit, java.util.concurrent.atomic.AtomicLong, .AtomicReferenceFieldUpdater, java.util.function.Supplier, java.util.stream.Stream, reactor.core.Disposable, .Scannable, reactor.core.publisher.Mono

Scheduler that hosts a fixed pool of single-threaded ScheduledExecutorService-based workers and is suited for parallel work. This scheduler is time-capable (can schedule with delay / periodically).
Authors
Stephane Maldini, Simon Baslé

Field Summary

Modifier and TypeField and Description
pack-priv static final AtomicLong
pack-priv final ThreadFactory
pack-priv final int
n

pack-priv int
pack-priv static final ScheduledExecutorService[]
pack-priv volatile SchedulerState<ScheduledExecutorService[]>
private static final AtomicReferenceFieldUpdater<ParallelScheduler, SchedulerState<T>>
pack-priv static final ScheduledExecutorService

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public boolean
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 Mono<Void>
disposeGracefully()

Overrides default reactor.core.scheduler.Scheduler.disposeGracefully.

Lazy variant of dispose() that also allows for graceful cleanup of underlying resources.
public ScheduledExecutorService
get()

Implements java.util.function.Supplier.get.

Instantiates the default ScheduledExecutorService for the ParallelScheduler (Executors.newScheduledThreadPoolExecutor with core and max pool size of 1).
public void
init()

Overrides default reactor.core.scheduler.Scheduler.init.

Instructs this Scheduler to prepare itself for running tasks directly or through its Workers.
public Stream<? extends Scannable>
inners()

Overrides default reactor.core.Scannable.inners.

Return a Stream of referenced inners (flatmap, multicast etc)
public boolean
isDisposed()

Overrides default reactor.core.Disposable.isDisposed.

Optionally return true when the resource or task is disposed.
pack-priv ScheduledExecutorService
pick()

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 Disposable
schedule(Runnable
the task to schedule
task
,
long
the delay amount, non-positive values indicate non-delayed scheduling
delay
,
TimeUnit
the unit of measure of the delay amount
unit
)

Overrides default reactor.core.scheduler.Scheduler.schedule.

Schedules the execution of the given task with the given delay amount.
public Disposable
schedulePeriodically(Runnable
the task to schedule
task
,
long
the initial delay amount, non-positive values indicate non-delayed scheduling
initialDelay
,
long
the period at which the task should be re-executed
period
,
TimeUnit
the unit of measure of the delay amount
unit
)

Overrides default reactor.core.scheduler.Scheduler.schedulePeriodically.

Schedules a periodic execution of the given task with the given initial delay and period.
public void
start()

Overrides default reactor.core.scheduler.Scheduler.start.

Instructs this Scheduler to prepare itself for running tasks directly or through its Workers.
public String
toString()

Overrides java.lang.Object.toString.

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

Field Detail

COUNTERback to summary
pack-priv static final AtomicLong COUNTER
factoryback to summary
pack-priv final ThreadFactory factory
nback to summary
pack-priv final int n
roundRobinback to summary
pack-priv int roundRobin
SHUTDOWNback to summary
pack-priv static final ScheduledExecutorService[] SHUTDOWN
stateback to summary
pack-priv volatile SchedulerState<ScheduledExecutorService[]> state
STATEback to summary
private static final AtomicReferenceFieldUpdater<ParallelScheduler, SchedulerState<T>> STATE
Annotations
@SuppressWarnings:rawtypes
TERMINATEDback to summary
pack-priv static final ScheduledExecutorService TERMINATED

Constructor Detail

ParallelSchedulerback to summary
pack-priv ParallelScheduler(int n, ThreadFactory factory)

Method Detail

awaitback to summary
public boolean await(ScheduledExecutorService[] resource, long timeout, TimeUnit timeUnit) throws InterruptedException

Implements reactor.core.scheduler.SchedulerState.DisposeAwaiter.await.

Annotations
@Override
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
disposeGracefullyback to summary
public Mono<Void> disposeGracefully()

Overrides default reactor.core.scheduler.Scheduler.disposeGracefully.

Doc from reactor.core.scheduler.Scheduler.disposeGracefully.

Lazy variant of dispose() that also allows for graceful cleanup of underlying resources.

It is advised to apply a Mono#timeout(Duration) operator to the resulting Mono.

The returned Mono can be retried in case of timeout errors. It can also be followed by a call to dispose() to issue a forceful shutdown of underlying resources.

Returns:Mono<Void>

Mono which upon subscription initiates the graceful dispose procedure. If the disposal is successful, the returned Mono completes without an error.

Annotations
@Override
getback to summary
public ScheduledExecutorService get()

Implements java.util.function.Supplier.get.

Instantiates the default ScheduledExecutorService for the ParallelScheduler (Executors.newScheduledThreadPoolExecutor with core and max pool size of 1).

Returns:ScheduledExecutorService

Doc from java.util.function.Supplier.get.

a result

Annotations
@Override
initback to summary
public void init()

Overrides default reactor.core.scheduler.Scheduler.init.

Doc from reactor.core.scheduler.Scheduler.init.

Instructs this Scheduler to prepare itself for running tasks directly or through its Workers.

Implementations are encouraged to throw an exception if this method is called after the scheduler has been disposed via dispose() or disposeGracefully().

Annotations
@Override
innersback to summary
public Stream<? extends Scannable> inners()

Overrides default reactor.core.Scannable.inners.

Doc from reactor.core.Scannable.inners.

Return a Stream of referenced inners (flatmap, multicast etc)

Returns:Stream<? extends Scannable>

a Stream of referenced inners (flatmap, multicast etc)

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
pickback to summary
pack-priv ScheduledExecutorService pick()
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
scheduleback to summary
public Disposable schedule(Runnable task, long delay, TimeUnit unit)

Overrides default reactor.core.scheduler.Scheduler.schedule.

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

Schedules the execution of the given task with the given delay amount.

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

Parameters
task:Runnable

the task to schedule

delay:long

the delay amount, non-positive values indicate non-delayed scheduling

unit:TimeUnit

the unit of measure of the delay amount

Returns:Disposable

the Disposable that let's one cancel this particular delayed task, or throw a RejectedExecutionException if the Scheduler is not capable of scheduling with delay.

Annotations
@Override
schedulePeriodicallyback to summary
public Disposable schedulePeriodically(Runnable task, long initialDelay, long period, TimeUnit unit)

Overrides default reactor.core.scheduler.Scheduler.schedulePeriodically.

Doc from reactor.core.scheduler.Scheduler.schedulePeriodically.

Schedules a periodic execution of the given task with the given initial delay and period.

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

The periodic execution is at a fixed rate, that is, the first execution will be after the initial delay, the second after initialDelay + period, the third after initialDelay + 2 * period, and so on.

Parameters
task:Runnable

the task to schedule

initialDelay:long

the initial delay amount, non-positive values indicate non-delayed scheduling

period:long

the period at which the task should be re-executed

unit:TimeUnit

the unit of measure of the delay amount

Returns:Disposable

the Disposable that let's one cancel this particular delayed task, or throw a RejectedExecutionException if the Scheduler is not capable of scheduling periodically.

Annotations
@Override
startback to summary
public void start()

Overrides default reactor.core.scheduler.Scheduler.start.

Doc from reactor.core.scheduler.Scheduler.start.

Instructs this Scheduler to prepare itself for running tasks directly or through its Workers.

The operation is thread-safe but one should avoid using start() and dispose() concurrently as it would non-deterministically leave the Scheduler in either active or inactive state.

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