Class Jet


public final class Jet
extends Object
Entry point to the Jet product.
  • Method Details

    • bootstrappedInstance

      @Nonnull public static JetInstance bootstrappedInstance()
      Returns either a local Jet instance or a "bootstrapped" Jet client for a remote Jet cluster, depending on the context. The main goal of this factory method is to simplify submitting a Jet job to a remote cluster while also making it convenient to test on the local machine.

      When you submit a job to a Jet instance that runs locally in your JVM, it will have all the dependency classes available. However, when you take the same job to a remote Jet cluster, you'll often find that it fails with a ClassNotFoundException because the remote cluster doesn't have all the classes you use in the job.

      Normally you would have to explicitly add all the dependency classes to the JobConfig, either one by one or packaged into a JAR. If you're submitting a job using the command-line tool jet submit, the JAR to attach is the same JAR that contains the code that submits the job.

      This factory takes all of the above into account in order to provide a smoother experience:

      • When not called from jet submit, it returns a local JetInstance, either by creating a new one or looking up a cached one. The instance won't join any cluster.
      • When called from jet submit, it returns a "bootstrapped" instance of Jet client that automatically attaches the JAR to all jobs you submit using it.
      With these semantics in place it's simple to write code that works both in your local development/testing environment (using a local Jet instance) and in production (using the remote cluster).

      To use this feature, follow these steps:

      1. Write your main() method and your Jet code the usual way, making sure you use this method (instead of newJetClient()) to acquire a Jet client instance.
      2. Create a runnable JAR (e.g. jetjob.jar) with your entry point declared as the Main-Class in MANIFEST.MF. The JAR should include all dependencies required to run it (except the Jet classes — these are already available on the cluster classpath).
      3. Submit the job by writing jet submit jetjob.jar on the command line. This assumes you have downloaded the Jet distribution package and its bin directory is on your system path. The Jet client will use the configuration file <distro_root>/config/hazelcast-client.yaml. Adjust that file as needed.
      4. The same code will work if you run it directly from your IDE. In this case it will create a local Jet instance for itself to run on.
      For example, you can write a class like this:
       public class CustomJetJob {
         public static void main(String[] args) {
           JetInstance jet = Jet.bootstrappedInstance();
         public static Pipeline createPipeline() {
             // ...
    • newJetInstance

      @Nonnull public static JetInstance newJetInstance()
      Creates a member of the Jet cluster with the configuration loaded from default location.
    • newJetInstance

      @Nonnull public static JetInstance newJetInstance​(@Nonnull JetConfig config)
      Creates a member of the Jet cluster with the given configuration.
    • newJetClient

      @Nonnull public static JetInstance newJetClient()
      Creates a Jet client with the default configuration.
    • newJetClient

      @Nonnull public static JetInstance newJetClient​(@Nonnull ClientConfig config)
      Creates a Jet client with the given Hazelcast client configuration.

      JetClientConfig may be used to create a configuration with the default group name for Jet.

    • newJetFailoverClient

      @Nonnull public static JetInstance newJetFailoverClient​(@Nonnull ClientFailoverConfig config)
      Creates a Jet client with cluster failover capability. Client will try to connect to alternative clusters according to the supplied ClientFailoverConfig when it disconnects from a cluster.
    • newJetFailoverClient

      @Nonnull public static JetInstance newJetFailoverClient()
      Creates a Jet client with cluster failover capability. The client will try to connect to alternative clusters as specified in the resolved ClientFailoverConfig when it disconnects from a cluster.

      The failover configuration is loaded using the following resolution mechanism:

      1. System property hazelcast.client.failover.config is checked. If found, and begins with classpath:, then a classpath resource is loaded, otherwise it will be loaded from the file system. The configuration can be either an XML or a YAML file, distinguished by the suffix of the provided file
      2. hazelcast-client-failover.xml is checked on in the working dir
      3. hazelcast-client-failover.xml is checked on the classpath
      4. hazelcast-client-failover.yaml is checked on the working dir
      5. hazelcast-client-failover.yaml is checked on the classpath
      6. If none are available, then a HazelcastException is thrown
    • shutdownAll

      public static void shutdownAll()
      Shuts down all running Jet client and member instances.