- java.lang.Object
-
- io.netty5.util.concurrent.UnorderedThreadPoolEventExecutor
-
- All Implemented Interfaces:
EventExecutor
,EventExecutorGroup
,FuturePromiseFactory
,Iterable<EventExecutor>
,Executor
public final class UnorderedThreadPoolEventExecutor extends Object implements EventExecutor
EventExecutor
implementation which makes no guarantees about the ordering of task execution that are submitted because there may be multiple threads executing these tasks. This implementation is most useful for protocols that do not need strict ordering. Because it provides no ordering care should be taken when using it!
-
-
Constructor Summary
Constructors Constructor Description UnorderedThreadPoolEventExecutor(int corePoolSize)
UnorderedThreadPoolEventExecutor(int corePoolSize, RejectedExecutionHandler handler)
UnorderedThreadPoolEventExecutor(int corePoolSize, ThreadFactory threadFactory)
UnorderedThreadPoolEventExecutor(int corePoolSize, ThreadFactory threadFactory, RejectedExecutionHandler handler)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
awaitTermination(long timeout, TimeUnit unit)
Wait for thisEventExecutorGroup
to terminate, up to the given timeout.void
execute(Runnable task)
boolean
inEventLoop(Thread thread)
boolean
isShutdown()
Returnstrue
if allEventExecutor
s managed by thisEventExecutorGroup
have been shut down gracefully and moved past the grace period so that they are no longer accepting any new tasks.boolean
isShuttingDown()
Returnstrue
if and only if allEventExecutor
s managed by thisEventExecutorGroup
are being shut down gracefully or was shut down.boolean
isTerminated()
Returnstrue
if allEventExecutor
s managed by thisEventExecutorGroup
are shut down, and all of their tasks have completed.Future<Void>
schedule(Runnable task, long delay, TimeUnit unit)
Schedule the given task for execution after the given delay, in the next availableEventExecutor
in this group, and return a future that produces anull
result when the task completes.<V> Future<V>
schedule(Callable<V> task, long delay, TimeUnit unit)
Schedule the given task for execution after the given delay, in the next availableEventExecutor
in this group, and return a future that will return the result of the callable when the task completes.Future<Void>
scheduleAtFixedRate(Runnable task, long initialDelay, long period, TimeUnit unit)
Schedule the given task for periodic execution in the next availableEventExecutor
.Future<Void>
scheduleWithFixedDelay(Runnable task, long initialDelay, long delay, TimeUnit unit)
Schedule the given task for periodic execution in the next availableEventExecutor
.Future<Void>
shutdownGracefully(long quietPeriod, long timeout, TimeUnit unit)
Signals this executor that the caller wants the executor to be shut down.Future<Void>
submit(Runnable task)
Submit the given task for execution in the next availableEventExecutor
in this group, and return a future that produces anull
result when the task completes.<T> Future<T>
submit(Runnable task, T result)
Submit the given task for execution in the next availableEventExecutor
in this group, and return a future that produces the given result when the task completes.<T> Future<T>
submit(Callable<T> task)
Submit the given task for execution in the next availableEventExecutor
in this group, and return a future that will return the result of the callable when the task completes.Future<Void>
terminationFuture()
Returns theFuture
which is notified when allEventExecutor
s managed by thisEventExecutorGroup
have been terminated.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty5.util.concurrent.EventExecutor
inEventLoop, iterator, newFailedFuture, newPromise, newSucceededFuture, next
-
Methods inherited from interface io.netty5.util.concurrent.EventExecutorGroup
shutdownGracefully
-
Methods inherited from interface io.netty5.util.concurrent.FuturePromiseFactory
newSucceededFuture
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
UnorderedThreadPoolEventExecutor
public UnorderedThreadPoolEventExecutor(int corePoolSize)
-
UnorderedThreadPoolEventExecutor
public UnorderedThreadPoolEventExecutor(int corePoolSize, ThreadFactory threadFactory)
-
UnorderedThreadPoolEventExecutor
public UnorderedThreadPoolEventExecutor(int corePoolSize, RejectedExecutionHandler handler)
-
UnorderedThreadPoolEventExecutor
public UnorderedThreadPoolEventExecutor(int corePoolSize, ThreadFactory threadFactory, RejectedExecutionHandler handler)
-
-
Method Detail
-
inEventLoop
public boolean inEventLoop(Thread thread)
Description copied from interface:EventExecutor
- Specified by:
inEventLoop
in interfaceEventExecutor
-
isShuttingDown
public boolean isShuttingDown()
Description copied from interface:EventExecutorGroup
Returnstrue
if and only if allEventExecutor
s managed by thisEventExecutorGroup
are being shut down gracefully or was shut down.An executor group that "is shutting down" can still accept new tasks for a little while (the grace period), but will eventually start rejecting new tasks. At that point, the executor group will be shut down.
- Specified by:
isShuttingDown
in interfaceEventExecutorGroup
- Returns:
true
if all executors in this group have at least started shutting down, otherwisefalse
.
-
isShutdown
public boolean isShutdown()
Description copied from interface:EventExecutorGroup
Returnstrue
if allEventExecutor
s managed by thisEventExecutorGroup
have been shut down gracefully and moved past the grace period so that they are no longer accepting any new tasks.An executor group that "is shut down" might still be executing tasks that it has queued up, but it will no longer be accepting any new tasks. Once all running and queued tasks have completed, the executor group will be terminated.
- Specified by:
isShutdown
in interfaceEventExecutorGroup
- Returns:
true
if all executors in this group have shut down and are no longer accepting any new tasks.
-
isTerminated
public boolean isTerminated()
Description copied from interface:EventExecutorGroup
Returnstrue
if allEventExecutor
s managed by thisEventExecutorGroup
are shut down, and all of their tasks have completed.- Specified by:
isTerminated
in interfaceEventExecutorGroup
- Returns:
true
if all executors in this group have terminated.
-
awaitTermination
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException
Description copied from interface:EventExecutorGroup
Wait for thisEventExecutorGroup
to terminate, up to the given timeout.- Specified by:
awaitTermination
in interfaceEventExecutorGroup
- Parameters:
timeout
- The non-negative maximum amount of time to wait for the executor group to terminate.unit
- The non-null time unit of the timeout.- Returns:
true
if the executor group terminated within the specific timeout.- Throws:
InterruptedException
- If this thread was interrupted while waiting for executor group to terminate.
-
shutdownGracefully
public Future<Void> shutdownGracefully(long quietPeriod, long timeout, TimeUnit unit)
Description copied from interface:EventExecutorGroup
Signals this executor that the caller wants the executor to be shut down. Once this method is called,EventExecutorGroup.isShuttingDown()
starts to returntrue
, and the executor prepares to shut itself down. This method ensures that no tasks are submitted for 'the quiet period' (usually a couple seconds) before it shuts itself down. If a task is submitted during the quiet period, it is guaranteed to be accepted and the quiet period will start over.- Specified by:
shutdownGracefully
in interfaceEventExecutorGroup
- Parameters:
quietPeriod
- the quiet period as described in the documentationtimeout
- the maximum amount of time to wait until the executor is shutting down regardless if a task was submitted during the quiet period.unit
- the unit ofquietPeriod
andtimeout
- Returns:
- the
EventExecutorGroup.terminationFuture()
-
terminationFuture
public Future<Void> terminationFuture()
Description copied from interface:EventExecutorGroup
Returns theFuture
which is notified when allEventExecutor
s managed by thisEventExecutorGroup
have been terminated.- Specified by:
terminationFuture
in interfaceEventExecutorGroup
- Returns:
- The
Future
representing the termination of thisEventExecutorGroup
.
-
schedule
public Future<Void> schedule(Runnable task, long delay, TimeUnit unit)
Description copied from interface:EventExecutorGroup
Schedule the given task for execution after the given delay, in the next availableEventExecutor
in this group, and return a future that produces anull
result when the task completes.- Specified by:
schedule
in interfaceEventExecutor
- Specified by:
schedule
in interfaceEventExecutorGroup
- Parameters:
task
- The task that should be executed in thisEventExecutorGroup
after the given delay.delay
- A positive time delay, in the given time unit.unit
- The non-null time unit for the delay.- Returns:
- A future that represents the completion of the scheduled task.
-
schedule
public <V> Future<V> schedule(Callable<V> task, long delay, TimeUnit unit)
Description copied from interface:EventExecutorGroup
Schedule the given task for execution after the given delay, in the next availableEventExecutor
in this group, and return a future that will return the result of the callable when the task completes.- Specified by:
schedule
in interfaceEventExecutor
- Specified by:
schedule
in interfaceEventExecutorGroup
- Type Parameters:
V
- The type of the future result.- Parameters:
task
- The task that should be executed in thisEventExecutorGroup
after the given delay.delay
- A positive time delay, in the given time unit.unit
- The non-null time unit for the delay.- Returns:
- A future that represents the completion of the scheduled task.
-
scheduleAtFixedRate
public Future<Void> scheduleAtFixedRate(Runnable task, long initialDelay, long period, TimeUnit unit)
Description copied from interface:EventExecutorGroup
Schedule the given task for periodic execution in the next availableEventExecutor
. The first execution will occur after the given initial delay, and the following repeated executions will occur with the given period of time between each execution is started. If the task takes longer to complete than the requested period, then the following executions will be delayed, rather than allowing multiple instances of the task to run concurrently.The task will be executed repeatedly until it either fails with an exception, or its future is cancelled. The future thus will never complete successfully.
- Specified by:
scheduleAtFixedRate
in interfaceEventExecutor
- Specified by:
scheduleAtFixedRate
in interfaceEventExecutorGroup
- Parameters:
task
- The task that should be scheduled to execute at a fixed rate in thisEventExecutorGroup
.initialDelay
- The positive initial delay for the first task execution, in terms of the given time unit.period
- The positive period for the execution frequency to use after the first execution has started, in terms of the given time unit.unit
- The non-null time unit for the delay and period.- Returns:
- A future that represents the recurring task, and which can be cancelled to stop future executions.
-
scheduleWithFixedDelay
public Future<Void> scheduleWithFixedDelay(Runnable task, long initialDelay, long delay, TimeUnit unit)
Description copied from interface:EventExecutorGroup
Schedule the given task for periodic execution in the next availableEventExecutor
. The first execution will occur after the given initial delay, and the following repeated executions will occur with the given subsequent delay between one task completing and the next task starting. The delay from the completion of one task, to the start of the next, stays unchanged regardless of how long a task takes to complete.This is in contrast to
EventExecutorGroup.scheduleAtFixedRate(Runnable, long, long, TimeUnit)
which varies the delays between the tasks in order to hit a given frequency.The task will be executed repeatedly until it either fails with an exception, or its future is cancelled. The future thus will never complete successfully.
- Specified by:
scheduleWithFixedDelay
in interfaceEventExecutor
- Specified by:
scheduleWithFixedDelay
in interfaceEventExecutorGroup
- Parameters:
task
- The task that should be scheduled to execute with fixed delays in thisEventExecutorGroup
.initialDelay
- The positive initial delay for the first task execution, in terms of the given time unit.delay
- The positive subsequent delay between task, to use after the first execution has completed, in terms of the given time unit.unit
- The non-null time unit for the delays.- Returns:
- A future that represents the recurring task, and which can be cancelled to stop future executions.
-
submit
public Future<Void> submit(Runnable task)
Description copied from interface:EventExecutorGroup
Submit the given task for execution in the next availableEventExecutor
in this group, and return a future that produces anull
result when the task completes.- Specified by:
submit
in interfaceEventExecutor
- Specified by:
submit
in interfaceEventExecutorGroup
- Parameters:
task
- The task that should be executed in thisEventExecutorGroup
.- Returns:
- A future that represents the completion of the submitted task.
-
submit
public <T> Future<T> submit(Runnable task, T result)
Description copied from interface:EventExecutorGroup
Submit the given task for execution in the next availableEventExecutor
in this group, and return a future that produces the given result when the task completes.- Specified by:
submit
in interfaceEventExecutor
- Specified by:
submit
in interfaceEventExecutorGroup
- Type Parameters:
T
- The type of the future result.- Parameters:
task
- The task that should be executed in thisEventExecutorGroup
.result
- The value that the returned future will complete with, if the task completes successfully.- Returns:
- A future that represents the completion of the submitted task.
-
submit
public <T> Future<T> submit(Callable<T> task)
Description copied from interface:EventExecutorGroup
Submit the given task for execution in the next availableEventExecutor
in this group, and return a future that will return the result of the callable when the task completes.- Specified by:
submit
in interfaceEventExecutor
- Specified by:
submit
in interfaceEventExecutorGroup
- Type Parameters:
T
- The type of the future result.- Parameters:
task
- The task that should be executed in thisEventExecutorGroup
.- Returns:
- A future that represents the completion of the submitted task.
-
execute
public void execute(Runnable task)
- Specified by:
execute
in interfaceEventExecutor
- Specified by:
execute
in interfaceEventExecutorGroup
- Specified by:
execute
in interfaceExecutor
-
-