Package org.apache.ignite.internal.processors.task

## Class GridTaskProcessor

- java.lang.Object
- - org.apache.ignite.internal.processors.GridProcessorAdapter
  - - org.apache.ignite.internal.processors.task.GridTaskProcessor

All Implemented Interfaces:
  `GridComponent`, `IgniteChangeGlobalStateSupport`, `GridProcessor`

    public class GridTaskProcessor
    extends GridProcessorAdapter
    implements IgniteChangeGlobalStateSupport

This class defines task processor.

### Nested Class Summary

### Nested classes/interfaces inherited from interface org.apache.ignite.internal.GridComponent

`GridComponent.DiscoveryDataExchangeType`

### Field Summary

Fields
`static String` `TASKS_VIEW`
`static String` `TASKS_VIEW_DESC`
`static String` `TOTAL_EXEC_TASKS` Total executed tasks metric name.

### Fields inherited from class org.apache.ignite.internal.processors.GridProcessorAdapter

`ctx, diagnosticLog, log`

### Constructor Summary

Constructors
`GridTaskProcessor​(GridKernalContext ctx)`

### Method Summary

All Methods Instance Methods Concrete Methods
`boolean` `cancel​(IgniteUuid sesId)` Handles user cancellation.
`<T,​R> ComputeTaskInternalFuture<R>` `execute​(Class<? extends ComputeTask<T,​R>> taskCls, T arg)`
`<T,​R> ComputeTaskInternalFuture<R>` `execute​(Class<? extends ComputeTask<T,​R>> taskCls, T arg, TaskExecutionOptions opts)`
`<T,​R> ComputeTaskInternalFuture<R>` `execute​(String taskName, T arg)`
`<T,​R> ComputeTaskInternalFuture<R>` `execute​(String taskName, T arg, @Nullable TaskExecutionOptions opts)`
`<T,​R> ComputeTaskInternalFuture<R>` `execute​(ComputeTask<T,​R> task, T arg)`
`<T,​R> ComputeTaskInternalFuture<R>` `execute​(ComputeTask<T,​R> task, T arg, TaskExecutionOptions opts)`
`Map<String,​GridDeployment>` `getUsedDeploymentMap()` Gets currently used deployments mapped by task name or aliases.
`Collection<GridDeployment>` `getUsedDeployments()` Gets currently used deployments.
`Map<ComputeJobStatusEnum,​Long>` `jobStatuses​(IgniteUuid sesId)` Collects statistics on jobs locally, only for those jobs that have already sent a response or are being executed locally.
`void` `listenStatusUpdates​(ComputeGridMonitor monitor)` Subscription to update the status of tasks.
`void` `onActivate​(GridKernalContext kctx)` Called when cluster performing activation.
`void` `onDeActivate​(GridKernalContext kctx)` Called when cluster performing deactivation.
`void` `onDisconnected​(IgniteFuture<?> reconnectFut)` Client disconnected callback.
`void` `onKernalStart​(boolean active)` Callback that notifies that kernal has successfully started, including all managers and processors.
`void` `onKernalStop​(boolean cancel)` Callback to notify that kernal is about to stop.
`void` `printMemoryStats()` Prints memory statistics (sizes of internal structures, etc.).
`void` `processJobExecuteResponse​(UUID nodeId, GridJobExecuteResponse msg)`
`void` `resetMetrics()` Resets processor metrics.
`String` `resolveTaskName​(int taskNameHash)` Resolves task name by task name hash.
`void` `setAttributes​(GridTaskSessionImpl ses, Map<?,​?> attrs)`
`void` `start()` Starts grid component.
`void` `stop​(boolean cancel)` Stops grid component.
`void` `stopListenStatusUpdates​(ComputeGridMonitor monitor)` Unsubscribe to update the status of tasks.
`<R> @Nullable ComputeTaskInternalFuture<R>` `taskFuture​(IgniteUuid sesId)`
`<R> Map<IgniteUuid,​ComputeTaskFuture<R>>` `taskFutures()`

### Methods inherited from class org.apache.ignite.internal.processors.GridProcessorAdapter

`assertParameter, collectGridNodeData, collectJoiningNodeData, discoveryDataType, onGridDataReceived, onJoiningNodeDataReceived, onReconnected, toString, validateNode, validateNode`

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

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

### Field Detail

#### TASKS_VIEW

    public static final String TASKS_VIEW

See Also:
  Constant Field Values

#### TASKS_VIEW_DESC

    public static final String TASKS_VIEW_DESC

See Also:
  Constant Field Values

#### TOTAL_EXEC_TASKS

    public static final String TOTAL_EXEC_TASKS

Total executed tasks metric name.

See Also:
  Constant Field Values

### Constructor Detail

#### GridTaskProcessor

    public GridTaskProcessor​(GridKernalContext ctx)

Parameters:
  `ctx` - Kernal context.

### Method Detail

#### start

    public void start()

Starts grid component.

Specified by:
  `start` in interface `GridComponent`
Overrides:
  `start` in class `GridProcessorAdapter`

#### onKernalStart

    public void onKernalStart​(boolean active)
                       throws IgniteCheckedException

Callback that notifies that kernal has successfully started, including all managers and processors.

Specified by:
  `onKernalStart` in interface `GridComponent`
Overrides:
  `onKernalStart` in class `GridProcessorAdapter`
Parameters:
  `active` - Cluster active flag (note: should be used carefully since state can change concurrently).
Throws:
  `IgniteCheckedException` - Thrown in case of any errors.

#### onDisconnected

    public void onDisconnected​(IgniteFuture<?> reconnectFut)
                        throws IgniteCheckedException

Client disconnected callback.

Specified by:
  `onDisconnected` in interface `GridComponent`
Overrides:
  `onDisconnected` in class `GridProcessorAdapter`
Parameters:
  `reconnectFut` - Reconnect future.
Throws:
  `IgniteCheckedException` - If failed.

#### onKernalStop

    public void onKernalStop​(boolean cancel)

Callback to notify that kernal is about to stop.

Specified by:
  `onKernalStop` in interface `GridComponent`
Overrides:
  `onKernalStop` in class `GridProcessorAdapter`
Parameters:
  `cancel` - Flag indicating whether jobs should be canceled.

#### stop

    public void stop​(boolean cancel)

Stops grid component.

Specified by:
  `stop` in interface `GridComponent`
Overrides:
  `stop` in class `GridProcessorAdapter`
Parameters:
  `cancel` - If `true`, then all ongoing tasks or jobs for relevant components need to be cancelled.

#### getUsedDeployments

    public Collection<GridDeployment> getUsedDeployments()

Gets currently used deployments.

Returns:
  Currently used deployments.

#### getUsedDeploymentMap

    public Map<String,​GridDeployment> getUsedDeploymentMap()

Gets currently used deployments mapped by task name or aliases.

Returns:
  Currently used deployments.

#### execute

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

Type Parameters:
  `T` - Task argument type.
  `R` - Task return value type.
Parameters:
  `taskCls` - Task class.
  `arg` - Optional execution argument.
Returns:
  Task future.

#### execute

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

Type Parameters:
  `T` - Task argument type.
  `R` - Task return value type.
Parameters:
  `taskCls` - Task class.
  `arg` - Optional execution argument.
  `opts` - Task execution options.
Returns:
  Task future.

#### execute

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

Type Parameters:
  `T` - Task argument type.
  `R` - Task return value type.
Parameters:
  `task` - Actual task.
  `arg` - Optional task argument.
Returns:
  Task future.

#### execute

    public <T,​R> ComputeTaskInternalFuture<R> execute​(ComputeTask<T,​R> task,
                                                            @Nullable
                                                            T arg,
                                                            TaskExecutionOptions opts)

Type Parameters:
  `T` - Task argument type.
  `R` - Task return value type.
Parameters:
  `task` - Actual task.
  `arg` - Optional task argument.
  `opts` - Task execution options.
Returns:
  Task future.

#### resolveTaskName

    public String resolveTaskName​(int taskNameHash)

Resolves task name by task name hash.

Parameters:
  `taskNameHash` - Task name hash.
Returns:
  Task name or `null` if not found.

#### execute

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

Type Parameters:
  `T` - Task argument type.
  `R` - Task return value type.
Parameters:
  `taskName` - Task name.
  `arg` - Optional execution argument.
Returns:
  Task future.

#### execute

    public <T,​R> ComputeTaskInternalFuture<R> execute​(String taskName,
                                                            @Nullable
                                                            T arg,
                                                            @Nullable
                                                            @Nullable TaskExecutionOptions opts)

Type Parameters:
  `T` - Task argument type.
  `R` - Task return value type.
Parameters:
  `taskName` - Task name.
  `arg` - Optional execution argument.
  `opts` - Task execution options.
Returns:
  Task future.

#### taskFuture

    @Nullable
    public <R> @Nullable ComputeTaskInternalFuture<R> taskFuture​(IgniteUuid sesId)

Parameters:
  `sesId` - Task's session id.
Returns:
  A `ComputeTaskInternalFuture` instance or `null` if no such task found.

#### taskFutures

    public <R> Map<IgniteUuid,​ComputeTaskFuture<R>> taskFutures()

Returns:
  Active task futures.

#### setAttributes

    public void setAttributes​(GridTaskSessionImpl ses,
                              Map<?,​?> attrs)
                       throws IgniteCheckedException

Parameters:
  `ses` - Task session.
  `attrs` - Attributes.
Throws:
  `IgniteCheckedException` - Thrown in case of any errors.

#### processJobExecuteResponse

    public void processJobExecuteResponse​(UUID nodeId,
                                          GridJobExecuteResponse msg)

Parameters:
  `nodeId` - Node ID.
  `msg` - Execute response message.

#### cancel

    public boolean cancel​(IgniteUuid sesId)

Handles user cancellation.

Parameters:
  `sesId` - Session ID.
Returns:
  Whether task was cancelled by this call.

#### onActivate

    public void onActivate​(GridKernalContext kctx)
                    throws IgniteCheckedException

Called when cluster performing activation.

Specified by:
  `onActivate` in interface `IgniteChangeGlobalStateSupport`
Parameters:
  `kctx` - Kernal context.
Throws:
  `IgniteCheckedException` - If failed.

#### onDeActivate

    public void onDeActivate​(GridKernalContext kctx)

Called when cluster performing deactivation.

Specified by:
  `onDeActivate` in interface `IgniteChangeGlobalStateSupport`
Parameters:
  `kctx` - Kernal context.

#### resetMetrics

    public void resetMetrics()

Resets processor metrics.

#### printMemoryStats

    public void printMemoryStats()

Prints memory statistics (sizes of internal structures, etc.). NOTE: this method is for testing and profiling purposes only.

Specified by:
  `printMemoryStats` in interface `GridComponent`
Overrides:
  `printMemoryStats` in class `GridProcessorAdapter`

#### listenStatusUpdates

    public void listenStatusUpdates​(ComputeGridMonitor monitor)
                             throws NodeStoppingException

Subscription to update the status of tasks.

NOTE: `ComputeGridMonitor.processStatusSnapshots(java.util.Collection<org.apache.ignite.internal.processors.task.monitor.ComputeTaskStatusSnapshot>)` will be called only on subscription, then only `ComputeGridMonitor.processStatusChange(org.apache.ignite.internal.processors.task.monitor.ComputeTaskStatusSnapshot)` will be called.

Parameters:
  `monitor` - Task status update monitor.
Throws:
  `NodeStoppingException` - If the node is stopped.

#### stopListenStatusUpdates

    public void stopListenStatusUpdates​(ComputeGridMonitor monitor)

Unsubscribe to update the status of tasks.

Parameters:
  `monitor` - Task status update monitor.

#### jobStatuses

    public Map<ComputeJobStatusEnum,​Long> jobStatuses​(IgniteUuid sesId)

Collects statistics on jobs locally, only for those jobs that have already sent a response or are being executed locally.

Parameters:
  `sesId` - Task session ID.
Returns:
  Job statistics for the task. Mapping: Job status -> count of jobs.