Package org.redisson
Class RedissonExecutorService
- java.lang.Object
-
- org.redisson.RedissonExecutorService
-
- All Implemented Interfaces:
Executor
,ExecutorService
,ScheduledExecutorService
,RExecutorService
,RExecutorServiceAsync
,RScheduledExecutorService
,RScheduledExecutorServiceAsync
public class RedissonExecutorService extends Object implements RScheduledExecutorService
- Author:
- Nikita Koksharov
-
-
Field Summary
Fields Modifier and Type Field Description static int
SHUTDOWN_STATE
static int
TERMINATED_STATE
-
Fields inherited from interface org.redisson.api.RExecutorService
MAPREDUCE_NAME
-
-
Constructor Summary
Constructors Constructor Description RedissonExecutorService(Codec codec, CommandExecutor commandExecutor, Redisson redisson, String name, QueueTransferService queueTransferService, ConcurrentMap<String,ResponseEntry> responses, ExecutorOptions options)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
awaitTermination(long timeout, TimeUnit unit)
boolean
cancelScheduledTask(String taskId)
boolean
cancelTask(String taskId)
Cancels task by idint
countActiveWorkers()
Returns active worker groupsboolean
delete()
Deletes executor request queue and state objectsRFuture<Boolean>
deleteAsync()
Deletes executor request queue and state objectsvoid
execute(Runnable task)
void
execute(Runnable... tasks)
Submits tasks batch for execution synchronously.protected String
generateRequestId()
String
getName()
Returns executor name<T> List<Future<T>>
invokeAll(Collection<? extends Callable<T>> tasks)
<T> List<Future<T>>
invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
<T> T
invokeAny(Collection<? extends Callable<T>> tasks)
<T> T
invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
boolean
isShutdown()
boolean
isTerminated()
void
registerWorkers(int workers)
Register workersvoid
registerWorkers(int workers, ExecutorService executor)
Register workers with custom executorRScheduledFuture<?>
schedule(Runnable task, long delay, TimeUnit unit)
Creates and executes a one-shot action that becomes enabled after the given delay.RScheduledFuture<?>
schedule(Runnable task, CronSchedule cronSchedule)
Creates and executes a periodic action with cron schedule object.<V> RScheduledFuture<V>
schedule(Callable<V> task, long delay, TimeUnit unit)
Creates and executes a ScheduledFuture that becomes enabled after the given delay.RScheduledFuture<?>
scheduleAsync(Runnable task, long delay, TimeUnit unit)
Creates in async mode and executes a one-shot action that becomes enabled after the given delay.RScheduledFuture<?>
scheduleAsync(Runnable task, CronSchedule cronSchedule)
Creates in async mode and executes a periodic action with cron schedule object.<V> RScheduledFuture<V>
scheduleAsync(Callable<V> task, long delay, TimeUnit unit)
Creates in async mode and executes a ScheduledFuture that becomes enabled after the given delay.RScheduledFuture<?>
scheduleAtFixedRate(Runnable task, 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 afterinitialDelay
theninitialDelay+period
, theninitialDelay + 2 * period
, and so on.RScheduledFuture<?>
scheduleAtFixedRateAsync(Runnable task, long initialDelay, long period, TimeUnit unit)
Creates in async mode and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period.RScheduledFuture<?>
scheduleWithFixedDelay(Runnable task, 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.RScheduledFuture<?>
scheduleWithFixedDelayAsync(Runnable task, long initialDelay, long delay, TimeUnit unit)
Creates in async mode 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.void
shutdown()
List<Runnable>
shutdownNow()
RExecutorFuture<?>
submit(Runnable task)
Submits a Runnable task for execution and returns a Future representing that task.RExecutorBatchFuture
submit(Runnable... tasks)
Submits tasks batch for execution synchronously.<T> RExecutorFuture<T>
submit(Runnable task, T result)
Submits a Runnable task for execution and returns a Future representing that task.RExecutorBatchFuture
submit(Callable<?>... tasks)
Submits tasks batch for execution synchronously.<T> RExecutorFuture<T>
submit(Callable<T> task)
Submits a value-returning task for execution synchronously and returns a Future representing the pending results of the task.RExecutorFuture<?>
submitAsync(Runnable task)
Submits task for execution asynchronouslyRExecutorBatchFuture
submitAsync(Runnable... tasks)
Submits tasks batch for execution asynchronously.RExecutorBatchFuture
submitAsync(Callable<?>... tasks)
Submits tasks batch for execution asynchronously.<T> RExecutorFuture<T>
submitAsync(Callable<T> task)
Submits task for execution asynchronously
-
-
-
Field Detail
-
SHUTDOWN_STATE
public static final int SHUTDOWN_STATE
- See Also:
- Constant Field Values
-
TERMINATED_STATE
public static final int TERMINATED_STATE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
RedissonExecutorService
public RedissonExecutorService(Codec codec, CommandExecutor commandExecutor, Redisson redisson, String name, QueueTransferService queueTransferService, ConcurrentMap<String,ResponseEntry> responses, ExecutorOptions options)
-
-
Method Detail
-
generateRequestId
protected String generateRequestId()
-
countActiveWorkers
public int countActiveWorkers()
Description copied from interface:RExecutorService
Returns active worker groups- Specified by:
countActiveWorkers
in interfaceRExecutorService
- Returns:
- active worker groups count
-
registerWorkers
public void registerWorkers(int workers)
Description copied from interface:RExecutorService
Register workers- Specified by:
registerWorkers
in interfaceRExecutorService
- Parameters:
workers
- - workers amount
-
registerWorkers
public void registerWorkers(int workers, ExecutorService executor)
Description copied from interface:RExecutorService
Register workers with custom executor- Specified by:
registerWorkers
in interfaceRExecutorService
- Parameters:
workers
- - workers amountexecutor
- - executor instance
-
execute
public void execute(Runnable... tasks)
Description copied from interface:RExecutorService
Submits tasks batch for execution synchronously. All tasks are stored to executor request queue atomically, if case of any error none of tasks will be added.- Specified by:
execute
in interfaceRExecutorService
- Parameters:
tasks
- - tasks to execute
-
shutdown
public void shutdown()
- Specified by:
shutdown
in interfaceExecutorService
-
getName
public String getName()
Description copied from interface:RExecutorService
Returns executor name- Specified by:
getName
in interfaceRExecutorService
- Returns:
- name of service
-
delete
public boolean delete()
Description copied from interface:RExecutorService
Deletes executor request queue and state objects- Specified by:
delete
in interfaceRExecutorService
- Returns:
true
if any of objects were deleted
-
deleteAsync
public RFuture<Boolean> deleteAsync()
Description copied from interface:RExecutorServiceAsync
Deletes executor request queue and state objects- Specified by:
deleteAsync
in interfaceRExecutorServiceAsync
- Returns:
true
if any of objects were deleted
-
shutdownNow
public List<Runnable> shutdownNow()
- Specified by:
shutdownNow
in interfaceExecutorService
-
isShutdown
public boolean isShutdown()
- Specified by:
isShutdown
in interfaceExecutorService
-
isTerminated
public boolean isTerminated()
- Specified by:
isTerminated
in interfaceExecutorService
-
awaitTermination
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException
- Specified by:
awaitTermination
in interfaceExecutorService
- Throws:
InterruptedException
-
submit
public <T> RExecutorFuture<T> submit(Callable<T> task)
Description copied from interface:RExecutorService
Submits a value-returning task for execution synchronously and returns a Future representing the pending results of the task. The Future'sget
method will return the task's result upon successful completion.- Specified by:
submit
in interfaceExecutorService
- Specified by:
submit
in interfaceRExecutorService
- Type Parameters:
T
- the type of the task's result- Parameters:
task
- the task to submit- Returns:
- a Future representing pending completion of the task
-
submitAsync
public <T> RExecutorFuture<T> submitAsync(Callable<T> task)
Description copied from interface:RExecutorServiceAsync
Submits task for execution asynchronously- Specified by:
submitAsync
in interfaceRExecutorServiceAsync
- Type Parameters:
T
- type of return value- Parameters:
task
- - task to execute- Returns:
- Future object
-
submit
public RExecutorBatchFuture submit(Callable<?>... tasks)
Description copied from interface:RExecutorService
Submits tasks batch for execution synchronously. All tasks are stored to executor request queue atomically, if case of any error none of tasks will be added.- Specified by:
submit
in interfaceRExecutorService
- Parameters:
tasks
- - tasks to execute- Returns:
- Future object
-
submitAsync
public RExecutorBatchFuture submitAsync(Callable<?>... tasks)
Description copied from interface:RExecutorServiceAsync
Submits tasks batch for execution asynchronously. All tasks are stored to executor request queue atomically, if case of any error none of tasks will be added.- Specified by:
submitAsync
in interfaceRExecutorServiceAsync
- Parameters:
tasks
- - tasks to execute- Returns:
- Future object
-
submit
public <T> RExecutorFuture<T> submit(Runnable task, T result)
Description copied from interface:RExecutorService
Submits a Runnable task for execution and returns a Future representing that task. The Future'sget
method will return the given result upon successful completion.- Specified by:
submit
in interfaceExecutorService
- Specified by:
submit
in interfaceRExecutorService
- Type Parameters:
T
- the type of the result- Parameters:
task
- the task to submitresult
- the result to return- Returns:
- a Future representing pending completion of the task
-
submit
public RExecutorBatchFuture submit(Runnable... tasks)
Description copied from interface:RExecutorService
Submits tasks batch for execution synchronously. All tasks are stored to executor request queue atomically, if case of any error none of tasks will be added.- Specified by:
submit
in interfaceRExecutorService
- Parameters:
tasks
- - tasks to execute- Returns:
- Future object
-
submitAsync
public RExecutorBatchFuture submitAsync(Runnable... tasks)
Description copied from interface:RExecutorServiceAsync
Submits tasks batch for execution asynchronously. All tasks are stored to executor request queue atomically, if case of any error none of tasks will be added.- Specified by:
submitAsync
in interfaceRExecutorServiceAsync
- Parameters:
tasks
- - tasks to execute- Returns:
- Future object
-
submit
public RExecutorFuture<?> submit(Runnable task)
Description copied from interface:RExecutorService
Submits a Runnable task for execution and returns a Future representing that task. The Future'sget
method will returnnull
upon successful completion.- Specified by:
submit
in interfaceExecutorService
- Specified by:
submit
in interfaceRExecutorService
- Parameters:
task
- the task to submit- Returns:
- a Future representing pending completion of the task
-
submitAsync
public RExecutorFuture<?> submitAsync(Runnable task)
Description copied from interface:RExecutorServiceAsync
Submits task for execution asynchronously- Specified by:
submitAsync
in interfaceRExecutorServiceAsync
- Parameters:
task
- - task to execute- Returns:
- Future object
-
schedule
public RScheduledFuture<?> schedule(Runnable task, long delay, TimeUnit unit)
Description copied from interface:RScheduledExecutorService
Creates and executes a one-shot action that becomes enabled after the given delay.- Specified by:
schedule
in interfaceRScheduledExecutorService
- Specified by:
schedule
in interfaceScheduledExecutorService
- Parameters:
task
- 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 returnnull
upon completion
-
scheduleAsync
public RScheduledFuture<?> scheduleAsync(Runnable task, long delay, TimeUnit unit)
Description copied from interface:RScheduledExecutorServiceAsync
Creates in async mode and executes a one-shot action that becomes enabled after the given delay.- Specified by:
scheduleAsync
in interfaceRScheduledExecutorServiceAsync
- Parameters:
task
- the task to executedelay
- the time from now to delay executionunit
- the time unit of the delay parameter- Returns:
- RScheduledFuture with listeners support
-
schedule
public <V> RScheduledFuture<V> schedule(Callable<V> task, long delay, TimeUnit unit)
Description copied from interface:RScheduledExecutorService
Creates and executes a ScheduledFuture that becomes enabled after the given delay.- Specified by:
schedule
in interfaceRScheduledExecutorService
- Specified by:
schedule
in interfaceScheduledExecutorService
- Type Parameters:
V
- the type of the callable's result- Parameters:
task
- 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
-
scheduleAsync
public <V> RScheduledFuture<V> scheduleAsync(Callable<V> task, long delay, TimeUnit unit)
Description copied from interface:RScheduledExecutorServiceAsync
Creates in async mode and executes a ScheduledFuture that becomes enabled after the given delay.- Specified by:
scheduleAsync
in interfaceRScheduledExecutorServiceAsync
- Type Parameters:
V
- the type of the callable's result- Parameters:
task
- the function to executedelay
- the time from now to delay executionunit
- the time unit of the delay parameter- Returns:
- RScheduledFuture with listeners support
-
scheduleAtFixedRate
public RScheduledFuture<?> scheduleAtFixedRate(Runnable task, long initialDelay, long period, TimeUnit unit)
Description copied from interface:RScheduledExecutorService
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 afterinitialDelay
theninitialDelay+period
, theninitialDelay + 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:
scheduleAtFixedRate
in interfaceRScheduledExecutorService
- Specified by:
scheduleAtFixedRate
in interfaceScheduledExecutorService
- Parameters:
task
- 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
-
scheduleAtFixedRateAsync
public RScheduledFuture<?> scheduleAtFixedRateAsync(Runnable task, long initialDelay, long period, TimeUnit unit)
Description copied from interface:RScheduledExecutorServiceAsync
Creates in async mode and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period. 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:
scheduleAtFixedRateAsync
in interfaceRScheduledExecutorServiceAsync
- Parameters:
task
- 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:
- RScheduledFuture with listeners support
-
schedule
public RScheduledFuture<?> schedule(Runnable task, CronSchedule cronSchedule)
Description copied from interface:RScheduledExecutorService
Creates and executes a periodic action with cron schedule object. 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:
schedule
in interfaceRScheduledExecutorService
- Parameters:
task
- - command the task to executecronSchedule
- - cron schedule object- Returns:
- future object
-
scheduleAsync
public RScheduledFuture<?> scheduleAsync(Runnable task, CronSchedule cronSchedule)
Description copied from interface:RScheduledExecutorServiceAsync
Creates in async mode and executes a periodic action with cron schedule object. 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:
scheduleAsync
in interfaceRScheduledExecutorServiceAsync
- Parameters:
task
- the task to executecronSchedule
- cron schedule object- Returns:
- RScheduledFuture with listeners support
-
scheduleWithFixedDelay
public RScheduledFuture<?> scheduleWithFixedDelay(Runnable task, long initialDelay, long delay, TimeUnit unit)
Description copied from interface:RScheduledExecutorService
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:
scheduleWithFixedDelay
in interfaceRScheduledExecutorService
- Specified by:
scheduleWithFixedDelay
in interfaceScheduledExecutorService
- Parameters:
task
- 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
-
scheduleWithFixedDelayAsync
public RScheduledFuture<?> scheduleWithFixedDelayAsync(Runnable task, long initialDelay, long delay, TimeUnit unit)
Description copied from interface:RScheduledExecutorServiceAsync
Creates in async mode 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:
scheduleWithFixedDelayAsync
in interfaceRScheduledExecutorServiceAsync
- Parameters:
task
- 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:
- RScheduledFuture with listeners support
-
cancelScheduledTask
public boolean cancelScheduledTask(String taskId)
Description copied from interface:RScheduledExecutorService
- Specified by:
cancelScheduledTask
in interfaceRScheduledExecutorService
- Parameters:
taskId
- of task- Returns:
- boolean
-
cancelTask
public boolean cancelTask(String taskId)
Description copied from interface:RExecutorService
Cancels task by id- Specified by:
cancelTask
in interfaceRExecutorService
- Parameters:
taskId
- - id of task- Returns:
true
if task has been canceled successfully- See Also:
RExecutorFuture.getTaskId()
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException
- Specified by:
invokeAny
in interfaceExecutorService
- Throws:
InterruptedException
ExecutionException
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
- Specified by:
invokeAny
in interfaceExecutorService
- Throws:
InterruptedException
ExecutionException
TimeoutException
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException
- Specified by:
invokeAll
in interfaceExecutorService
- Throws:
InterruptedException
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException
- Specified by:
invokeAll
in interfaceExecutorService
- Throws:
InterruptedException
-
-