Class Jet
public final class Jet extends Object
- Since:
- 3.0
-
Method Summary
Modifier and Type Method Description static JetInstance
bootstrappedInstance()
Returns either a local Jet instance or a "bootstrapped" Jet client for a remote Jet cluster, depending on the context.static JetInstance
newJetClient()
Creates a Jet client with the default configuration.static JetInstance
newJetClient(ClientConfig config)
Creates a Jet client with the given Hazelcast client configuration.static JetInstance
newJetFailoverClient()
Creates a Jet client with cluster failover capability.static JetInstance
newJetFailoverClient(ClientFailoverConfig config)
Creates a Jet client with cluster failover capability.static JetInstance
newJetInstance()
Creates a member of the Jet cluster with the configuration loaded from default location.static JetInstance
newJetInstance(JetConfig config)
Creates a member of the Jet cluster with the given configuration.static void
shutdownAll()
Shuts down all running Jet client and member instances.
-
Method Details
-
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 tooljet 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 localJetInstance
, 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.
To use this feature, follow these steps:
-
Write your
main()
method and your Jet code the usual way, making sure you use this method (instead ofnewJetClient()
) to acquire a Jet client instance. -
Create a runnable JAR (e.g.
jetjob.jar
) with your entry point declared as theMain-Class
inMANIFEST.MF
. The JAR should include all dependencies required to run it (except the Jet classes — these are already available on the cluster classpath). -
Submit the job by writing
jet submit jetjob.jar
on the command line. This assumes you have downloaded the Jet distribution package and itsbin
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. - 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.
public class CustomJetJob { public static void main(String[] args) { JetInstance jet = Jet.bootstrappedInstance(); jet.newJob(buildPipeline()).join(); } public static Pipeline createPipeline() { // ... } }
- Since:
- 4.0
-
When not called from
-
newJetInstance
Creates a member of the Jet cluster with the configuration loaded from default location. -
newJetInstance
Creates a member of the Jet cluster with the given configuration. -
newJetClient
Creates a Jet client with the default configuration. -
newJetClient
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
Creates a Jet client with cluster failover capability. Client will try to connect to alternative clusters according to the suppliedClientFailoverConfig
when it disconnects from a cluster. -
newJetFailoverClient
Creates a Jet client with cluster failover capability. The client will try to connect to alternative clusters as specified in the resolvedClientFailoverConfig
when it disconnects from a cluster.The failover configuration is loaded using the following resolution mechanism:
- System property
hazelcast.client.failover.config
is checked. If found, and begins withclasspath:
, 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 hazelcast-client-failover.xml
is checked on in the working dirhazelcast-client-failover.xml
is checked on the classpathhazelcast-client-failover.yaml
is checked on the working dirhazelcast-client-failover.yaml
is checked on the classpath- If none are available, then a
HazelcastException
is thrown
- System property
-
shutdownAll
public static void shutdownAll()Shuts down all running Jet client and member instances.
-