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 inherited from class org.apache.ignite.internal.processors.GridProcessorAdapter

`ctx, diagnosticLog, log`

### Constructor Summary

Constructors
Constructor and Description
`GridTaskProcessor(GridKernalContext ctx)`

### Method Summary

Methods
`<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, String execName)`
`<T,R> ComputeTaskInternalFuture<R>` `execute(ComputeTask<T,R> task, T arg)`
`<T,R> ComputeTaskInternalFuture<R>` `execute(ComputeTask<T,R> task, T arg, boolean sys)`
`<T,R> ComputeTaskInternalFuture<R>` `execute(ComputeTask<T,R> task, T arg, boolean sys, String execName)`
`<T,R> ComputeTaskInternalFuture<R>` `execute(ComputeTask<T,R> task, T arg, String execName)`
`<T,R> ComputeTaskInternalFuture<R>` `execute(String taskName, T arg)`
`<T,R> ComputeTaskInternalFuture<R>` `execute(String taskName, T arg, String execName)`
`<T> T` `getThreadContext(GridTaskThreadContextKey key)` Gets thread-local context value for a given `key`.
`int` `getTotalExecutedTasks()`
`Map<String,GridDeployment>` `getUsedDeploymentMap()` Gets currently used deployments mapped by task name or aliases.
`Collection<GridDeployment>` `getUsedDeployments()` Gets currently used deployments.
`void` `onActivate(GridKernalContext kctx)` Called when cluster performing activation.
`void` `onCancelled(IgniteUuid sesId)` Handles user cancellation.
`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` `setThreadContext(GridTaskThreadContextKey key, Object val)` Sets the thread-local context value.
`void` `setThreadContextIfNotNull(GridTaskThreadContextKey key, Object val)` Sets the thread-local context value, if it is not null.
`void` `start()` Starts grid component.
`void` `stop(boolean cancel)` Stops grid component.
`<R> 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`

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

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

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

#### setThreadContext

    public void setThreadContext(GridTaskThreadContextKey key,
                        Object val)

Sets the thread-local context value.

Parameters:
  `key` - Key.
  `val` - Value.

#### setThreadContextIfNotNull

    public void setThreadContextIfNotNull(GridTaskThreadContextKey key,
                                 @Nullable
                                 Object val)

Sets the thread-local context value, if it is not null.

Parameters:
  `key` - Key.
  `val` - Value.

#### getThreadContext

    @Nullable
    public <T> T getThreadContext(GridTaskThreadContextKey key)

Gets thread-local context value for a given `key`.

Parameters:
  `key` - Thread-local context key.
Returns:
  Thread-local context value associated with given `key` - or `null` if value with given `key` doesn't exist.

#### 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,
                                             @Nullable
                                             String execName)

Type Parameters:
  `T` - Task argument type.
  `R` - Task return value type.
Parameters:
  `taskCls` - Task class.
  `arg` - Optional execution argument.
  `execName` - Name of the custom executor.
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,
                                             String execName)

Type Parameters:
  `T` - Task argument type.
  `R` - Task return value type.
Parameters:
  `task` - Actual task.
  `arg` - Optional task argument.
  `execName` - Name of the custom executor.
Returns:
  Task future.

#### execute

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

Type Parameters:
  `T` - Task argument type.
  `R` - Task return value type.
Parameters:
  `task` - Actual task.
  `arg` - Optional task argument.
  `sys` - If `true`, then system pool will be used.
Returns:
  Task future.

#### execute

    public <T,R> ComputeTaskInternalFuture<R> execute(ComputeTask<T,R> task,
                                             @Nullable
                                             T arg,
                                             boolean sys,
                                             @Nullable
                                             String execName)

Type Parameters:
  `T` - Task argument type.
  `R` - Task return value type.
Parameters:
  `task` - Actual task.
  `arg` - Optional task argument.
  `sys` - If `true`, then system pool will be used.
  `execName` - Name of the custom executor.
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
                                             String execName)

Type Parameters:
  `T` - Task argument type.
  `R` - Task return value type.
Parameters:
  `taskName` - Task name.
  `arg` - Optional execution argument.
  `execName` - Name of the custom executor.
Returns:
  Task future.

#### taskFuture

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

#### onCancelled

    public void onCancelled(IgniteUuid sesId)

Handles user cancellation.

Parameters:
  `sesId` - Session ID.

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

#### getTotalExecutedTasks

    public int getTotalExecutedTasks()

Returns:
  Number of executed tasks.

#### 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`

2017 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 2.2.0
Release Date | : September 15 2017