Package org.apache.ignite.compute

## Interface ComputeJobContext

- All Superinterfaces:
    `ComputeJobContinuation`

      public interface ComputeJobContext
      extends ComputeJobContinuation

  Context attached to every job executed on the grid. Note that unlike `ComputeTaskSession`, which distributes all attributes to all jobs in the task including the task itself, job context attributes belong to a job and do not get sent over network unless a job moves from one node to another.

  In most cases a job, once assigned to a node, will never move to another node. However, it is possible that collision SPI rejects a job before it ever got a chance to execute (job rejection) which will cause fail-over to another node. Or user is not satisfied with the outcome of a job and fails it over to another node by returning `ComputeJobResultPolicy.FAILOVER` policy from `ComputeTask.result(ComputeJobResult, List)` method. In this case all context attributes set on one node will be available on any other node this job travels to.

  You can also use `ComputeJobContext` to communicate between SPI's and jobs. For example, if you need to cancel an actively running job from `CollisionSpi` you may choose to set some context attribute on the job to mark the fact that a job was cancelled by grid and not by a user. Context attributes can also be assigned in `FailoverSpi` prior to failing over a job.

  From within `ComputeTask.result(ComputeJobResult, List)` or `ComputeTask.reduce(List)` methods, job context is available via `ComputeJobResult.getJobContext()` method which gives user the ability to check context attributes from within grid task implementation for every job returned from remote nodes.

  Job context can be injected into `ComputeJob` via `JobContextResource` annotation. Refer to the `JobContextResource` documentation for coding examples on how to inject job context.

  Attribute names that start with `"apache.ignite:"` are reserved for internal system use.

- - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `<K,​V> V` | `getAttribute​(K key)` | Gets attribute from this job context.
    `Map<?,​?>` | `getAttributes()` | Gets all attributes present in this job context.
    `IgniteUuid` | `getJobId()` | Gets ID of the job this context belongs to.
    `void` | `setAttribute​(Object key, @Nullable Object val)` | Sets an attribute into this job context.
    `void` | `setAttributes​(Map<?,​?> attrs)` | Sets map of attributes into this job context.

    - ### Methods inherited from interface org.apache.ignite.compute.ComputeJobContinuation

      `callcc, heldcc, holdcc, holdcc`

- - ### Method Detail

    - #### getJobId

          IgniteUuid getJobId()

      Gets ID of the job this context belongs to.
      Returns:
        ID of the job this context belongs to.

    - #### setAttribute

          void setAttribute​(Object key,
                            @Nullable
                            @Nullable Object val)

      Sets an attribute into this job context.
      Parameters:
        `key` - Attribute key.
        `val` - Attribute value.

    - #### setAttributes

          void setAttributes​(Map<?,​?> attrs)

      Sets map of attributes into this job context.
      Parameters:
        `attrs` - Local attributes.

    - #### getAttribute

          <K,​V> V getAttribute​(K key)

      Gets attribute from this job context.
      Type Parameters:
        `K` - Type of the attribute key.
        `V` - Type of the attribute value.
      Parameters:
        `key` - Attribute key.
      Returns:
        Attribute value (possibly `null`).

    - #### getAttributes

          Map<?,​?> getAttributes()

      Gets all attributes present in this job context.
      Returns:
        All attributes.