public interface IgniteCompute extends IgniteAsyncSupport
ClusterGroup
. Instance of GridCompute
is obtained from grid projection
as follows:
GridCompute c = Ignition.ignite().compute();The methods are grouped as follows:
apply(...)
methods execute IgniteClosure
jobs over nodes in the projection.call(...)
methods execute Callable
jobs over nodes in the projection.
Use IgniteCallable
for better performance as it implements Serializable
.
run(...)
methods execute Runnable
jobs over nodes in the projection.
Use IgniteRunnable
for better performance as it implements Serializable
.
broadcast(...)
methods broadcast jobs to all nodes in the projection.affinity(...)
methods colocate jobs with nodes on which a specified key is cached.ClusterGroupEmptyCheckedException
will be thrown out of result future.
Runnable
and Callable
implementations must support serialization as required
by the configured marshaller. For example, OptimizedMarshaller
requires Serializable
objects by default, but can be configured not to. Generally speaking objects that implement Serializable
or Externalizable
will perform better. For Runnable
and Callable
interfaces
Ignite provides analogous IgniteRunnable
and IgniteCallable
classes which are
Serializable
and should be used to run computations on the grid.
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 grid projection. Other load balancing
policies, such as random
or adaptive
, can be configured as well by selecting
a different load balancing SPI in grid 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 MyGridJob extends GridRunnable { ... @IgniteInstanceResource private Grid grid; ... }
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(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).
|
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).
|
<T,R> Collection<R> |
apply(IgniteClosure<T,R> job,
Collection<? extends T> args)
Executes provided closure job on nodes within this grid projection.
|
<R,T> R |
apply(IgniteClosure<T,R> job,
T arg)
Executes provided closure job on a node in this grid projection.
|
<R1,R2,T> R2 |
apply(IgniteClosure<T,R1> job,
Collection<? extends T> args,
IgniteReducer<R1,R2> rdc)
Executes provided closure job on nodes within this grid projection.
|
<R> Collection<R> |
broadcast(IgniteCallable<R> job)
Broadcasts given job to all nodes in grid projection.
|
<R,T> Collection<R> |
broadcast(IgniteClosure<T,R> job,
T arg)
Broadcasts given closure job with passed in argument to all nodes in grid projection.
|
void |
broadcast(IgniteRunnable job)
Broadcasts given job to all nodes in grid projection.
|
<R> Collection<R> |
call(Collection<? extends IgniteCallable<R>> jobs)
Executes collection of jobs on nodes within this grid projection.
|
<R1,R2> R2 |
call(Collection<? extends IgniteCallable<R1>> jobs,
IgniteReducer<R1,R2> rdc)
Executes collection of jobs on nodes within this grid projection.
|
<R> R |
call(IgniteCallable<R> job)
Executes provided job on a node in this grid projection.
|
ClusterGroup |
clusterGroup()
Gets grid projection to which this
GridCompute instance belongs. |
<T,R> R |
execute(Class<? extends ComputeTask<T,R>> taskCls,
T arg)
Executes given task on the grid projection.
|
<T,R> R |
execute(ComputeTask<T,R> task,
T arg)
Executes given task on this grid projection.
|
<T,R> R |
execute(String taskName,
T arg)
Executes given task on this grid projection.
|
<R> ComputeTaskFuture<R> |
future()
Gets and resets future for previous asynchronous operation.
|
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 this grid projection.
|
void |
run(IgniteRunnable job)
Executes provided job on a node in this grid projection.
|
void |
undeployTask(String taskName)
Makes the best attempt to undeploy a task with given name from this grid projection.
|
IgniteCompute |
withAsync()
Gets component with asynchronous mode enabled.
|
IgniteCompute |
withName(String taskName)
Sets task name for the next executed task on this projection in the current thread.
|
IgniteCompute |
withNoFailover()
Sets no-failover flag for the next executed task on this projection in the current thread.
|
IgniteCompute |
withTimeout(long timeout)
Sets task timeout for the next executed task on this projection in the current thread.
|
isAsync
ClusterGroup clusterGroup()
GridCompute
instance belongs.GridCompute
instance belongs.@IgniteAsyncSupported void affinityRun(@Nullable String cacheName, Object affKey, IgniteRunnable job) throws IgniteException
Supports asynchronous execution (see IgniteAsyncSupport
).
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.ComputeJobContext#cacheName()
,
ComputeJobContext#affinityKey()
@IgniteAsyncSupported <R> R affinityCall(@Nullable String cacheName, Object affKey, IgniteCallable<R> job) throws IgniteException
Supports asynchronous execution (see IgniteAsyncSupport
).
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.ComputeJobContext#cacheName()
,
ComputeJobContext#affinityKey()
@IgniteAsyncSupported <T,R> R execute(Class<? extends ComputeTask<T,R>> taskCls, @Nullable T arg) throws IgniteException
ComputeTask
documentation.
Supports asynchronous execution (see IgniteAsyncSupport
).
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.@IgniteAsyncSupported <T,R> R execute(ComputeTask<T,R> task, @Nullable T arg) throws IgniteException
ComputeTask
documentation.
Supports asynchronous execution (see IgniteAsyncSupport
).
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.@IgniteAsyncSupported <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).
Supports asynchronous execution (see IgniteAsyncSupport
).
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.
@IgniteAsyncSupported void broadcast(IgniteRunnable job) throws IgniteException
Supports asynchronous execution (see IgniteAsyncSupport
).
job
- Job to broadcast to all projection nodes.IgniteException
- If job failed.@IgniteAsyncSupported <R> Collection<R> broadcast(IgniteCallable<R> job) throws IgniteException
Supports asynchronous execution (see IgniteAsyncSupport
).
job
- Job to broadcast to all projection nodes.IgniteException
- If execution failed.@IgniteAsyncSupported <R,T> Collection<R> broadcast(IgniteClosure<T,R> job, @Nullable T arg) throws IgniteException
Supports asynchronous execution (see IgniteAsyncSupport
).
job
- Job to broadcast to all projection nodes.arg
- Job closure argument.IgniteException
- If execution failed.@IgniteAsyncSupported void run(IgniteRunnable job) throws IgniteException
Supports asynchronous execution (see IgniteAsyncSupport
).
job
- Job closure to execute.IgniteException
- If execution failed.@IgniteAsyncSupported void run(Collection<? extends IgniteRunnable> jobs) throws IgniteException
Supports asynchronous execution (see IgniteAsyncSupport
).
jobs
- Collection of jobs to execute.IgniteException
- If execution failed.@IgniteAsyncSupported <R> R call(IgniteCallable<R> job) throws IgniteException
Supports asynchronous execution (see IgniteAsyncSupport
).
job
- Job to execute.IgniteException
- If execution failed.@IgniteAsyncSupported <R> Collection<R> call(Collection<? extends IgniteCallable<R>> jobs) throws IgniteException
Supports asynchronous execution (see IgniteAsyncSupport
).
jobs
- Collection of jobs to execute.IgniteException
- If execution failed.@IgniteAsyncSupported <R1,R2> R2 call(Collection<? extends IgniteCallable<R1>> jobs, IgniteReducer<R1,R2> rdc) throws IgniteException
Supports asynchronous execution (see IgniteAsyncSupport
).
jobs
- Collection of jobs to execute.rdc
- Reducer to reduce all job results into one individual return value.IgniteException
- If execution failed.@IgniteAsyncSupported <R,T> R apply(IgniteClosure<T,R> job, @Nullable 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.
Supports asynchronous execution (see IgniteAsyncSupport
).
job
- Job to run.arg
- Job argument.IgniteException
- If execution failed.@IgniteAsyncSupported <T,R> Collection<R> apply(IgniteClosure<T,R> job, Collection<? extends T> args) throws IgniteException
Supports asynchronous execution (see IgniteAsyncSupport
).
job
- Job to run.args
- Job arguments.IgniteException
- If execution failed.@IgniteAsyncSupported <R1,R2,T> R2 apply(IgniteClosure<T,R1> job, Collection<? extends T> args, IgniteReducer<R1,R2> rdc) throws IgniteException
Supports asynchronous execution (see IgniteAsyncSupport
).
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.
Ignition.ignite().withName("MyTask").run(new MyRunnable() {...});
taskName
- Task name.GridCompute
instance for chaining calls.IgniteCompute withTimeout(long timeout)
ComputeTask
.
Here is an example.
Ignition.ignite().withTimeout(10000).run(new MyRunnable() {...});
timeout
- Computation timeout in milliseconds.GridCompute
instance for chaining calls.IgniteCompute withNoFailover()
Here is an example.
Ignition.ignite().compute().withNoFailover().run(new MyRunnable() {...});
GridCompute
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.<R> ComputeTaskFuture<R> future()
future
in interface IgniteAsyncSupport
IgniteCompute withAsync()
withAsync
in interface IgniteAsyncSupport
Follow @ApacheIgnite
Apache Ignite Fabric : ver. 1.0.0-RC1 Release Date : February 16 2015