public interface IgniteCompute extends IgniteAsyncSupport
ClusterGroup
.
IgniteCompute
is obtained from Ignite
as follows:
Ignite ignite = Ignition.ignite(); // Compute over all nodes in the cluster. IgniteCompute c = ignite.compute();You can also get an instance of
IgniteCompute
over a subset of cluster nodes, i.e. over
a ClusterGroup
:
// Cluster group composed of all remote nodes. ClusterGroup rmtGrp = ignite.cluster().forRemotes(); // Compute over remote nodes only. IgniteCompute c = ignite.compute(rmtGrp);The methods are grouped as follows:
apply(...)
methods execute IgniteClosure
jobs over nodes in the cluster group.call(...)
methods execute IgniteCallable
jobs over nodes in the cluster group.run(...)
methods execute IgniteRunnable
jobs over nodes in the cluster group.broadcast(...)
methods broadcast jobs to all nodes in the cluster group.affinityCall(...)
and affinityRun(...)
methods collocate jobs with nodes
on which a specified key is cached.ClusterGroupEmptyException
will be thrown out of result future.
broadcast(...)
, Ignite must select a node for a computation
to be executed. The node will be selected based on the underlying LoadBalancingSpi
,
which by default sequentially picks next available node from the underlying cluster group. Other
load balancing policies, such as random
or adaptive
, can be configured as well by
selecting a different load balancing SPI in Ignite configuration. If your logic requires some custom
load balancing behavior, consider implementing ComputeTask
directly.
FailoverSpi
in grid configuration.
TaskSessionResource
IgniteInstanceResource
LoggerResource
SpringApplicationContextResource
SpringResource
Ignite
into a computation:
public class MyIgniteJob extends IgniteRunnable { ... @IgniteInstanceResource private Ignite ignite; ... }
ComputeTaskSpis
annotation. Refer to ComputeTask
documentation for more information.Modifier and Type | Method and Description |
---|---|
<R> Map<IgniteUuid,ComputeTaskFuture<R>> |
activeTaskFutures()
Gets tasks future for active tasks started on local node.
|
<R> R |
affinityCall(Collection<String> cacheNames,
int partId,
IgniteCallable<R> job)
Executes given job on the node where partition is located (the partition is primary on the node)
It's guaranteed that the data of all the partitions of all participating caches,
the affinity key belongs to, will present on the destination node throughout the job execution.
|
<R> R |
affinityCall(Collection<String> cacheNames,
Object affKey,
IgniteCallable<R> job)
Executes given job on the node where data for provided affinity key is located
(a.k.a. affinity co-location).
|
<R> R |
affinityCall(String cacheName,
Object affKey,
IgniteCallable<R> job)
Executes given job on the node where data for provided affinity key is located
(a.k.a. affinity co-location).
|
<R> IgniteFuture<R> |
affinityCallAsync(Collection<String> cacheNames,
int partId,
IgniteCallable<R> job)
Executes given job asynchronously on the node where partition is located (the partition is primary on the node)
The data of the partition will not be migrated from the target node
while the job is executed.
|
<R> IgniteFuture<R> |
affinityCallAsync(Collection<String> cacheNames,
Object affKey,
IgniteCallable<R> job)
Executes given job asynchronously on the node where data for provided affinity key is located
(a.k.a. affinity co-location).
|
<R> IgniteFuture<R> |
affinityCallAsync(String cacheName,
Object affKey,
IgniteCallable<R> job)
Executes given job asynchronously on the node where data for provided affinity key is located
(a.k.a. affinity co-location).
|
void |
affinityRun(Collection<String> cacheNames,
int partId,
IgniteRunnable job)
Executes given job on the node where partition is located (the partition is primary on the node)
It's guaranteed that the data of all the partitions of all participating caches,
the affinity key belongs to, will present on the destination node throughout the job execution.
|
void |
affinityRun(Collection<String> cacheNames,
Object affKey,
IgniteRunnable job)
Executes given job on the node where data for provided affinity key is located
(a.k.a. affinity co-location).
|
void |
affinityRun(String cacheName,
Object affKey,
IgniteRunnable job)
Executes given job on the node where data for provided affinity key is located
(a.k.a. affinity co-location).
|
IgniteFuture<Void> |
affinityRunAsync(Collection<String> cacheNames,
int partId,
IgniteRunnable job)
Executes given job asynchronously on the node where partition is located (the partition is primary on the node)
The data of the partition will not be migrated from the target node
while the job is executed.
|
IgniteFuture<Void> |
affinityRunAsync(Collection<String> cacheNames,
Object affKey,
IgniteRunnable job)
Executes given job asynchronously on the node where data for provided affinity key is located
(a.k.a. affinity co-location).
|
IgniteFuture<Void> |
affinityRunAsync(String cacheName,
Object affKey,
IgniteRunnable job)
Executes given job asynchronously on the node where data for provided affinity key is located
(a.k.a. affinity co-location).
|
<T,R> Collection<R> |
apply(IgniteClosure<T,R> job,
Collection<? extends T> args)
Executes provided closure job on nodes within the underlying cluster group.
|
<R,T> R |
apply(IgniteClosure<T,R> job,
T arg)
Executes provided closure job on a node within the underlying cluster group.
|
<R1,R2,T> R2 |
apply(IgniteClosure<T,R1> job,
Collection<? extends T> args,
IgniteReducer<R1,R2> rdc)
Executes provided closure job on nodes within the underlying cluster group.
|
<T,R> IgniteFuture<Collection<R>> |
applyAsync(IgniteClosure<T,R> job,
Collection<? extends T> args)
Executes provided closure job asynchronously on nodes within the underlying cluster group.
|
<R,T> IgniteFuture<R> |
applyAsync(IgniteClosure<T,R> job,
T arg)
Executes provided closure job asynchronously on a node within the underlying cluster group.
|
<R1,R2,T> IgniteFuture<R2> |
applyAsync(IgniteClosure<T,R1> job,
Collection<? extends T> args,
IgniteReducer<R1,R2> rdc)
Executes provided closure job asynchronously on nodes within the underlying cluster group.
|
<R> Collection<R> |
broadcast(IgniteCallable<R> job)
Broadcasts given job to all nodes in cluster group.
|
<R,T> Collection<R> |
broadcast(IgniteClosure<T,R> job,
T arg)
Broadcasts given closure job with passed in argument to all nodes in the cluster group.
|
void |
broadcast(IgniteRunnable job)
Broadcasts given job to all nodes in the cluster group.
|
<R> IgniteFuture<Collection<R>> |
broadcastAsync(IgniteCallable<R> job)
Broadcasts given job asynchronously to all nodes in cluster group.
|
<R,T> IgniteFuture<Collection<R>> |
broadcastAsync(IgniteClosure<T,R> job,
T arg)
Broadcasts given closure job asynchronously with passed in argument to all nodes in the cluster group.
|
IgniteFuture<Void> |
broadcastAsync(IgniteRunnable job)
Broadcasts given job asynchronously to all nodes in the cluster group.
|
<R> Collection<R> |
call(Collection<? extends IgniteCallable<R>> jobs)
Executes collection of jobs on nodes within the underlying cluster group.
|
<R1,R2> R2 |
call(Collection<? extends IgniteCallable<R1>> jobs,
IgniteReducer<R1,R2> rdc)
Executes collection of jobs on nodes within the underlying cluster group.
|
<R> R |
call(IgniteCallable<R> job)
Executes provided job on a node within the underlying cluster group.
|
<R> IgniteFuture<Collection<R>> |
callAsync(Collection<? extends IgniteCallable<R>> jobs)
Executes collection of jobs asynchronously on nodes within the underlying cluster group.
|
<R1,R2> IgniteFuture<R2> |
callAsync(Collection<? extends IgniteCallable<R1>> jobs,
IgniteReducer<R1,R2> rdc)
Executes collection of jobs asynchronously on nodes within the underlying cluster group.
|
<R> IgniteFuture<R> |
callAsync(IgniteCallable<R> job)
Executes provided job asynchronously on a node within the underlying cluster group.
|
ClusterGroup |
clusterGroup()
Gets cluster group to which this
IgniteCompute instance belongs. |
<T,R> R |
execute(Class<? extends ComputeTask<T,R>> taskCls,
T arg)
Executes given task on within the cluster group.
|
<T,R> R |
execute(ComputeTask<T,R> task,
T arg)
Executes given task within the cluster group.
|
<T,R> R |
execute(String taskName,
T arg)
Executes given task within the cluster group.
|
<T,R> ComputeTaskFuture<R> |
executeAsync(Class<? extends ComputeTask<T,R>> taskCls,
T arg)
Executes given task asynchronously on within the cluster group.
|
<T,R> ComputeTaskFuture<R> |
executeAsync(ComputeTask<T,R> task,
T arg)
Executes given task asynchronously within the cluster group.
|
<T,R> ComputeTaskFuture<R> |
executeAsync(String taskName,
T arg)
Executes given task asynchronously within the cluster group.
|
<R> ComputeTaskFuture<R> |
future()
Deprecated.
|
void |
localDeployTask(Class<? extends ComputeTask> taskCls,
ClassLoader clsLdr)
Explicitly deploys a task with given class loader on the local node.
|
Map<String,Class<? extends ComputeTask<?,?>>> |
localTasks()
Gets map of all locally deployed tasks keyed by their task name .
|
void |
run(Collection<? extends IgniteRunnable> jobs)
Executes collection of jobs on grid nodes within the underlying cluster group.
|
void |
run(IgniteRunnable job)
Executes provided job on a node within the underlying cluster group.
|
IgniteFuture<Void> |
runAsync(Collection<? extends IgniteRunnable> jobs)
Executes collection of jobs asynchronously on grid nodes within the underlying cluster group.
|
IgniteFuture<Void> |
runAsync(IgniteRunnable job)
Executes provided job asynchronously on a node within the underlying cluster group.
|
void |
undeployTask(String taskName)
Makes the best attempt to undeploy a task with given name within the underlying cluster group.
|
IgniteCompute |
withAsync()
Deprecated.
|
IgniteCompute |
withExecutor(String name)
Gets instance of the compute API associated with custom executor.
|
IgniteCompute |
withName(String taskName)
Sets task name for the next executed task in the current thread.
|
IgniteCompute |
withNoFailover()
Sets no-failover flag for the next task executed in the current thread.
|
IgniteCompute |
withNoResultCache()
Disables caching for the next executed task in the current thread.
|
IgniteCompute |
withTimeout(long timeout)
Sets task timeout for the next executed task in the current thread.
|
isAsync
ClusterGroup clusterGroup()
IgniteCompute
instance belongs.IgniteCompute
instance belongs.void affinityRun(String cacheName, Object affKey, IgniteRunnable job) throws IgniteException
cacheName
- Name of the cache to use for affinity co-location.affKey
- Affinity key.job
- Job which will be co-located on the node with given affinity key.IgniteException
- If job failed.IgniteFuture<Void> affinityRunAsync(String cacheName, Object affKey, IgniteRunnable job) throws IgniteException
cacheName
- Name of the cache to use for affinity co-location.affKey
- Affinity key.job
- Job which will be co-located on the node with given affinity key.IgniteException
- If job failed.void affinityRun(Collection<String> cacheNames, Object affKey, IgniteRunnable job) throws IgniteException
cacheNames
- Names of the caches to to reserve the partition. The first cache is used for
affinity co-location.affKey
- Affinity key.job
- Job which will be co-located on the node with given affinity key.NullPointerException
- if cacheNames
is null
.IgniteException
- If job failed.IgniteFuture<Void> affinityRunAsync(Collection<String> cacheNames, Object affKey, IgniteRunnable job) throws IgniteException
cacheNames
- Names of the caches to to reserve the partition. The first cache uses for affinity co-location.affKey
- Affinity key.job
- Job which will be co-located on the node with given affinity key.NullPointerException
- if cacheNames
is null
.IgniteException
- If job failed.void affinityRun(Collection<String> cacheNames, int partId, IgniteRunnable job) throws IgniteException
cacheNames
- Names of the caches to to reserve the partition. The first cache is used for
affinity co-location.partId
- Partition number.job
- Job which will be co-located on the node with given affinity key.NullPointerException
- if cacheNames
is null
.IgniteException
- If job failed.IgniteFuture<Void> affinityRunAsync(Collection<String> cacheNames, int partId, IgniteRunnable job) throws IgniteException
cacheNames
- Names of the caches to to reserve the partition. The first cache uses for affinity co-location.partId
- Partition number.job
- Job which will be co-located on the node with given affinity key.NullPointerException
- if cacheNames
is null
.IgniteException
- If job failed.<R> R affinityCall(String cacheName, Object affKey, IgniteCallable<R> job) throws IgniteException
cacheName
- Name of the cache to use for affinity co-location.affKey
- Affinity key.job
- Job which will be co-located on the node with given affinity key.IgniteException
- If job failed.<R> IgniteFuture<R> affinityCallAsync(String cacheName, Object affKey, IgniteCallable<R> job) throws IgniteException
cacheName
- Name of the cache to use for affinity co-location.affKey
- Affinity key.job
- Job which will be co-located on the node with given affinity key.IgniteException
- If job failed.<R> R affinityCall(Collection<String> cacheNames, Object affKey, IgniteCallable<R> job) throws IgniteException
cacheNames
- Names of the caches to to reserve the partition. The first cache uses for affinity co-location.affKey
- Affinity key.job
- Job which will be co-located on the node with given affinity key.NullPointerException
- if cacheNames
is null
.IgniteException
- If job failed.<R> IgniteFuture<R> affinityCallAsync(Collection<String> cacheNames, Object affKey, IgniteCallable<R> job) throws IgniteException
cacheNames
- Names of the caches to to reserve the partition. The first cache uses for affinity co-location.affKey
- Affinity key.job
- Job which will be co-located on the node with given affinity key.NullPointerException
- if cacheNames
is null
.IgniteException
- If job failed.<R> R affinityCall(Collection<String> cacheNames, int partId, IgniteCallable<R> job) throws IgniteException
cacheNames
- Names of the caches to to reserve the partition. The first cache uses for affinity co-location.partId
- Partition to reserve.job
- Job which will be co-located on the node with given affinity key.NullPointerException
- if cacheNames
is null
.IgniteException
- If job failed.<R> IgniteFuture<R> affinityCallAsync(Collection<String> cacheNames, int partId, IgniteCallable<R> job) throws IgniteException
cacheNames
- Names of the caches to to reserve the partition. The first cache uses for affinity co-location.partId
- Partition to reserve.job
- Job which will be co-located on the node with given affinity key.NullPointerException
- if cacheNames
is null
.IgniteException
- If job failed.<T,R> R execute(Class<? extends ComputeTask<T,R>> taskCls, T arg) throws IgniteException
ComputeTask
documentation.taskCls
- Class of the task to execute. If class has ComputeTaskName
annotation,
then task is deployed under a name specified within annotation. Otherwise, full
class name is used as task name.arg
- Optional argument of task execution, can be null
.IgniteException
- If task failed.<T,R> ComputeTaskFuture<R> executeAsync(Class<? extends ComputeTask<T,R>> taskCls, T arg) throws IgniteException
ComputeTask
documentation.taskCls
- Class of the task to execute. If class has ComputeTaskName
annotation,
then task is deployed under a name specified within annotation. Otherwise, full
class name is used as task name.arg
- Optional argument of task execution, can be null
.IgniteException
- If task failed.<T,R> R execute(ComputeTask<T,R> task, T arg) throws IgniteException
ComputeTask
documentation.task
- Instance of task to execute. If task class has ComputeTaskName
annotation,
then task is deployed under a name specified within annotation. Otherwise, full
class name is used as task name.arg
- Optional argument of task execution, can be null
.IgniteException
- If task failed.<T,R> ComputeTaskFuture<R> executeAsync(ComputeTask<T,R> task, T arg) throws IgniteException
ComputeTask
documentation.task
- Instance of task to execute. If task class has ComputeTaskName
annotation,
then task is deployed under a name specified within annotation. Otherwise, full
class name is used as task name.arg
- Optional argument of task execution, can be null
.IgniteException
- If task failed.<T,R> R execute(String taskName, @Nullable T arg) throws IgniteException
ComputeTask
documentation.
If task for given name has not been deployed yet, then taskName
will be
used as task class name to auto-deploy the task (see localDeployTask(Class, ClassLoader)
method).
If there are more one class deployed with the same name this method will execute the lasts one deployed of them. This method has no guarantees if it invokes where classes with the same names deployed from different threads.
taskName
- Name of the task to execute.arg
- Optional argument of task execution, can be null
.IgniteException
- If task failed.for information about task execution.
<T,R> ComputeTaskFuture<R> executeAsync(String taskName, T arg) throws IgniteException
ComputeTask
documentation.
If task for given name has not been deployed yet, then taskName
will be
used as task class name to auto-deploy the task (see localDeployTask(Class, ClassLoader)
method).
taskName
- Name of the task to execute.arg
- Optional argument of task execution, can be null
.IgniteException
- If task failed.for information about task execution.
void broadcast(IgniteRunnable job) throws IgniteException
job
- Job to broadcast to all cluster group nodes.IgniteException
- If job failed.IgniteFuture<Void> broadcastAsync(IgniteRunnable job) throws IgniteException
job
- Job to broadcast to all cluster group nodes.IgniteException
- If job failed.<R> Collection<R> broadcast(IgniteCallable<R> job) throws IgniteException
job
- Job to broadcast to all cluster group nodes.IgniteException
- If execution failed.<R> IgniteFuture<Collection<R>> broadcastAsync(IgniteCallable<R> job) throws IgniteException
job
- Job to broadcast to all cluster group nodes.IgniteException
- If execution failed.<R,T> Collection<R> broadcast(IgniteClosure<T,R> job, T arg) throws IgniteException
job
- Job to broadcast to all cluster group nodes.arg
- Job closure argument.IgniteException
- If execution failed.<R,T> IgniteFuture<Collection<R>> broadcastAsync(IgniteClosure<T,R> job, T arg) throws IgniteException
job
- Job to broadcast to all cluster group nodes.arg
- Job closure argument.IgniteException
- If execution failed.void run(IgniteRunnable job) throws IgniteException
job
- Job closure to execute.IgniteException
- If execution failed.IgniteFuture<Void> runAsync(IgniteRunnable job) throws IgniteException
job
- Job closure to execute.IgniteException
- If execution failed.void run(Collection<? extends IgniteRunnable> jobs) throws IgniteException
jobs
- Collection of jobs to execute.IgniteException
- If execution failed.IgniteFuture<Void> runAsync(Collection<? extends IgniteRunnable> jobs) throws IgniteException
jobs
- Collection of jobs to execute.IgniteException
- If execution failed.<R> R call(IgniteCallable<R> job) throws IgniteException
job
- Job to execute.IgniteException
- If execution failed.<R> IgniteFuture<R> callAsync(IgniteCallable<R> job) throws IgniteException
job
- Job to execute.IgniteException
- If execution failed.<R> Collection<R> call(Collection<? extends IgniteCallable<R>> jobs) throws IgniteException
jobs
- Non-empty collection of jobs to execute.IgniteException
- If execution failed.<R> IgniteFuture<Collection<R>> callAsync(Collection<? extends IgniteCallable<R>> jobs) throws IgniteException
jobs
- Non-empty collection of jobs to execute.IgniteException
- If execution failed.<R1,R2> R2 call(Collection<? extends IgniteCallable<R1>> jobs, IgniteReducer<R1,R2> rdc) throws IgniteException
jobs
- Non-empty collection of jobs to execute.rdc
- Reducer to reduce all job results into one individual return value.IgniteException
- If execution failed.<R1,R2> IgniteFuture<R2> callAsync(Collection<? extends IgniteCallable<R1>> jobs, IgniteReducer<R1,R2> rdc) throws IgniteException
jobs
- Non-empty collection of jobs to execute.rdc
- Reducer to reduce all job results into one individual return value.IgniteException
- If execution failed.<R,T> R apply(IgniteClosure<T,R> job, T arg) throws IgniteException
run(...)
and call(...)
methods in a way that it receives job argument
which is then passed into the closure at execution time.job
- Job to run.arg
- Job argument.IgniteException
- If execution failed.<R,T> IgniteFuture<R> applyAsync(IgniteClosure<T,R> job, T arg) throws IgniteException
run(...)
and call(...)
methods in a way that
it receives job argument which is then passed into the closure at execution time.job
- Job to run.arg
- Job argument.IgniteException
- If execution failed.<T,R> Collection<R> apply(IgniteClosure<T,R> job, Collection<? extends T> args) throws IgniteException
job
- Job to run.args
- Job arguments.IgniteException
- If execution failed.<T,R> IgniteFuture<Collection<R>> applyAsync(IgniteClosure<T,R> job, Collection<? extends T> args) throws IgniteException
job
- Job to run.args
- Job arguments.IgniteException
- If execution failed.<R1,R2,T> R2 apply(IgniteClosure<T,R1> job, Collection<? extends T> args, IgniteReducer<R1,R2> rdc) throws IgniteException
job
- Job to run.args
- Job arguments.rdc
- Reducer to reduce all job results into one individual return value.IgniteException
- If execution failed.<R1,R2,T> IgniteFuture<R2> applyAsync(IgniteClosure<T,R1> job, Collection<? extends T> args, IgniteReducer<R1,R2> rdc) throws IgniteException
job
- Job to run.args
- Job arguments.rdc
- Reducer to reduce all job results into one individual return value.IgniteException
- If execution failed.<R> Map<IgniteUuid,ComputeTaskFuture<R>> activeTaskFutures()
IgniteCompute withName(String taskName)
ComputeTask
.
Here is an example.
ignite.withName("MyTask").run(new IgniteRunnable() {...});
taskName
- Task name.IgniteCompute
instance for chaining calls.IgniteCompute withTimeout(long timeout)
ComputeTask
.
Here is an example.
ignite.withTimeout(10000).run(new IgniteRunnable() {...});
timeout
- Computation timeout in milliseconds.IgniteCompute
instance for chaining calls.IgniteCompute withNoFailover()
Here is an example.
ignite.compute().withNoFailover().run(new IgniteRunnable() {...});
IgniteCompute
instance for chaining calls.IgniteCompute withNoResultCache()
ComputeTaskNoResultCache
.
Here is an example.
ignite.compute().withNoResultCache().run(new IgniteRunnable() {...});
IgniteCompute
instance for chaining calls.void localDeployTask(Class<? extends ComputeTask> taskCls, ClassLoader clsLdr) throws IgniteException
Note that tasks are automatically deployed upon first execution (if peer-class-loading is enabled),
so use this method only when the provided class loader is different from the
taskClass.getClassLoader()
.
Another way of class deployment is deployment from local class path. Classes from local class path always have a priority over P2P deployed ones.
Note that class can be deployed multiple times on remote nodes, i.e. re-deployed. Ignition maintains internal version of deployment for each instance of deployment (analogous to class and class loader in Java). Execution happens always on the latest deployed instance.
This method has no effect if the class passed in was already deployed.
taskCls
- Task class to deploy. If task class has ComputeTaskName
annotation,
then task will be deployed under the name specified within annotation. Otherwise, full
class name will be used as task's name.clsLdr
- Task class loader. This class loader is in charge
of loading all necessary resources for task execution.IgniteException
- If task is invalid and cannot be deployed.Map<String,Class<? extends ComputeTask<?,?>>> localTasks()
void undeployTask(String taskName) throws IgniteException
taskName
- Name of the task to undeploy.IgniteException
- Thrown if undeploy failed.@Deprecated <R> ComputeTaskFuture<R> future()
future
in interface IgniteAsyncSupport
@Deprecated IgniteCompute withAsync()
withAsync
in interface IgniteAsyncSupport
IgniteCompute withExecutor(String name)
Executor should be defined in IgniteConfiguration.setExecutorConfiguration(ExecutorConfiguration...)
.
name
- Custom executor name. If null
, the returned instance will execute tasks in
default thread pool.
GridGain In-Memory Computing Platform : ver. 8.9.15 Release Date : December 3 2024