com.hazelcast.jet

## Interface Job

-     public interface Job

  A Jet computation job created from a `DAG` or `Pipeline`. Once submitted, Jet starts executing the job automatically.

- - ### Method Summary

    All Methods Instance Methods Abstract Methods Default Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `cancel()` Makes a request to cancel this job and returns.
    `JobConfig` | `getConfig()` Returns the configuration this job was submitted with.
    `CompletableFuture<Void>` | `getFuture()` Gets the future associated with the job.
    `long` | `getId()` Returns the ID of this job.
    `default String` | `getName()` Returns the name of this job or `null` if no name was supplied.
    `JobStatus` | `getStatus()` Returns the current status of this job.
    `long` | `getSubmissionTime()` Returns the time when the job was submitted to the cluster.
    `default void` | `join()` Waits for the job to complete and throws an exception if the job completes with an error.
    `void` | `restart()` Gracefully stops the current execution and schedules a new execution with the current member list of the Jet cluster.
    `void` | `resume()` Resumes a suspended job.
    `void` | `suspend()` Gracefully suspends the current execution of the job.

- - ### Method Detail

    - #### getId

          long getId()

      Returns the ID of this job.
      Throws:
        `IllegalStateException` - if the job has not started yet, and thus has no id.

    - #### getConfig

          @Nonnull
          JobConfig getConfig()

      Returns the configuration this job was submitted with. Changes made to the returned config object will not have any affect.

    - #### getName

          @Nullable
          default String getName()

      Returns the name of this job or `null` if no name was supplied.

      Jobs can be named through `JobConfig.setName(String)` prior to submission.

    - #### getSubmissionTime

          long getSubmissionTime()

      Returns the time when the job was submitted to the cluster.

      The time is assigned by reading `System.currentTimeMillis()` of the master member that executes the job for the first time. It doesn't change on restart.

    - #### getStatus

          @Nonnull
          JobStatus getStatus()

      Returns the current status of this job.

    - #### getFuture

          @Nonnull
          CompletableFuture<Void> getFuture()

      Gets the future associated with the job. The returned future is not cancellable. To cancel the job, the `cancel()` method should be used.
      Throws:
        `IllegalStateException` - if the job has not started yet.

    - #### join

          default void join()

      Waits for the job to complete and throws an exception if the job completes with an error. Does not return if the job gets suspended. Never returns for streaming (unbounded) jobs unless they fail.

      Shorthand for `job.getFuture().get()`.

    - #### restart

          void restart()

      Gracefully stops the current execution and schedules a new execution with the current member list of the Jet cluster. Can be called to manually make use of added members, if auto scaling is disabled. Only a running job can be restarted; a suspended job must be resumed.

      Conceptually this call is equivalent to `suspend()` & `resume()`.

      Throws:
        `IllegalStateException` - if the job is not running, for example it has already completed, is not yet running, is already restarting, suspended etc.

    - #### suspend

          void suspend()

      Gracefully suspends the current execution of the job. The job's status will become `JobStatus.SUSPENDED`. To resume the job, call `resume()`.

      You can suspend a job even if it's not configured for snapshotting. Such a job will resume with empty state, as if it has just been started.

      This call just initiates the suspension process and doesn't wait for it to complete. Suspension starts with creating a terminal state snapshot. Should the terminal snapshot fail, the job will suspend anyway, but the previous snapshot (if there was one) won't be deleted. When the job resumes, its processing starts from the point of the last snapshot.

      NOTE: if the cluster becomes unstable (a member leaves or similar) while the job is in the process of being suspended, it may end up getting immediately restarted. Call `getStatus()` to find out and possibly try to suspend again.

      Throws:
        `IllegalStateException` - if the job is not running

    - #### resume

          void resume()

      Resumes a suspended job. The job will resume from the last known successful snapshot, if there is one.

      If the job is not suspended, it does nothing.

    - #### cancel

          void cancel()

      Makes a request to cancel this job and returns. The job will complete after its execution has stopped on all the nodes. If the job is already suspended, Jet will delete its runtime state so it can't be resumed.

      NOTE: if the cluster becomes unstable (a member leaves or similar) while the job is in the process of being cancelled, it may end up getting restarted after the cluster has stabilized. Call `getStatus()` to find out and possibly try to cancel again.

      Throws:
        `IllegalStateException` - if the cluster is not in a state to restart the job, for example when coordinator member left and new coordinator did not yet load job's metadata.

Copyright © 2018. All rights reserved.