com.hazelcast.jet

## Interface JetInstance

-     public interface JetInstance

  Represents either an instance of a Jet server node or a Jet client instance that connects to a remote cluster.
  Since:
    3.0

- - ### Method Summary

    All Methods Instance Methods Abstract Methods Default Methods
    Modifier and Type | Method and Description
    --- | ---
    `JetCacheManager` | `getCacheManager()` Obtain the `JetCacheManager` that provides access to JSR-107 (JCache) caches configured on a Hazelcast Jet cluster.
    `Cluster` | `getCluster()` Returns information about the cluster this Jet instance is part of.
    `JetConfig` | `getConfig()` Returns the configuration for this Jet member.
    `HazelcastInstance` | `getHazelcastInstance()` Returns the underlying Hazelcast IMDG instance used by Jet.
    `Job` | `getJob(long jobId)` Returns the job with the given id or `null` if no such job could be found.
    `default Job` | `getJob(String name)` Returns the active or last submitted job with the given name or `null` if no such job could be found.
    `List<Job>` | `getJobs()` Returns all submitted jobs including running and completed ones.
    `List<Job>` | `getJobs(String name)` Returns all jobs submitted with the given name, ordered in descending order by submission time.
    `default JobStateSnapshot` | `getJobStateSnapshot(String name)` Returns the `JobStateSnapshot` object representing an exported snapshot with the given name.
    `default Collection<JobStateSnapshot>` | `getJobStateSnapshots()` Returns the collection of exported job state snapshots stored in the cluster.
    `<E> IListJet<E>` | `getList(String name)` Returns the distributed list instance with the specified name.
    `<K,V> IMapJet<K,V>` | `getMap(String name)` Returns the distributed map instance with the specified name.
    `String` | `getName()` Returns the name of the Jet instance.
    `<K,V> ReplicatedMap<K,V>` | `getReplicatedMap(String name)` Returns the replicated map instance with the specified name.
    `default Job` | `newJob(DAG dag)` Creates and returns a Jet job based on the supplied DAG.
    `Job` | `newJob(DAG dag, JobConfig config)` Creates and returns a Jet job based on the supplied DAG and job configuration.
    `default Job` | `newJob(Pipeline pipeline)` Creates and returns an executable job based on the supplied pipeline.
    `default Job` | `newJob(Pipeline pipeline, JobConfig config)` Creates and returns a Jet job based on the supplied pipeline and job configuration.
    `Job` | `newJobIfAbsent(DAG dag, JobConfig config)` Creates and returns a Jet job based on the supplied DAG and job configuration.
    `default Job` | `newJobIfAbsent(Pipeline pipeline, JobConfig config)` Creates and returns a Jet job based on the supplied pipeline and job configuration.
    `void` | `shutdown()` Shuts down the current instance.

- - ### Method Detail

    - #### getName

          @Nonnull
          String getName()

      Returns the name of the Jet instance.

    - #### getHazelcastInstance

          @Nonnull
          HazelcastInstance getHazelcastInstance()

      Returns the underlying Hazelcast IMDG instance used by Jet. It will be either a server node or a client, depending on the type of this `JetInstance`.

    - #### getCluster

          @Nonnull
          Cluster getCluster()

      Returns information about the cluster this Jet instance is part of.

    - #### getConfig

          @Nonnull
          JetConfig getConfig()

      Returns the configuration for this Jet member. This method is not available on client instances.

    - #### newJob

          @Nonnull
          default Job newJob(@Nonnull
                                      DAG dag)

      Creates and returns a Jet job based on the supplied DAG. Jet will asynchronously start executing the job.

    - #### newJob

          @Nonnull
          default Job newJob(@Nonnull
                                      Pipeline pipeline)

      Creates and returns an executable job based on the supplied pipeline. Jet will asynchronously start executing the job.

    - #### newJob

          @Nonnull
          Job newJob(@Nonnull
                              DAG dag,
                              @Nonnull
                              JobConfig config)

      Creates and returns a Jet job based on the supplied DAG and job configuration. Jet will asynchronously start executing the job.

      If the name in the JobConfig is non-null, Jet checks if there is an active job with equal name, in which case it throws `JobAlreadyExistsException`. Job is active if it is running, suspended or waiting to be run; that is it has not completed or failed. Thus there can be at most one active job with a given name at a time and you can re-use the job name after the previous job completed.

      See also `newJobIfAbsent(com.hazelcast.jet.core.DAG, com.hazelcast.jet.config.JobConfig)`.

      Throws:
        `JobAlreadyExistsException` - if there is an active job with an equal name

    - #### newJob

          @Nonnull
          default Job newJob(@Nonnull
                                      Pipeline pipeline,
                                      @Nonnull
                                      JobConfig config)

      Creates and returns a Jet job based on the supplied pipeline and job configuration. Jet will asynchronously start executing the job.

      If the name in the JobConfig is non-null, Jet checks if there is an active job with equal name, in which case it throws `JobAlreadyExistsException`. Job is active if it is running, suspended or waiting to be run; that is it has not completed or failed. Thus there can be at most one active job with a given name at a time and you can re-use the job name after the previous job completed.

      See also `newJobIfAbsent(com.hazelcast.jet.core.DAG, com.hazelcast.jet.config.JobConfig)`.

      Throws:
        `JobAlreadyExistsException` - if there is an active job with an equal name

    - #### newJobIfAbsent

          @Nonnull
          Job newJobIfAbsent(@Nonnull
                                      DAG dag,
                                      @Nonnull
                                      JobConfig config)

      Creates and returns a Jet job based on the supplied DAG and job configuration. Jet will asynchronously start executing the job.

      If the name in the JobConfig is non-null, Jet checks if there is an active job with equal name. If there is, it will join that job instead of submitting a new one. Job is active if it is running, suspended or waiting to be run; that is it has not completed or failed. In other words, this method ensures that the job with this name is running and is not running multiple times in parallel.

      This method is useful for microservices deployment when each package contains a jet member and the job and you want the job to run only once. But if the job is a batch job and runs very quickly, it can happen that it executes multiple times, because the job name can be reused after a previous execution completed.

      If the job name is null, a new job is always submitted.

      See also `newJob(com.hazelcast.jet.core.DAG)`.

    - #### newJobIfAbsent

          @Nonnull
          default Job newJobIfAbsent(@Nonnull
                                              Pipeline pipeline,
                                              @Nonnull
                                              JobConfig config)

      Creates and returns a Jet job based on the supplied pipeline and job configuration. Jet will asynchronously start executing the job.

      If the name in the JobConfig is non-null, Jet checks if there is an active job with equal name. If there is, it will join that job instead of submitting a new one. Job is active if it is running, suspended or waiting to be run; that is it has not completed or failed. In other words, this method ensures that the job with this name is running and is not running multiple times in parallel.

      This method is useful for microservices deployment when each package contains a jet member and the job and you want the job to run only once. But if the job is a batch job and runs very quickly, it can happen that it executes multiple times, because the job name can be reused after a previous execution completed.

      If the job name is null, a new job is always submitted.

      See also `newJob(com.hazelcast.jet.core.DAG)`.

    - #### getJobs

          @Nonnull
          List<Job> getJobs()

      Returns all submitted jobs including running and completed ones.

    - #### getJob

          @Nullable
          Job getJob(long jobId)

      Returns the job with the given id or `null` if no such job could be found.

    - #### getJobs

          @Nonnull
          List<Job> getJobs(@Nonnull
                                     String name)

      Returns all jobs submitted with the given name, ordered in descending order by submission time. The active job is always first. Empty list will be returned if no job with the given name exists. The list includes completed jobs.

    - #### getJob

          @Nullable
          default Job getJob(@Nonnull
                                       String name)

      Returns the active or last submitted job with the given name or `null` if no such job could be found. The returned job can be already completed.

    - #### getJobStateSnapshot

          @Nullable
          default JobStateSnapshot getJobStateSnapshot(@Nonnull
                                                                 String name)

      Returns the `JobStateSnapshot` object representing an exported snapshot with the given name. Returns `null` if no such snapshot exists.

    - #### getJobStateSnapshots

          @Nonnull
          default Collection<JobStateSnapshot> getJobStateSnapshots()

      Returns the collection of exported job state snapshots stored in the cluster.

    - #### getMap

          @Nonnull
          <K,V> IMapJet<K,V> getMap(@Nonnull
                                             String name)

      Returns the distributed map instance with the specified name.
      Parameters:
        `name` - name of the distributed map
      Returns:
        distributed map instance with the specified name

    - #### getReplicatedMap

          @Nonnull
          <K,V> ReplicatedMap<K,V> getReplicatedMap(@Nonnull
                                                             String name)

      Returns the replicated map instance with the specified name.

      A replicated map can be used for enriching a stream, see `GeneralStage.mapUsingReplicatedMap(String, FunctionEx, BiFunctionEx)`.

      Parameters:
        `name` - name of the distributed map
      Returns:
        distributed map instance with the specified name

    - #### getList

          @Nonnull
          <E> IListJet<E> getList(@Nonnull
                                           String name)

      Returns the distributed list instance with the specified name.
      Parameters:
        `name` - name of the distributed list
      Returns:
        distributed list instance with the specified name

    - #### getCacheManager

          @Nonnull
          JetCacheManager getCacheManager()

      Obtain the `JetCacheManager` that provides access to JSR-107 (JCache) caches configured on a Hazelcast Jet cluster.

      Note that this method does not return a JCache `CacheManager`

      Returns:
        the Hazelcast Jet `JetCacheManager`
      See Also:
        `JetCacheManager`

    - #### shutdown

          void shutdown()

      Shuts down the current instance. If this is a client instance, it disconnects the client. If this is a member instance, it gracefully terminates the jobs running on it and, if so configured, restarts them after this instance has shut down. When shutting down the entire cluster, it is a good practice to manually suspend all the jobs so that they don't get restarted multiple times as each member shuts down.

      The call blocks until the instance is actually down.

      Note: If you call `this.getHazelcastInstance().shutdown()`, it will cause all the jobs that run on this member to be forcefully terminated, without creating a terminal snapshot. After the cluster stabilizes again, Jet will restart them from the last snapshot that was created some time ago.

Copyright © 2019. All rights reserved.