Interface IgniteCompute
-
- All Superinterfaces:
IgniteAsyncSupport
public interface IgniteCompute extends IgniteAsyncSupport
Defines compute grid functionality for executing tasks and closures over nodes in theClusterGroup
. Instance ofIgniteCompute
is obtained fromIgnite
as follows:Ignite ignite = Ignition.ignite(); // Compute over all nodes in the cluster. IgniteCompute c = ignite.compute();
You can also get an instance ofIgniteCompute
over a subset of cluster nodes, i.e. over aClusterGroup
:// 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 executeIgniteClosure
jobs over nodes in the cluster group.call(...)
methods executeIgniteCallable
jobs over nodes in the cluster group.run(...)
methods executeIgniteRunnable
jobs over nodes in the cluster group.broadcast(...)
methods broadcast jobs to all nodes in the cluster group.affinityCall(...)
andaffinityRun(...)
methods collocate jobs with nodes on which a specified key is cached.
ClusterGroupEmptyException
will be thrown out of result future.Load Balancing
In all cases other thanbroadcast(...)
, Ignite must select a node for a computation to be executed. The node will be selected based on the underlyingLoadBalancingSpi
, which by default sequentially picks next available node from the underlying cluster group. Other load balancing policies, such asrandom
oradaptive
, 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 implementingComputeTask
directly.Fault Tolerance
Ignite guarantees that as long as there is at least one grid node standing, every job will be executed. Jobs will automatically failover to another node if a remote node crashed or has rejected execution due to lack of resources. By default, in case of failover, next load balanced node will be picked for job execution. Also jobs will never be re-routed to the nodes they have failed on. This behavior can be changed by configuring any of the existing or a customFailoverSpi
in grid configuration.Resource Injection
All compute jobs, including closures, runnables, callables, and tasks can be injected with ignite resources. Both, field and method based injections are supported. The following grid resources can be injected:TaskSessionResource
IgniteInstanceResource
LoggerResource
SpringApplicationContextResource
SpringResource
Ignite
into a computation:public class MyIgniteJob extends IgniteRunnable { ... @IgniteInstanceResource private Ignite ignite; ... }
Computation SPIs
Note that regardless of which method is used for executing computations, all relevant SPI implementations configured for this compute instance will be used (i.e. failover, load balancing, collision resolution, checkpoints, etc.). If you need to override configured defaults, you should use compute task together withComputeTaskSpis
annotation. Refer toComputeTask
documentation for more information.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description <R> Map<IgniteUuid,ComputeTaskFuture<R>>
activeTaskFutures()
Gets tasks future for active tasks started on local node.<R> R
affinityCall(@NotNull 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)<R> R
affinityCall(@NotNull 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(@NotNull 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(@NotNull 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(@NotNull Collection<String> cacheNames, int partId, IgniteRunnable job)
Executes given job on the node where partition is located (the partition is primary on the node)void
affinityRun(@NotNull 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(@NotNull 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(@NotNull 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>
Rapply(IgniteClosure<T,R> job, T arg)
Executes provided closure job on a node within the underlying cluster group.<R1,R2,T>
R2apply(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>
R2call(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 thisIgniteCompute
instance belongs.<T,R>
Rexecute(Class<? extends ComputeTask<T,R>> taskCls, T arg)
Executes given task on within the cluster group.<T,R>
Rexecute(String taskName, T arg)
Executes given task within the cluster group.<T,R>
Rexecute(ComputeTask<T,R> task, 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(String taskName, T arg)
Executes given task asynchronously within the cluster group.<T,R>
ComputeTaskFuture<R>executeAsync(ComputeTask<T,R> task, 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(@NotNull 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.-
Methods inherited from interface org.apache.ignite.lang.IgniteAsyncSupport
isAsync
-
-
-
-
Method Detail
-
clusterGroup
ClusterGroup clusterGroup()
Gets cluster group to which thisIgniteCompute
instance belongs.- Returns:
- Cluster group to which this
IgniteCompute
instance belongs.
-
affinityRun
@IgniteAsyncSupported void affinityRun(String cacheName, Object affKey, IgniteRunnable job) throws IgniteException
Executes given job on the node where data for provided affinity key is located (a.k.a. affinity co-location). It's guaranteed that the data of the whole partition, the affinity key belongs to, will present on the destination node throughout the job execution.- Parameters:
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.- Throws:
IgniteException
- If job failed.
-
affinityRunAsync
IgniteFuture<Void> affinityRunAsync(String cacheName, Object affKey, IgniteRunnable job) throws IgniteException
Executes given job asynchronously on the node where data for provided affinity key is located (a.k.a. affinity co-location). The data of the partition where affKey is stored will not be migrated from the target node while the job is executed.- Parameters:
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.- Returns:
- a Future representing pending completion of the affinity run.
- Throws:
IgniteException
- If job failed.
-
affinityRun
@IgniteAsyncSupported void affinityRun(@NotNull @NotNull Collection<String> cacheNames, Object affKey, IgniteRunnable job) throws IgniteException
Executes given job on the node where data for provided affinity key is located (a.k.a. affinity co-location). 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.- Parameters:
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.- Throws:
IgniteException
- If job failed.
-
affinityRunAsync
IgniteFuture<Void> affinityRunAsync(@NotNull @NotNull Collection<String> cacheNames, Object affKey, IgniteRunnable job) throws IgniteException
Executes given job asynchronously on the node where data for provided affinity key is located (a.k.a. affinity co-location). The data of the partition where affKey is stored will not be migrated from the target node while the job is executed. The data of the extra caches' partitions with the same partition number also will not be migrated.- Parameters:
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.- Returns:
- a Future representing pending completion of the affinity run.
- Throws:
IgniteException
- If job failed.
-
affinityRun
@IgniteAsyncSupported void affinityRun(@NotNull @NotNull Collection<String> cacheNames, int partId, IgniteRunnable job) throws IgniteException
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.- Parameters:
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.- Throws:
IgniteException
- If job failed.
-
affinityRunAsync
IgniteFuture<Void> affinityRunAsync(@NotNull @NotNull Collection<String> cacheNames, int partId, IgniteRunnable job) throws IgniteException
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. The data of the extra caches' partitions with the same partition number also will not be migrated.- Parameters:
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.- Returns:
- a Future representing pending completion of the affinity run.
- Throws:
IgniteException
- If job failed.
-
affinityCall
@IgniteAsyncSupported <R> R affinityCall(String cacheName, Object affKey, IgniteCallable<R> job) throws IgniteException
Executes given job on the node where data for provided affinity key is located (a.k.a. affinity co-location). It's guaranteed that the data of the whole partition, the affinity key belongs to, will present on the destination node throughout the job execution.- Type Parameters:
R
- Type of the job result.- Parameters:
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.- Returns:
- Job result.
- Throws:
IgniteException
- If job failed.
-
affinityCallAsync
<R> IgniteFuture<R> affinityCallAsync(String cacheName, Object affKey, IgniteCallable<R> job) throws IgniteException
Executes given job asynchronously on the node where data for provided affinity key is located (a.k.a. affinity co-location). The data of the partition where affKey is stored will not be migrated from the target node while the job is executed.- Type Parameters:
R
- Type of the job result.- Parameters:
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.- Returns:
- a Future representing pending completion of the affinity call.
- Throws:
IgniteException
- If job failed.
-
affinityCall
@IgniteAsyncSupported <R> R affinityCall(@NotNull @NotNull Collection<String> cacheNames, Object affKey, IgniteCallable<R> job) throws IgniteException
Executes given job on the node where data for provided affinity key is located (a.k.a. affinity co-location). 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.- Type Parameters:
R
- Type of the job result.- Parameters:
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.- Returns:
- Job result.
- Throws:
IgniteException
- If job failed.
-
affinityCallAsync
<R> IgniteFuture<R> affinityCallAsync(@NotNull @NotNull Collection<String> cacheNames, Object affKey, IgniteCallable<R> job) throws IgniteException
Executes given job asynchronously on the node where data for provided affinity key is located (a.k.a. affinity co-location). The data of the partition where affKey is stored will not be migrated from the target node while the job is executed. The data of the extra caches' partitions with the same partition number also will not be migrated.- Type Parameters:
R
- Type of the job result.- Parameters:
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.- Returns:
- a Future representing pending completion of the affinity call.
- Throws:
IgniteException
- If job failed.
-
affinityCall
@IgniteAsyncSupported <R> R affinityCall(@NotNull @NotNull Collection<String> cacheNames, int partId, IgniteCallable<R> job) throws IgniteException
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.- Type Parameters:
R
- Type of the job result.- Parameters:
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.- Returns:
- Job result.
- Throws:
IgniteException
- If job failed.
-
affinityCallAsync
<R> IgniteFuture<R> affinityCallAsync(@NotNull @NotNull Collection<String> cacheNames, int partId, IgniteCallable<R> job) throws IgniteException
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. The data of the extra caches' partitions with the same partition number also will not be migrated.- Type Parameters:
R
- Type of the job result.- Parameters:
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.- Returns:
- a Future representing pending completion of the affinity call.
- Throws:
IgniteException
- If job failed.
-
execute
@IgniteAsyncSupported <T,R> R execute(Class<? extends ComputeTask<T,R>> taskCls, @Nullable T arg) throws IgniteException
Executes given task on within the cluster group. For step-by-step explanation of task execution process refer toComputeTask
documentation.- Type Parameters:
R
- Type of the task result.T
- Type of the task argument.- Parameters:
taskCls
- Class of the task to execute. If class hasComputeTaskName
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 benull
.- Returns:
- Task result.
- Throws:
IgniteException
- If task failed.
-
executeAsync
<T,R> ComputeTaskFuture<R> executeAsync(Class<? extends ComputeTask<T,R>> taskCls, @Nullable T arg) throws IgniteException
Executes given task asynchronously on within the cluster group. For step-by-step explanation of task execution process refer toComputeTask
documentation.- Type Parameters:
R
- Type of the task result.T
- Type of the task argument.- Parameters:
taskCls
- Class of the task to execute. If class hasComputeTaskName
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 benull
.- Returns:
- a Future representing pending completion of the task.
- Throws:
IgniteException
- If task failed.
-
execute
@IgniteAsyncSupported <T,R> R execute(ComputeTask<T,R> task, @Nullable T arg) throws IgniteException
Executes given task within the cluster group. For step-by-step explanation of task execution process refer toComputeTask
documentation.- Type Parameters:
R
- Type of the task result.T
- Type of the task argument.- Parameters:
task
- Instance of task to execute. If task class hasComputeTaskName
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 benull
.- Returns:
- Task result.
- Throws:
IgniteException
- If task failed.
-
executeAsync
<T,R> ComputeTaskFuture<R> executeAsync(ComputeTask<T,R> task, @Nullable T arg) throws IgniteException
Executes given task asynchronously within the cluster group. For step-by-step explanation of task execution process refer toComputeTask
documentation.- Type Parameters:
R
- type.T
- type.- Parameters:
task
- Instance of task to execute. If task class hasComputeTaskName
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 benull
.- Returns:
- a Future representing pending completion of the task.
- Throws:
IgniteException
- If task failed.
-
execute
@IgniteAsyncSupported <T,R> R execute(String taskName, @Nullable T arg) throws IgniteException
Executes given task within the cluster group. For step-by-step explanation of task execution process refer toComputeTask
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 (seelocalDeployTask(Class, ClassLoader)
method).If class with the same name was deployed more than once, the last deployed version is used. If method is called when other threads are deploying other versions of class with the same name there are no guarantees which version of the class will be executed.
- Type Parameters:
R
- Type of the task result.T
- Type of the task argument.- Parameters:
taskName
- Name of the task to execute.arg
- Optional argument of task execution, can benull
.- Returns:
- Task result.
- Throws:
IgniteException
- If task failed.- See Also:
for information about task execution.
-
executeAsync
<T,R> ComputeTaskFuture<R> executeAsync(String taskName, @Nullable T arg) throws IgniteException
Executes given task asynchronously within the cluster group. For step-by-step explanation of task execution process refer toComputeTask
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 (seelocalDeployTask(Class, ClassLoader)
method).- Type Parameters:
R
- Type of the task result.T
- Type of the task argument.- Parameters:
taskName
- Name of the task to execute.arg
- Optional argument of task execution, can benull
.- Returns:
- a Future representing pending completion of the task.
- Throws:
IgniteException
- If task failed.- See Also:
for information about task execution.
-
broadcast
@IgniteAsyncSupported void broadcast(IgniteRunnable job) throws IgniteException
Broadcasts given job to all nodes in the cluster group.- Parameters:
job
- Job to broadcast to all cluster group nodes.- Throws:
IgniteException
- If job failed.
-
broadcastAsync
IgniteFuture<Void> broadcastAsync(IgniteRunnable job) throws IgniteException
Broadcasts given job asynchronously to all nodes in the cluster group.- Parameters:
job
- Job to broadcast to all cluster group nodes.- Returns:
- a Future representing pending completion of the broadcast execution of the job.
- Throws:
IgniteException
- If job failed.
-
broadcast
@IgniteAsyncSupported <R> Collection<R> broadcast(IgniteCallable<R> job) throws IgniteException
Broadcasts given job to all nodes in cluster group. Every participating node will return a job result. Collection of all returned job results is returned from the result future.- Type Parameters:
R
- Type of the job result.- Parameters:
job
- Job to broadcast to all cluster group nodes.- Returns:
- Collection of results for this execution.
- Throws:
IgniteException
- If execution failed.
-
broadcastAsync
<R> IgniteFuture<Collection<R>> broadcastAsync(IgniteCallable<R> job) throws IgniteException
Broadcasts given job asynchronously to all nodes in cluster group. Every participating node will return a job result. Collection of all returned job results is returned from the result future.- Type Parameters:
R
- Type of the job result.- Parameters:
job
- Job to broadcast to all cluster group nodes.- Returns:
- a Future representing pending completion of the broadcast execution of the job.
- Throws:
IgniteException
- If execution failed.
-
broadcast
@IgniteAsyncSupported <R,T> Collection<R> broadcast(IgniteClosure<T,R> job, @Nullable T arg) throws IgniteException
Broadcasts given closure job with passed in argument to all nodes in the cluster group. Every participating node will return a job result. Collection of all returned job results is returned from the result future.- Type Parameters:
R
- Type of the job result.T
- Type of the job argument.- Parameters:
job
- Job to broadcast to all cluster group nodes.arg
- Job closure argument.- Returns:
- Collection of results for this execution.
- Throws:
IgniteException
- If execution failed.
-
broadcastAsync
<R,T> IgniteFuture<Collection<R>> broadcastAsync(IgniteClosure<T,R> job, @Nullable T arg) throws IgniteException
Broadcasts given closure job asynchronously with passed in argument to all nodes in the cluster group. Every participating node will return a job result. Collection of all returned job results is returned from the result future.- Type Parameters:
R
- Type of the job result.T
- Type of the job argument.- Parameters:
job
- Job to broadcast to all cluster group nodes.arg
- Job closure argument.- Returns:
- a Future representing pending completion of the broadcast execution of the job.
- Throws:
IgniteException
- If execution failed.
-
run
@IgniteAsyncSupported void run(IgniteRunnable job) throws IgniteException
Executes provided job on a node within the underlying cluster group.- Parameters:
job
- Job closure to execute.- Throws:
IgniteException
- If execution failed.
-
runAsync
IgniteFuture<Void> runAsync(IgniteRunnable job) throws IgniteException
Executes provided job asynchronously on a node within the underlying cluster group.- Parameters:
job
- Job closure to execute.- Returns:
- a Future representing pending completion of the job.
- Throws:
IgniteException
- If execution failed.
-
run
@IgniteAsyncSupported void run(Collection<? extends IgniteRunnable> jobs) throws IgniteException
Executes collection of jobs on grid nodes within the underlying cluster group.- Parameters:
jobs
- Collection of jobs to execute.- Throws:
IgniteException
- If execution failed.
-
runAsync
IgniteFuture<Void> runAsync(Collection<? extends IgniteRunnable> jobs) throws IgniteException
Executes collection of jobs asynchronously on grid nodes within the underlying cluster group. Executes asynchronously. Returns control immediately.- Parameters:
jobs
- Collection of jobs to execute.- Returns:
- a Future representing pending completion of the job.
- Throws:
IgniteException
- If execution failed.
-
call
@IgniteAsyncSupported <R> R call(IgniteCallable<R> job) throws IgniteException
Executes provided job on a node within the underlying cluster group. The result of the job execution is returned from the result closure.- Type Parameters:
R
- Type of the job result.- Parameters:
job
- Job to execute.- Returns:
- Job result.
- Throws:
IgniteException
- If execution failed.
-
callAsync
<R> IgniteFuture<R> callAsync(IgniteCallable<R> job) throws IgniteException
Executes provided job asynchronously on a node within the underlying cluster group. The result of the job execution is returned from the result closure.- Type Parameters:
R
- Type of the job result.- Parameters:
job
- Job to execute.- Returns:
- a Future representing pending completion of the job.
- Throws:
IgniteException
- If execution failed.
-
call
@IgniteAsyncSupported <R> Collection<R> call(Collection<? extends IgniteCallable<R>> jobs) throws IgniteException
Executes collection of jobs on nodes within the underlying cluster group. Collection of all returned job results is returned from the result future.- Type Parameters:
R
- Type of the jobs result.- Parameters:
jobs
- Non-empty collection of jobs to execute.- Returns:
- Collection of job results for this execution.
- Throws:
IgniteException
- If execution failed.
-
callAsync
<R> IgniteFuture<Collection<R>> callAsync(Collection<? extends IgniteCallable<R>> jobs) throws IgniteException
Executes collection of jobs asynchronously on nodes within the underlying cluster group. Collection of all returned job results is returned from the result future.- Type Parameters:
R
- Type of the job result.- Parameters:
jobs
- Non-empty collection of jobs to execute.- Returns:
- a Future representing pending completion of the job.
- Throws:
IgniteException
- If execution failed.
-
call
@IgniteAsyncSupported <R1,R2> R2 call(Collection<? extends IgniteCallable<R1>> jobs, IgniteReducer<R1,R2> rdc) throws IgniteException
Executes collection of jobs on nodes within the underlying cluster group. The returned job results will be reduced into an individual result by provided reducer.- Type Parameters:
R1
- Type of the job result.R2
- Type of the result returned by reducer.- Parameters:
jobs
- Non-empty collection of jobs to execute.rdc
- Reducer to reduce all job results into one individual return value.- Returns:
- Reduced job result for this execution.
- Throws:
IgniteException
- If execution failed.
-
callAsync
<R1,R2> IgniteFuture<R2> callAsync(Collection<? extends IgniteCallable<R1>> jobs, IgniteReducer<R1,R2> rdc) throws IgniteException
Executes collection of jobs asynchronously on nodes within the underlying cluster group. The returned job results will be reduced into an individual result by provided reducer.- Type Parameters:
R1
- Type of the job result.R2
- Type of the result returned by reducer.- Parameters:
jobs
- Non-empty collection of jobs to execute.rdc
- Reducer to reduce all job results into one individual return value.- Returns:
- a Future with reduced job result for this execution.
- Throws:
IgniteException
- If execution failed.
-
apply
@IgniteAsyncSupported <R,T> R apply(IgniteClosure<T,R> job, @Nullable T arg) throws IgniteException
Executes provided closure job on a node within the underlying cluster group. This method is different fromrun(...)
andcall(...)
methods in a way that it receives job argument which is then passed into the closure at execution time.- Type Parameters:
R
- Type of the job result.T
- Type of the job argument.- Parameters:
job
- Job to run.arg
- Job argument.- Returns:
- Job result.
- Throws:
IgniteException
- If execution failed.
-
applyAsync
<R,T> IgniteFuture<R> applyAsync(IgniteClosure<T,R> job, @Nullable T arg) throws IgniteException
Executes provided closure job asynchronously on a node within the underlying cluster group. This method is different fromrun(...)
andcall(...)
methods in a way that it receives job argument which is then passed into the closure at execution time.- Type Parameters:
R
- Type of the job result.T
- Type of the job argument.- Parameters:
job
- Job to run.arg
- Job argument.- Returns:
- a Future representing pending completion of the job.
- Throws:
IgniteException
- If execution failed.
-
apply
@IgniteAsyncSupported <T,R> Collection<R> apply(IgniteClosure<T,R> job, Collection<? extends T> args) throws IgniteException
Executes provided closure job on nodes within the underlying cluster group. A new job is executed for every argument in the passed in collection. The number of actual job executions will be equal to size of the job arguments collection.- Type Parameters:
R
- Type of the job result.T
- Type of the job argument.- Parameters:
job
- Job to run.args
- Job arguments.- Returns:
- Collection of job results.
- Throws:
IgniteException
- If execution failed.
-
applyAsync
<T,R> IgniteFuture<Collection<R>> applyAsync(IgniteClosure<T,R> job, Collection<? extends T> args) throws IgniteException
Executes provided closure job asynchronously on nodes within the underlying cluster group. A new job is executed for every argument in the passed in collection. The number of actual job executions will be equal to size of the job arguments collection.- Type Parameters:
R
- Type of the job result.T
- Type of the job argument.- Parameters:
job
- Job to run.args
- Job arguments.- Returns:
- a Future representing pending completion of the job.
- Throws:
IgniteException
- If execution failed.
-
apply
@IgniteAsyncSupported <R1,R2,T> R2 apply(IgniteClosure<T,R1> job, Collection<? extends T> args, IgniteReducer<R1,R2> rdc) throws IgniteException
Executes provided closure job on nodes within the underlying cluster group. A new job is executed for every argument in the passed in collection. The number of actual job executions will be equal to size of the job arguments collection. The returned job results will be reduced into an individual result by provided reducer.- Type Parameters:
R1
- Type of the job result.R2
- Type of the reducer argument.T
- Type of the job argument.- Parameters:
job
- Job to run.args
- Job arguments.rdc
- Reducer to reduce all job results into one individual return value.- Returns:
- Reduced job result for this execution.
- Throws:
IgniteException
- If execution failed.
-
applyAsync
<R1,R2,T> IgniteFuture<R2> applyAsync(IgniteClosure<T,R1> job, Collection<? extends T> args, IgniteReducer<R1,R2> rdc) throws IgniteException
Executes provided closure job asynchronously on nodes within the underlying cluster group. A new job is executed for every argument in the passed in collection. The number of actual job executions will be equal to size of the job arguments collection. The returned job results will be reduced into an individual result by provided reducer.- Type Parameters:
R1
- Type of the job result.R2
- Type of the reducer argument.T
- Type of the job argument.- Parameters:
job
- Job to run.args
- Job arguments.rdc
- Reducer to reduce all job results into one individual return value.- Returns:
- a Future with reduced job result for this execution.
- Throws:
IgniteException
- If execution failed.
-
activeTaskFutures
<R> Map<IgniteUuid,ComputeTaskFuture<R>> activeTaskFutures()
Gets tasks future for active tasks started on local node.- Type Parameters:
R
- Type of the task result.- Returns:
- Map of active tasks keyed by their task task session ID.
-
withName
IgniteCompute withName(String taskName)
Sets task name for the next executed task in the current thread. When task starts execution, the name is reset, so one name is used only once. You may use this method to set task name when executing jobs directly, without explicitly definingComputeTask
.Here is an example.
ignite.withName("MyTask").run(new IgniteRunnable() {...});
- Parameters:
taskName
- Task name.- Returns:
- This
IgniteCompute
instance for chaining calls.
-
withTimeout
IgniteCompute withTimeout(long timeout)
Sets task timeout for the next executed task in the current thread. When task starts execution, the timeout is reset, so one timeout is used only once.Here is an example.
ignite.withTimeout(10000).run(new IgniteRunnable() {...});
- Parameters:
timeout
- Computation timeout in milliseconds.- Returns:
- This
IgniteCompute
instance for chaining calls.
-
withNoFailover
IgniteCompute withNoFailover()
Sets no-failover flag for the next task executed in the current thread. If flag is set, job will be never failed over even if remote node crashes or rejects execution. When task starts execution, the no-failover flag is reset, so all other task will use default failover policy, unless this flag is set again.Here is an example.
ignite.compute().withNoFailover().run(new IgniteRunnable() {...});
- Returns:
- This
IgniteCompute
instance for chaining calls.
-
withNoResultCache
IgniteCompute withNoResultCache()
Disables caching for the next executed task in the current thread. Has the same behaviour as annotationComputeTaskNoResultCache
.Here is an example.
ignite.compute().withNoResultCache().run(new IgniteRunnable() {...});
- Returns:
- This
IgniteCompute
instance for chaining calls.
-
localDeployTask
void localDeployTask(Class<? extends ComputeTask> taskCls, ClassLoader clsLdr) throws IgniteException
Explicitly deploys a task with given class loader on the local node. Upon completion of this method, a task can immediately be executed on the grid, considering that all participating remote nodes also have this task deployed.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.
- Parameters:
taskCls
- Task class to deploy. If task class hasComputeTaskName
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.- Throws:
IgniteException
- If task is invalid and cannot be deployed.
-
localTasks
Map<String,Class<? extends ComputeTask<?,?>>> localTasks()
Gets map of all locally deployed tasks keyed by their task name .- Returns:
- Map of locally deployed tasks keyed by their task name.
-
undeployTask
void undeployTask(String taskName) throws IgniteException
Makes the best attempt to undeploy a task with given name within the underlying cluster group. Note that this method returns immediately and does not wait until the task will actually be undeployed on every node.- Parameters:
taskName
- Name of the task to undeploy.- Throws:
IgniteException
- Thrown if undeploy failed.
-
future
@Deprecated <R> ComputeTaskFuture<R> future()
Deprecated.Gets and resets future for previous asynchronous operation.- Specified by:
future
in interfaceIgniteAsyncSupport
- Type Parameters:
R
- Type of the future result.- Returns:
- Future for previous asynchronous operation.
-
withAsync
@Deprecated IgniteCompute withAsync()
Deprecated.Gets instance of this component with asynchronous mode enabled.- Specified by:
withAsync
in interfaceIgniteAsyncSupport
- Returns:
- Instance of this component with asynchronous mode enabled.
-
withExecutor
IgniteCompute withExecutor(@NotNull @NotNull String name)
Gets instance of the compute API associated with custom executor. All tasks and closures submitted to returned instance will be processed by this executor on both remote and local nodes. If executor with the given name doesn't exist, task will be processed in default ("public") pool.Executor should be defined in
IgniteConfiguration.setExecutorConfiguration(ExecutorConfiguration...)
.- Parameters:
name
- Custom executor name.- Returns:
- Instance of compute API associated with custom executor.
-
-