Defines compute grid functionality for executing tasks and closures over nodes
in the
ClusterGroup. Instance of
IgniteCompute is obtained from
Igniteas 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.
Note that if attempt is made to execute a computation over an empty cluster group (i.e. cluster group
that does not have any alive nodes), then
org.apache.ignite.cluster.ClusterGroupEmptyExceptionwill be thrown out of result future.
Load Balancing
In all cases other than
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.
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 custom
FailoverSpi 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
Refer to corresponding resource documentation for more information.
Here is an example of how to inject instance of
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 with
ComputeTaskSpis annotation. Refer to
ComputeTask documentation for more information.