@Beta public interface IScheduledExecutorService extends DistributedObject
ScheduledExecutorService
.
IScheduledExecutorService
provides similar API to the ScheduledExecutorService
with some
exceptions but also additional methods like scheduling tasks on a specific member, on a member who is owner of a specific key,
executing a tasks on multiple members etc.
Tasks (Runnable and/or Callable) scheduled on any partition through an IScheduledExecutorService,
yield some durability characteristics.
StatefulTask
interface.
ScheduledTaskHandler
. The handler is generated before
the actual scheduling of the task on the node, which allows for a way to access the future in an event of a node failure
immediately after scheduling, and also guarantees no duplicates in the cluster by utilising a unique name per task.
A name can also be defined by the user by having the Runnable or Callable implement the NamedTask
.
Alternatively, one can wrap any task using the TaskUtils.named(String, Callable)
or
TaskUtils.named(String, Runnable)
for simplicity.
One difference of this service in comparison to ScheduledExecutorService
is the
scheduleAtFixedRate(Runnable, long, long, TimeUnit)
which has similar semantic
to ScheduledExecutorService.scheduleAtFixedRate(Runnable, long, long, TimeUnit)
. It
guarantees a task won't be executed by multiple threads concurrently. The difference is that this service will
skip a scheduled execution if another thread is still running the same task, instead of postponing its execution.
ScheduledExecutorService.scheduleWithFixedDelay(Runnable, long, long, TimeUnit)
Modifier and Type | Method and Description |
---|---|
<V> Map<Member,List<IScheduledFuture<V>>> |
getAllScheduledFutures()
Fetches and returns all scheduled (not disposed yet) futures from all members in the cluster.
|
<V> IScheduledFuture<V> |
getScheduledFuture(ScheduledTaskHandler handler)
Creates a new
IScheduledFuture from the given handler. |
<V> IScheduledFuture<V> |
schedule(Callable<V> command,
long delay,
TimeUnit unit)
Creates and executes a one-shot action that becomes enabled
after the given delay.
|
IScheduledFuture<?> |
schedule(Runnable command,
long delay,
TimeUnit unit)
Creates and executes a one-shot action that becomes enabled
after the given delay.
|
IScheduledFuture<?> |
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.
|
<V> Map<Member,IScheduledFuture<V>> |
scheduleOnAllMembers(Callable<V> command,
long delay,
TimeUnit unit)
Creates and executes a one-shot action that becomes enabled
after the given delay on all cluster
Member s. |
Map<Member,IScheduledFuture<?>> |
scheduleOnAllMembers(Runnable command,
long delay,
TimeUnit unit)
Creates and executes a one-shot action that becomes enabled
after the given delay on all cluster
Member s. |
Map<Member,IScheduledFuture<?>> |
scheduleOnAllMembersAtFixedRate(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 on all cluster
Member s. |
<V> IScheduledFuture<V> |
scheduleOnKeyOwner(Callable<V> command,
Object key,
long delay,
TimeUnit unit)
Creates and executes a one-shot action that becomes enabled
after the given delay on the partition owner of the given key.
|
IScheduledFuture<?> |
scheduleOnKeyOwner(Runnable command,
Object key,
long delay,
TimeUnit unit)
Creates and executes a one-shot action that becomes enabled
after the given delay on the partition owner of the given key.
|
IScheduledFuture<?> |
scheduleOnKeyOwnerAtFixedRate(Runnable command,
Object key,
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 on the partition owner of the given key.
|
<V> IScheduledFuture<V> |
scheduleOnMember(Callable<V> command,
Member member,
long delay,
TimeUnit unit)
Creates and executes a one-shot action that becomes enabled
after the given delay at the given
Member . |
IScheduledFuture<?> |
scheduleOnMember(Runnable command,
Member member,
long delay,
TimeUnit unit)
Creates and executes a one-shot action that becomes enabled
after the given delay at the given
Member . |
IScheduledFuture<?> |
scheduleOnMemberAtFixedRate(Runnable command,
Member member,
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 at the given
Member . |
<V> Map<Member,IScheduledFuture<V>> |
scheduleOnMembers(Callable<V> command,
Collection<Member> members,
long delay,
TimeUnit unit)
Creates and executes a one-shot action that becomes enabled
after the given delay on all
Member s given. |
Map<Member,IScheduledFuture<?>> |
scheduleOnMembers(Runnable command,
Collection<Member> members,
long delay,
TimeUnit unit)
Creates and executes a one-shot action that becomes enabled
after the given delay on all
Member s given. |
Map<Member,IScheduledFuture<?>> |
scheduleOnMembersAtFixedRate(Runnable command,
Collection<Member> members,
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 on all
Member s given. |
void |
shutdown()
Initiates an orderly shutdown in which previously submitted
tasks are executed, but no new tasks will be accepted.
|
destroy, getName, getPartitionKey, getServiceName
IScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit)
command
- the task to executedelay
- the time from now to delay executionunit
- the time unit of the delay parameterget()
method will return
null
upon completionRejectedExecutionException
- if the task cannot be
scheduled for executionNullPointerException
- if command is null<V> IScheduledFuture<V> schedule(Callable<V> command, long delay, TimeUnit unit)
command
- the task to executedelay
- the time from now to delay executionunit
- the time unit of the delay parameterget()
method will return
null
upon completionRejectedExecutionException
- if the task cannot be
scheduled for executionNullPointerException
- if command is nullIScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit)
initialDelay
then initialDelay+period
, then
initialDelay + 2 * period
, and so on.
If any execution of this task
takes longer than its period, then subsequent execution will be skipped.command
- the task to executeinitialDelay
- the time to delay first executionperiod
- the period between successive executionsunit
- the time unit of the initialDelay and period parametersget()
method will throw an
exception upon cancellationRejectedExecutionException
- if the task cannot be
scheduled for executionNullPointerException
- if command is nullIScheduledFuture<?> scheduleOnMember(Runnable command, Member member, long delay, TimeUnit unit)
Member
.command
- the task to executemember
- the member to execute the taskdelay
- the time from now to delay executionunit
- the time unit of the delay parameterget()
method will return
null
upon completionRejectedExecutionException
- if the task cannot be
scheduled for executionNullPointerException
- if command is null<V> IScheduledFuture<V> scheduleOnMember(Callable<V> command, Member member, long delay, TimeUnit unit)
Member
.command
- the task to executemember
- the member to execute the taskdelay
- the time from now to delay executionunit
- the time unit of the delay parameterget()
method will return
null
upon completionRejectedExecutionException
- if the task cannot be
scheduled for executionNullPointerException
- if command is nullIScheduledFuture<?> scheduleOnMemberAtFixedRate(Runnable command, Member member, long initialDelay, long period, TimeUnit unit)
Member
. Executions will commence after
initialDelay
then initialDelay+period
, then
initialDelay + 2 * period
, and so on.
If any execution of this task
takes longer than its period, then subsequent execution will be skipped.command
- the task to executemember
- the member to execute the taskinitialDelay
- the time to delay first executionperiod
- the period between successive executionsunit
- the time unit of the initialDelay and period parametersget()
method will throw an
exception upon cancellationRejectedExecutionException
- if the task cannot be
scheduled for executionNullPointerException
- if command is nullIScheduledFuture<?> scheduleOnKeyOwner(Runnable command, Object key, long delay, TimeUnit unit)
command
- the task to executekey
- the key to identify the partition owner, which will execute the taskdelay
- the time from now to delay executionunit
- the time unit of the delay parameterget()
method will return
null
upon completionRejectedExecutionException
- if the task cannot be
scheduled for executionNullPointerException
- if command is null<V> IScheduledFuture<V> scheduleOnKeyOwner(Callable<V> command, Object key, long delay, TimeUnit unit)
command
- the task to executekey
- the key to identify the partition owner, which will execute the taskdelay
- the time from now to delay executionunit
- the time unit of the delay parameterget()
method will return
null
upon completionRejectedExecutionException
- if the task cannot be
scheduled for executionNullPointerException
- if command is nullIScheduledFuture<?> scheduleOnKeyOwnerAtFixedRate(Runnable command, Object key, long initialDelay, long period, TimeUnit unit)
initialDelay
then initialDelay+period
, then
initialDelay + 2 * period
, and so on.
If any execution of this task
takes longer than its period, then subsequent execution will be skipped.command
- the task to executekey
- the key to identify the partition owner, which will execute the taskinitialDelay
- the time to delay first executionperiod
- the period between successive executionsunit
- the time unit of the initialDelay and period parametersget()
method will throw an
exception upon cancellationRejectedExecutionException
- if the task cannot be
scheduled for executionNullPointerException
- if command is nullMap<Member,IScheduledFuture<?>> scheduleOnAllMembers(Runnable command, long delay, TimeUnit unit)
Member
s.
command
- the task to executedelay
- the time from now to delay executionunit
- the time unit of the delay parameterget()
method will return
null
upon completionRejectedExecutionException
- if the task cannot be
scheduled for executionNullPointerException
- if command is null<V> Map<Member,IScheduledFuture<V>> scheduleOnAllMembers(Callable<V> command, long delay, TimeUnit unit)
Member
s.
command
- the task to executedelay
- the time from now to delay executionunit
- the time unit of the delay parameterget()
method will return
null
upon completionRejectedExecutionException
- if the task cannot be
scheduled for executionNullPointerException
- if command is nullMap<Member,IScheduledFuture<?>> scheduleOnAllMembersAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit)
Member
s. Executions will commence after
initialDelay
then initialDelay+period
, then
initialDelay + 2 * period
, and so on.
If any execution of this task
takes longer than its period, then subsequent execution will be skipped.
command
- the task to executeinitialDelay
- the time to delay first executionperiod
- the period between successive executionsunit
- the time unit of the initialDelay and period parametersget()
method will throw an
exception upon cancellationRejectedExecutionException
- if the task cannot be
scheduled for executionNullPointerException
- if command is nullMap<Member,IScheduledFuture<?>> scheduleOnMembers(Runnable command, Collection<Member> members, long delay, TimeUnit unit)
Member
s given.
command
- the task to executemembers
- the collections of members - where to execute the taskdelay
- the time from now to delay executionunit
- the time unit of the delay parameterget()
method will return
null
upon completionRejectedExecutionException
- if the task cannot be
scheduled for executionNullPointerException
- if command is null<V> Map<Member,IScheduledFuture<V>> scheduleOnMembers(Callable<V> command, Collection<Member> members, long delay, TimeUnit unit)
Member
s given.
command
- the task to executemembers
- the collections of members - where to execute the taskdelay
- the time from now to delay executionunit
- the time unit of the delay parameterget()
method will return
null
upon completionRejectedExecutionException
- if the task cannot be
scheduled for executionNullPointerException
- if command is nullMap<Member,IScheduledFuture<?>> scheduleOnMembersAtFixedRate(Runnable command, Collection<Member> members, long initialDelay, long period, TimeUnit unit)
Member
s given. Executions will commence after
initialDelay
then initialDelay+period
, then
initialDelay + 2 * period
, and so on.
If any execution of this task
takes longer than its period, then subsequent execution will be skipped.
command
- the task to executemembers
- the collections of members - where to execute the taskinitialDelay
- the time to delay first executionperiod
- the period between successive executionsunit
- the time unit of the initialDelay and period parametersget()
method will throw an
exception upon cancellationRejectedExecutionException
- if the task cannot be
scheduled for executionNullPointerException
- if command is null<V> IScheduledFuture<V> getScheduledFuture(ScheduledTaskHandler handler)
IScheduledFuture
from the given handler.
This is useful in case your member node or client from which the original
scheduling happened, went down, and now you want to access the ScheduledFuture again.V
- The return type of callable taskshandler
- The handler of the task as found from IScheduledFuture.getHandler()
IScheduledFuture
from the given handler.<V> Map<Member,List<IScheduledFuture<V>>> getAllScheduledFutures()
Map
.Map
with Member
keys and a List of IScheduledFuture
found for this scheduler.void shutdown()
This method does not wait for previously submitted tasks to complete execution.
Copyright © 2018 Hazelcast, Inc.. All Rights Reserved.