Search in sources :

Example 76 with JetInstance

use of com.hazelcast.jet.JetInstance in project hazelcast-jet-reference-manual by hazelcast.

the class LogDebug method s3.

static void s3() {
    // tag::s3[]
    Pipeline p = Pipeline.create();
    p.drawFrom(Sources.<String>list("inputList")).flatMap(line -> traverseArray(line.toLowerCase().split("\\W+"))).filter(word -> !word.isEmpty()).peek().groupingKey(wholeItem()).aggregate(counting()).drainTo(Sinks.map("counts"));
    // end::s3[]
    // tag::s4[]
    JetInstance jet = Jet.newJetInstance();
    try {
        jet.getList("inputList").addAll(asList("The quick brown fox", "jumped over the lazy dog"));
        jet.newJob(p).join();
    } finally {
        Jet.shutdownAll();
    }
// end::s4[]
}
Also used : Sources(com.hazelcast.jet.pipeline.Sources) JetConfig(com.hazelcast.jet.config.JetConfig) AggregateOperations.counting(com.hazelcast.jet.aggregate.AggregateOperations.counting) JetInstance(com.hazelcast.jet.JetInstance) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Arrays.asList(java.util.Arrays.asList) Traversers.traverseArray(com.hazelcast.jet.Traversers.traverseArray) Sinks(com.hazelcast.jet.pipeline.Sinks) Jet(com.hazelcast.jet.Jet) DistributedFunctions.wholeItem(com.hazelcast.jet.function.DistributedFunctions.wholeItem) JetInstance(com.hazelcast.jet.JetInstance) Pipeline(com.hazelcast.jet.pipeline.Pipeline)

Example 77 with JetInstance

use of com.hazelcast.jet.JetInstance in project hazelcast-jet-reference-manual by hazelcast.

the class StartTwoInstances method main.

// tag::s2[]
public static void main(String[] args) {
    try {
        JetInstance jet = Jet.newJetInstance();
        Jet.newJetInstance();
    // work with Jet
    } finally {
        Jet.shutdownAll();
    }
}
Also used : JetInstance(com.hazelcast.jet.JetInstance)

Example 78 with JetInstance

use of com.hazelcast.jet.JetInstance in project hazelcast-jet-reference-manual by hazelcast.

the class WordCountCoreApi method main.

public static void main(String[] args) {
    // tag::s0[]
    DAG dag = new DAG();
    Vertex source = dag.newVertex("source", SourceProcessors.readMapP("lines"));
    // end::s0[]
    // tag::s1[]
    // (lineNum, line) -> words
    Pattern delimiter = Pattern.compile("\\W+");
    Vertex tokenize = dag.newVertex("tokenize", Processors.flatMapP((Entry<Integer, String> e) -> traverseArray(delimiter.split(e.getValue().toLowerCase())).filter(word -> !word.isEmpty())));
    // end::s1[]
    // tag::s2[]
    // word -> (word, count)
    Vertex accumulate = dag.newVertex("accumulate", Processors.accumulateByKeyP(singletonList(wholeItem()), counting()));
    // end::s2[]
    // tag::s3[]
    // (word, count) -> (word, count)
    Vertex combine = dag.newVertex("combine", Processors.combineByKeyP(counting(), Util::entry));
    // end::s3[]
    // tag::s4[]
    Vertex sink = dag.newVertex("sink", SinkProcessors.writeMapP("counts"));
    // end::s4[]
    // tag::s5[]
    dag.edge(between(source, tokenize)).edge(// <1>
    between(tokenize, accumulate).partitioned(wholeItem(), Partitioner.HASH_CODE)).edge(// <2>
    between(accumulate, combine).distributed().partitioned(entryKey())).edge(between(combine, sink));
    // end::s5[]
    JetInstance jet = Jet.newJetInstance();
    Jet.newJetInstance();
    try {
        IMap<Integer, String> map = jet.getMap("lines");
        map.put(0, "It was the best of times,");
        map.put(1, "it was the worst of times,");
        map.put(2, "it was the age of wisdom,");
        map.put(3, "it was the age of foolishness,");
        map.put(4, "it was the epoch of belief,");
        map.put(5, "it was the epoch of incredulity,");
        map.put(6, "it was the season of Light,");
        map.put(7, "it was the season of Darkness");
        map.put(8, "it was the spring of hope,");
        map.put(9, "it was the winter of despair,");
        map.put(10, "we had everything before us,");
        map.put(11, "we had nothing before us,");
        map.put(12, "we were all going direct to Heaven,");
        map.put(13, "we were all going direct the other way --");
        map.put(14, "in short, the period was so far like the present period, that some of " + "its noisiest authorities insisted on its being received, for good or for " + "evil, in the superlative degree of comparison only.");
        jet.newJob(dag).join();
        System.out.println(jet.getMap("counts").entrySet());
    // Expected output:
    // [heaven=1, times=2, of=12, its=2, far=1, light=1, noisiest=1,
    // the=14, other=1, incredulity=1, worst=1, hope=1, on=1, good=1, going=2,
    // like=1, we=4, was=11, best=1, nothing=1, degree=1, epoch=2, all=2,
    // that=1, us=2, winter=1, it=10, present=1, to=1, short=1, period=2,
    // had=2, wisdom=1, received=1, superlative=1, age=2, darkness=1, direct=2,
    // only=1, in=2, before=2, were=2, so=1, season=2, evil=1, being=1,
    // insisted=1, despair=1, belief=1, comparison=1, some=1, foolishness=1,
    // or=1, everything=1, spring=1, authorities=1, way=1, for=2]
    } finally {
        Jet.shutdownAll();
    }
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) Pattern(java.util.regex.Pattern) JetInstance(com.hazelcast.jet.JetInstance) DAG(com.hazelcast.jet.core.DAG)

Example 79 with JetInstance

use of com.hazelcast.jet.JetInstance in project hazelcast-jet-reference-manual by hazelcast.

the class Configuration method s3.

static void s3() {
    // tag::s3[]
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.getGroupConfig().setName("test");
    JetInstance jet = Jet.newJetClient(clientConfig);
// end::s3[]
}
Also used : JetInstance(com.hazelcast.jet.JetInstance) ClientConfig(com.hazelcast.client.config.ClientConfig)

Example 80 with JetInstance

use of com.hazelcast.jet.JetInstance in project hazelcast-jet-reference-manual by hazelcast.

the class Configuration method s2.

static void s2() {
    // tag::s2[]
    JetConfig jetConfig = new JetConfig();
    jetConfig.getHazelcastConfig().getGroupConfig().setName("test");
    JetInstance jet = Jet.newJetInstance(jetConfig);
// end::s2[]
}
Also used : JetInstance(com.hazelcast.jet.JetInstance) JetConfig(com.hazelcast.jet.config.JetConfig)

Aggregations

JetInstance (com.hazelcast.jet.JetInstance)84 Test (org.junit.Test)45 Job (com.hazelcast.jet.Job)32 JetConfig (com.hazelcast.jet.config.JetConfig)22 MockPS (com.hazelcast.jet.core.TestProcessors.MockPS)14 Pipeline (com.hazelcast.jet.pipeline.Pipeline)14 JobConfig (com.hazelcast.jet.config.JobConfig)13 StuckProcessor (com.hazelcast.jet.core.TestProcessors.StuckProcessor)12 DAG (com.hazelcast.jet.core.DAG)10 ExpectedException (org.junit.rules.ExpectedException)10 Jet (com.hazelcast.jet.Jet)9 Assert.assertEquals (org.junit.Assert.assertEquals)9 JetService (com.hazelcast.jet.impl.JetService)8 Map (java.util.Map)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 JobRepository (com.hazelcast.jet.impl.JobRepository)7 Sources (com.hazelcast.jet.pipeline.Sources)7 CancellationException (java.util.concurrent.CancellationException)7 Assert.assertNotNull (org.junit.Assert.assertNotNull)7 Before (org.junit.Before)7