org.apache.ignite.compute

## Class ComputeJobContinuationAdapter

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

- All Implemented Interfaces:
    Serializable, Callable<Object>, ComputeJob, ComputeJobContinuation

      public abstract class ComputeJobContinuationAdapter
      extends ComputeJobAdapter
      implements ComputeJobContinuation

  Convenience adapter for `ComputeJob` implementations. It provides the following functionality:
  - Default implementation of `ComputeJob.cancel()` method and ability to check whether cancellation occurred.
  - Ability to set and get a job arguments via `ComputeJobAdapter.setArguments(Object...)` and `ComputeJobAdapter.argument(int)` methods.
  Here is an example of how `ComputeJobAdapter` can be used from task logic to create jobs. The example creates job adapter as anonymous class, but you are free to create a separate class for it.

       public class TestGridTask extends ComputeTaskSplitAdapter<String, Integer> {
           // Used to imitate some logic for the
           // sake of this example
           private int multiplier = 3;

           @Override
           protected Collection<? extends ComputeJob> split(int gridSize, final String arg) throws IgniteCheckedException {
               List<ComputeJobAdapter<String>> jobs = new ArrayList<ComputeJobAdapter<String>>(gridSize);

               for (int i = 0; i < gridSize; i++) {
                   jobs.add(new ComputeJobAdapter() {
                       // Job execution logic.
                       public Object execute() throws IgniteCheckedException {
                           return multiplier * arg.length();
                       }
                   });
              }

               return jobs;
           }

           // Aggregate multiple job results into
           // one task result.
           public Integer reduce(List<ComputeJobResult> results) throws IgniteCheckedException {
               int sum = 0;

               // For the sake of this example, let's sum all results.
               for (ComputeJobResult res : results) {
                   sum += (Integer)res.getData();
               }

               return sum;
           }
       }

  See Also:
    Serialized Form

- - ### Constructor Summary

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

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `callcc()` Resumes job if it was held by `ComputeJobContinuation.holdcc()` method.
    `boolean` | `heldcc()` Checks if job execution has been temporarily held (suspended).
    `<T> T` | `holdcc()` Holds (suspends) a given job indefinitely until `ComputeJobContinuation.callcc()` is called.
    `<T> T` | `holdcc(long timeout)` Holds (suspends) a given job for specified timeout or until `ComputeJobContinuation.callcc()` is called.

    - ### Methods inherited from class org.apache.ignite.compute.ComputeJobAdapter

      `argument, arguments, call, cancel, isCancelled, setArguments`

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

    - #### ComputeJobContinuationAdapter

          protected ComputeJobContinuationAdapter()

      No-arg constructor.

    - #### ComputeJobContinuationAdapter

          protected ComputeJobContinuationAdapter(@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.

    - #### ComputeJobContinuationAdapter

          protected ComputeJobContinuationAdapter(@Nullable
                                                  Object... args)

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

  - ### Method Detail

    - #### heldcc

          public boolean heldcc()

      Checks if job execution has been temporarily held (suspended).

      If job has completed its execution, then `false` is always returned.

      Specified by:
        `heldcc` in interface `ComputeJobContinuation`
      Returns:
        `True` if job has been held.

    - #### callcc

          public void callcc()

      Resumes job if it was held by `ComputeJobContinuation.holdcc()` method. Resuming job means that `ComputeJob.execute()` method will be called again. It is user's responsibility to check, as needed, whether job is executing from scratch and has been resumed.

      Note that the job is resumed with exactly the same state as of when it was 'held' via the `ComputeJobContinuation.holdcc()` method.

      If job is not running, has not been suspended, or has completed its execution, then no-op.

      The method is named after `'call-with-current-continuation'` design pattern, commonly abbreviated as `'call/cc'`, which originated in Scheme programming language.

      Specified by:
        `callcc` in interface `ComputeJobContinuation`

    - #### holdcc

          @Nullable
          public <T> T holdcc()

      Holds (suspends) a given job indefinitely until `ComputeJobContinuation.callcc()` is called. Job will remain in active queue, but its `ComputeJobContinuation.heldcc()` method will return `true`. Implementations of `CollisionSpi` should check if jobs are held or not as needed.

      All jobs should stop their execution and return right after calling `'holdcc(..)'` method. For convenience, this method always returns `null`, so you can hold and return in one line by calling `'return holdcc()'` method.

      If job is not running or has completed its execution, then no-op.

      The `'cc'` suffix stands for `'current-continuation'` which is a pretty standard notation for this concept that originated from Scheme programming language. Basically, the job is held to be continued later, hence the name of the method.

      Specified by:
        `holdcc` in interface `ComputeJobContinuation`
      Returns:
        Always returns `null` for convenience to be used in code with return statement.

    - #### holdcc

          @Nullable
          public <T> T holdcc(long timeout)

      Holds (suspends) a given job for specified timeout or until `ComputeJobContinuation.callcc()` is called. Holds (suspends) a given job for specified timeout or until `ComputeJobContinuation.callcc()` is called. Job will remain in active queue, but its `ComputeJobContinuation.heldcc()` method will return `true`. Implementations of `CollisionSpi` should check if jobs are held or not as needed.

      All jobs should stop their execution and return right after calling `'holdcc(..)'` method. For convenience, this method always returns `null`, so you can hold and return in one line by calling `'return holdcc()'`.

      If job is not running or has completed its execution, then no-op.

      The `'cc'` suffix stands for `'current-continuation'` which is a fairly standard notation for this concept. Basically, the job is held to be continued later, hence the name of the method.

      Specified by:
        `holdcc` in interface `ComputeJobContinuation`
      Parameters:
        `timeout` - Timeout in milliseconds after which job will be automatically resumed.
      Returns:
        Always returns `null` for convenience to be used in code with return statement.

2020 Copyright © Apache Software Foundation
| Follow @ApacheIgnite
Ignite Database and Caching Platform | : ver. 2.9.1
Release Date | : December 9 2020