org.apache.ignite.compute

## Class ComputeJobAdapter

- java.lang.Object
- - org.apache.ignite.compute.ComputeJobAdapter

- All Implemented Interfaces:
    Serializable, Callable<Object>, ComputeJob
  Direct Known Subclasses:
    ComputeJobContinuationAdapter

      public abstract class ComputeJobAdapter
      extends Object
      implements ComputeJob, Callable<Object>

  Convenience adapter for `ComputeJob` implementations. It provides the following functionality:
  - Default implementation of `ComputeJob.cancel()` method and ability to check whether cancellation occurred with `isCancelled()` method.
  - Ability to set and get job arguments via `setArguments(Object...)` and `argument(int)` methods.
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `ComputeJobAdapter()` No-arg constructor.
    `protected` | `ComputeJobAdapter(Object... args)` Creates job with specified arguments.
    `protected` | `ComputeJobAdapter(@Nullable Object arg)` Creates job with one arguments.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `<T> T` | `argument(int idx)` Gets job argument.
    `protected @Nullable Object[]` | `arguments()` Gets array of job arguments.
    `Object` | `call()`
    `void` | `cancel()` This method is called when system detects that completion of this job can no longer alter the overall outcome (for example, when parent task has already reduced the results).
    `protected boolean` | `isCancelled()` This method tests whether or not this job was cancelled.
    `void` | `setArguments(Object... args)` Sets given arguments.

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

      `execute`

- - ### Constructor Detail

    - #### ComputeJobAdapter

          protected ComputeJobAdapter()

      No-arg constructor.

    - #### ComputeJobAdapter

          protected ComputeJobAdapter(@Nullable
                                      @Nullable Object arg)

      Creates job with one arguments. This constructor exists for better backward compatibility with internal Ignite 2.x code.
      Parameters:
        `arg` - Job argument.

    - #### ComputeJobAdapter

          protected ComputeJobAdapter(@Nullable
                                      Object... args)

      Creates job with specified arguments.
      Parameters:
        `args` - Optional job arguments.

  - ### Method Detail

    - #### setArguments

          public void setArguments(@Nullable
                                   Object... args)

      Sets given arguments.
      Parameters:
        `args` - Optional job arguments to set.

    - #### cancel

          public void cancel()

      This method is called when system detects that completion of this job can no longer alter the overall outcome (for example, when parent task has already reduced the results). Job is also cancelled when `IgniteFuture.cancel()` is called.

      Note that job cancellation is only a hint, and just like with `Thread.interrupt()` method, it is really up to the actual job instance to gracefully finish execution and exit.

      Specified by:
        `cancel` in interface `ComputeJob`

    - #### isCancelled

          protected final boolean isCancelled()

      This method tests whether or not this job was cancelled. This method is thread-safe and can be called without extra synchronization.

      This method can be periodically called in `ComputeJob.execute()` method implementation to check whether or not this job cancelled. Note that system calls `cancel()` method only as a hint and this is a responsibility of the implementation of the job to properly cancel its execution.

      Returns:
        `true` if this job was cancelled, `false` otherwise.

    - #### argument

          @Nullable
          public <T> T argument(int idx)

      Gets job argument.
      Type Parameters:
        `T` - Type of the argument to return.
      Parameters:
        `idx` - Index of the argument.
      Returns:
        Job argument.
      Throws:
        `NullPointerException` - Thrown in case when there no arguments set.
        `IllegalArgumentException` - Thrown if index is invalid.

    - #### arguments

          @Nullable
          protected @Nullable Object[] arguments()

      Gets array of job arguments. Note that changes to this array may affect job execution.
      Returns:
        Array of job arguments.

    - #### call

          public final Object call()

      Specified by:
        `call` in interface `Callable<Object>`

2022 Copyright © Apache Software Foundation
| Follow @ApacheIgnite
Ignite Database and Caching Platform | : ver. 2.13.0
Release Date | : April 20 2022