org.apache.ignite.internal

## Class IgniteComputeImpl

- java.lang.Object
- - org.apache.ignite.internal.AsyncSupportAdapter<IgniteCompute>
  - - org.apache.ignite.internal.IgniteComputeImpl

All Implemented Interfaces:
  Externalizable, Serializable, IgniteCompute, IgniteAsyncSupport

    public class IgniteComputeImpl
    extends AsyncSupportAdapter<IgniteCompute>
    implements IgniteCompute, Externalizable

`IgniteCompute` implementation.

See Also:
  Serialized Form

### Field Summary

### Fields inherited from class org.apache.ignite.internal.AsyncSupportAdapter

`curFut`

### Constructor Summary

Constructors
Constructor and Description
`IgniteComputeImpl()` Required by `Externalizable`.
`IgniteComputeImpl(GridKernalContext ctx, ClusterGroupAdapter prj, UUID subjId, boolean async)`

### Method Summary

Methods
`<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 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.
`<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> 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.
`ClusterGroup` `clusterGroup()` Gets cluster group to which this `IgniteCompute` instance belongs.
`protected IgniteCompute` `createAsyncInstance()` Creates component with asynchronous mode enabled.
`protected <R> IgniteFuture<R>` `createFuture(IgniteInternalFuture<R> fut)`
`<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> ComputeTaskInternalFuture<R>` `executeAsync(ComputeTask<T,R> task, T arg)`
`<T,R> ComputeTaskInternalFuture<R>` `executeAsync(String taskName, T arg)`
`<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` `readExternal(ObjectInput in)`
`protected Object` `readResolve()` Reconstructs object on unmarshalling.
`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.
`void` `undeployTask(String taskName)` Makes the best attempt to undeploy a task with given name within the underlying cluster group.
`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` `withTimeout(long timeout)` Sets task timeout for the next executed task in the current thread.
`void` `writeExternal(ObjectOutput out)`

### Methods inherited from class org.apache.ignite.internal.AsyncSupportAdapter

`future, isAsync, saveOrGet, withAsync`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.apache.ignite.IgniteCompute

`withAsync`

### Methods inherited from interface org.apache.ignite.lang.IgniteAsyncSupport

`isAsync`

### Constructor Detail

#### IgniteComputeImpl

    public IgniteComputeImpl()

Required by `Externalizable`.

#### IgniteComputeImpl

    public IgniteComputeImpl(GridKernalContext ctx,
                     ClusterGroupAdapter prj,
                     UUID subjId,
                     boolean async)

Parameters:
  `ctx` - Kernal context.
  `prj` - Projection.
  `subjId` - Subject ID.
  `async` - Async support flag.

### Method Detail

#### createAsyncInstance

    protected IgniteCompute createAsyncInstance()

Creates component with asynchronous mode enabled.

Overrides:
  `createAsyncInstance` in class `AsyncSupportAdapter<IgniteCompute>`
Returns:
  Component with asynchronous mode enabled.

#### clusterGroup

    public ClusterGroup clusterGroup()

Gets cluster group to which this `IgniteCompute` instance belongs.

Specified by:
  `clusterGroup` in interface `IgniteCompute`
Returns:
  Cluster group to which this `IgniteCompute` instance belongs.

#### affinityRun

    public void affinityRun(@Nullable
                   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).

Specified by:
  `affinityRun` in interface `IgniteCompute`
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.

#### affinityCall

    public <R> R affinityCall(@Nullable
                     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).

Specified by:
  `affinityCall` in interface `IgniteCompute`
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.

#### execute

    public <T,R> R execute(String taskName,
                  @Nullable
                  T arg)

Executes given task within the cluster group. For step-by-step explanation of task execution process refer to `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 `IgniteCompute.localDeployTask(Class, ClassLoader)` method).

Specified by:
  `execute` in interface `IgniteCompute`
Parameters:
  `taskName` - Name of the task to execute.
  `arg` - Optional argument of task execution, can be `null`.
Returns:
  Task result.
See Also:
  `for information about task execution.`

#### execute

    public <T,R> R execute(Class<? extends ComputeTask<T,R>> taskCls,
                  @Nullable
                  T arg)

Executes given task on within the cluster group. For step-by-step explanation of task execution process refer to `ComputeTask` documentation.

Specified by:
  `execute` in interface `IgniteCompute`
Parameters:
  `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`.
Returns:
  Task result.

#### execute

    public <T,R> R execute(ComputeTask<T,R> task,
                  @Nullable
                  T arg)

Executes given task within the cluster group. For step-by-step explanation of task execution process refer to `ComputeTask` documentation.

Specified by:
  `execute` in interface `IgniteCompute`
Parameters:
  `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`.
Returns:
  Task result.

#### executeAsync

    public <T,R> ComputeTaskInternalFuture<R> executeAsync(ComputeTask<T,R> task,
                                                  @Nullable
                                                  T arg)

Parameters:
  `task` - Task.
  `arg` - Task argument.
Returns:
  Task future.

#### executeAsync

    public <T,R> ComputeTaskInternalFuture<R> executeAsync(String taskName,
                                                  @Nullable
                                                  T arg)

Parameters:
  `taskName` - Task name.
  `arg` - Task argument.
Returns:
  Task future.

#### broadcast

    public void broadcast(IgniteRunnable job)

Broadcasts given job to all nodes in the cluster group.

Specified by:
  `broadcast` in interface `IgniteCompute`
Parameters:
  `job` - Job to broadcast to all cluster group nodes.

#### broadcast

    public <R> Collection<R> broadcast(IgniteCallable<R> job)

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.

Specified by:
  `broadcast` in interface `IgniteCompute`
Parameters:
  `job` - Job to broadcast to all cluster group nodes.
Returns:
  Collection of results for this execution.

#### broadcast

    public <R,T> Collection<R> broadcast(IgniteClosure<T,R> job,
                                @Nullable
                                T arg)

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.

Specified by:
  `broadcast` in interface `IgniteCompute`
Parameters:
  `job` - Job to broadcast to all cluster group nodes.
  `arg` - Job closure argument.
Returns:
  Collection of results for this execution.

#### run

    public void run(IgniteRunnable job)

Executes provided job on a node within the underlying cluster group.

Specified by:
  `run` in interface `IgniteCompute`
Parameters:
  `job` - Job closure to execute.

#### run

    public void run(Collection<? extends IgniteRunnable> jobs)

Executes collection of jobs on grid nodes within the underlying cluster group.

Specified by:
  `run` in interface `IgniteCompute`
Parameters:
  `jobs` - Collection of jobs to execute.

#### apply

    public <R,T> R apply(IgniteClosure<T,R> job,
                @Nullable
                T arg)

Executes provided closure job on a node within the underlying cluster group. This method is different from `run(...)` and `call(...)` methods in a way that it receives job argument which is then passed into the closure at execution time.

Specified by:
  `apply` in interface `IgniteCompute`
Parameters:
  `job` - Job to run.
  `arg` - Job argument.
Returns:
  Job result.

#### call

    public <R> R call(IgniteCallable<R> job)

Executes provided job on a node within the underlying cluster group. The result of the job execution is returned from the result closure.

Specified by:
  `call` in interface `IgniteCompute`
Parameters:
  `job` - Job to execute.
Returns:
  Job result.

#### call

    public <R> Collection<R> call(Collection<? extends IgniteCallable<R>> jobs)

Executes collection of jobs on nodes within the underlying cluster group. Collection of all returned job results is returned from the result future.

Specified by:
  `call` in interface `IgniteCompute`
Parameters:
  `jobs` - Collection of jobs to execute.
Returns:
  Collection of job results for this execution.

#### apply

    public <T,R> Collection<R> apply(IgniteClosure<T,R> job,
                            @Nullable
                            Collection<? extends T> args)

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.

Specified by:
  `apply` in interface `IgniteCompute`
Parameters:
  `job` - Job to run.
  `args` - Job arguments.
Returns:
  Collection of job results.

#### call

    public <R1,R2> R2 call(Collection<? extends IgniteCallable<R1>> jobs,
                  IgniteReducer<R1,R2> rdc)

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.

Specified by:
  `call` in interface `IgniteCompute`
Parameters:
  `jobs` - Collection of jobs to execute.
  `rdc` - Reducer to reduce all job results into one individual return value.
Returns:
  Future with reduced job result for this execution.

#### apply

    public <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. 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.

Specified by:
  `apply` in interface `IgniteCompute`
Parameters:
  `job` - Job to run.
  `args` - Job arguments.
  `rdc` - Reducer to reduce all job results into one individual return value.
Returns:
  Future with reduced job result for this execution.

#### activeTaskFutures

    public <R> Map<IgniteUuid,ComputeTaskFuture<R>> activeTaskFutures()

Gets tasks future for active tasks started on local node.

Specified by:
  `activeTaskFutures` in interface `IgniteCompute`
Returns:
  Map of active tasks keyed by their task task session ID.

#### withName

    public 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 defining `ComputeTask`.

Here is an example.

     ignite.withName("MyTask").run(new IgniteRunnable() {...});

Specified by:
  `withName` in interface `IgniteCompute`
Parameters:
  `taskName` - Task name.
Returns:
  This `IgniteCompute` instance for chaining calls.

#### withTimeout

    public 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. You may use this method to set task name when executing jobs directly, without explicitly defining `ComputeTask`.

Here is an example.

     ignite.withTimeout(10000).run(new IgniteRunnable() {...});

Specified by:
  `withTimeout` in interface `IgniteCompute`
Parameters:
  `timeout` - Computation timeout in milliseconds.
Returns:
  This `IgniteCompute` instance for chaining calls.

#### withNoFailover

    public 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() {...});

Specified by:
  `withNoFailover` in interface `IgniteCompute`
Returns:
  This `IgniteCompute` instance for chaining calls.

#### localDeployTask

    public void localDeployTask(Class<? extends ComputeTask> taskCls,
                       ClassLoader clsLdr)

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.

Specified by:
  `localDeployTask` in interface `IgniteCompute`
Parameters:
  `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.

#### localTasks

    public Map<String,Class<? extends ComputeTask<?,?>>> localTasks()

Gets map of all locally deployed tasks keyed by their task name .

Specified by:
  `localTasks` in interface `IgniteCompute`
Returns:
  Map of locally deployed tasks keyed by their task name.

#### undeployTask

    public void undeployTask(String taskName)

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.

Specified by:
  `undeployTask` in interface `IgniteCompute`
Parameters:
  `taskName` - Name of the task to undeploy.

#### writeExternal

    public void writeExternal(ObjectOutput out)
                       throws IOException

Specified by:
  `writeExternal` in interface `Externalizable`
Throws:
  `IOException`

#### readExternal

    public void readExternal(ObjectInput in)
                      throws IOException,
                             ClassNotFoundException

Specified by:
  `readExternal` in interface `Externalizable`
Throws:
  `IOException`
  `ClassNotFoundException`

#### readResolve

    protected Object readResolve()
                          throws ObjectStreamException

Reconstructs object on unmarshalling.

Returns:
  Reconstructed object.
Throws:
  `ObjectStreamException` - Thrown in case of unmarshalling error.

#### createFuture

    protected <R> IgniteFuture<R> createFuture(IgniteInternalFuture<R> fut)

Overrides:
  `createFuture` in class `AsyncSupportAdapter<IgniteCompute>`
Parameters:
  `fut` - Internal future.
Returns:
  Public API future.

#### future

    public <R> ComputeTaskFuture<R> future()

Gets and resets future for previous asynchronous operation.

Specified by:
  `future` in interface `IgniteCompute`
Specified by:
  `future` in interface `IgniteAsyncSupport`
Overrides:
  `future` in class `AsyncSupportAdapter<IgniteCompute>`
Returns:
  Future for previous asynchronous operation.

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.3.0-incubating
Release Date | : July 10 2015