Search in sources :

Example 21 with Sources

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

the class ImdgConnectors method s14.

static void s14() {
    JetInstance jet = Jet.newJetInstance();
    // tag::s14[]
    IList<Integer> inputList = jet.getList("inputList");
    for (int i = 0; i < 10; i++) {
        inputList.add(i);
    }
    Pipeline p = Pipeline.create();
    p.drawFrom(Sources.<Integer>list("inputList")).map(i -> "item" + i).drainTo(Sinks.list("resultList"));
    jet.newJob(p).join();
    IList<String> resultList = jet.getList("resultList");
    System.out.println("Results: " + new ArrayList<>(resultList));
// end::s14[]
}
Also used : EventJournalCacheEvent(com.hazelcast.cache.journal.EventJournalCacheEvent) JetConfig(com.hazelcast.jet.config.JetConfig) StreamStage(com.hazelcast.jet.pipeline.StreamStage) Person(datamodel.Person) JetInstance(com.hazelcast.jet.JetInstance) DistributedFunctions(com.hazelcast.jet.function.DistributedFunctions) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Sinks(com.hazelcast.jet.pipeline.Sinks) IListJet(com.hazelcast.jet.IListJet) EntryBackupProcessor(com.hazelcast.map.EntryBackupProcessor) ArrayList(java.util.ArrayList) BatchStage(com.hazelcast.jet.pipeline.BatchStage) Sources(com.hazelcast.jet.pipeline.Sources) EntryProcessor(com.hazelcast.map.EntryProcessor) Entry(java.util.Map.Entry) START_FROM_CURRENT(com.hazelcast.jet.pipeline.JournalInitialPosition.START_FROM_CURRENT) ClientConfig(com.hazelcast.client.config.ClientConfig) IList(com.hazelcast.core.IList) Jet(com.hazelcast.jet.Jet) DistributedFunction(com.hazelcast.jet.function.DistributedFunction) EventJournalMapEvent(com.hazelcast.map.journal.EventJournalMapEvent) JetInstance(com.hazelcast.jet.JetInstance) ArrayList(java.util.ArrayList) Pipeline(com.hazelcast.jet.pipeline.Pipeline)

Example 22 with Sources

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

the class ImdgConnectors method s5.

static void s5() {
    // tag::s5[]
    Pipeline pipeline = Pipeline.create();
    pipeline.drawFrom(Sources.<String, Integer>map("mymap")).drainTo(Sinks.mapWithEntryProcessor("mymap", Entry::getKey, entry -> new IncrementEntryProcessor(5)));
// end::s5[]
}
Also used : EventJournalCacheEvent(com.hazelcast.cache.journal.EventJournalCacheEvent) JetConfig(com.hazelcast.jet.config.JetConfig) StreamStage(com.hazelcast.jet.pipeline.StreamStage) Person(datamodel.Person) JetInstance(com.hazelcast.jet.JetInstance) DistributedFunctions(com.hazelcast.jet.function.DistributedFunctions) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Sinks(com.hazelcast.jet.pipeline.Sinks) IListJet(com.hazelcast.jet.IListJet) EntryBackupProcessor(com.hazelcast.map.EntryBackupProcessor) ArrayList(java.util.ArrayList) BatchStage(com.hazelcast.jet.pipeline.BatchStage) Sources(com.hazelcast.jet.pipeline.Sources) EntryProcessor(com.hazelcast.map.EntryProcessor) Entry(java.util.Map.Entry) START_FROM_CURRENT(com.hazelcast.jet.pipeline.JournalInitialPosition.START_FROM_CURRENT) ClientConfig(com.hazelcast.client.config.ClientConfig) IList(com.hazelcast.core.IList) Jet(com.hazelcast.jet.Jet) DistributedFunction(com.hazelcast.jet.function.DistributedFunction) EventJournalMapEvent(com.hazelcast.map.journal.EventJournalMapEvent) Pipeline(com.hazelcast.jet.pipeline.Pipeline)

Example 23 with Sources

use of com.hazelcast.jet.pipeline.Sources 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 24 with Sources

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

the class WhatIsDistributedComputing method s1.

static void s1() {
    // tag::s1[]
    Pattern delimiter = Pattern.compile("\\W+");
    Pipeline p = Pipeline.create();
    p.drawFrom(Sources.<Long, String>map("book-lines")).flatMap(e -> traverseArray(delimiter.split(e.getValue().toLowerCase()))).filter(word -> !word.isEmpty()).groupingKey(wholeItem()).aggregate(AggregateOperations.counting()).drainTo(Sinks.map("counts"));
// end::s1[]
}
Also used : Arrays(java.util.Arrays) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Sinks(com.hazelcast.jet.pipeline.Sinks) AggregateOperations(com.hazelcast.jet.aggregate.AggregateOperations) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) DistributedFunctions.wholeItem(com.hazelcast.jet.function.DistributedFunctions.wholeItem) ArrayList(java.util.ArrayList) Sources(com.hazelcast.jet.pipeline.Sources) List(java.util.List) Map(java.util.Map) Traversers.traverseArray(com.hazelcast.jet.Traversers.traverseArray) Entry(java.util.Map.Entry) Pattern(java.util.regex.Pattern) Pattern(java.util.regex.Pattern) Pipeline(com.hazelcast.jet.pipeline.Pipeline)

Aggregations

Pipeline (com.hazelcast.jet.pipeline.Pipeline)24 Sources (com.hazelcast.jet.pipeline.Sources)24 Sinks (com.hazelcast.jet.pipeline.Sinks)23 JetInstance (com.hazelcast.jet.JetInstance)18 Entry (java.util.Map.Entry)18 JetConfig (com.hazelcast.jet.config.JetConfig)15 Test (org.junit.Test)14 IList (com.hazelcast.core.IList)12 Arrays.asList (java.util.Arrays.asList)12 Assert.assertEquals (org.junit.Assert.assertEquals)12 AggregateOperation (com.hazelcast.jet.aggregate.AggregateOperation)11 Tag (com.hazelcast.jet.datamodel.Tag)11 Before (org.junit.Before)11 Category (org.junit.experimental.categories.Category)11 RunWith (org.junit.runner.RunWith)11 Util.entry (com.hazelcast.jet.Util.entry)10 JetTestSupport (com.hazelcast.jet.core.JetTestSupport)10 HazelcastParallelClassRunner (com.hazelcast.test.HazelcastParallelClassRunner)10 EventJournalConfig (com.hazelcast.config.EventJournalConfig)9 IMap (com.hazelcast.core.IMap)9