@RequestMapping("/put") public CommandResponse put(@RequestParam(value = "name") String name, @RequestParam(value = "key") Integer key, @RequestParam(value = "value") String value) { IMap<Integer, String> map = jetClient.getMap(name); String oldValue = map.put(key, value); return new CommandResponse(oldValue); }
@RequestMapping("/get") public CommandResponse get(@RequestParam(value = "name") String name, @RequestParam(value = "key") Object key) { IMap<Object, String> map = jetClient.getMap(name); String value = map.get(key); return new CommandResponse(value); }
/** * Inserts the sequence 1..ITEM_COUNT into {@code sourceMapName} as (1,1) , (2,2) ....( ITEM_COUNT-1, ITEM_COUNT-1) */ private static void prepareSampleInput(JetInstance instance, String sourceMapName) { IMap<Integer, Integer> sourceMap = instance.getMap(sourceMapName); for (int i = 0; i < ITEM_COUNT; i++) { sourceMap.put(i, i); } }
private void buildDocumentInventory() { ClassLoader cl = TfIdfCoreApi.class.getClassLoader(); try (BufferedReader r = new BufferedReader(new InputStreamReader(cl.getResourceAsStream("books"), UTF_8))) { IMap<Long, String> docId2Name = jet.getMap(DOCID_NAME); long[] docId = {0}; r.lines().peek(System.out::println).forEach(fname -> docId2Name.put(++docId[0], fname)); } catch (IOException e) { throw new RuntimeException(e); } }
@RequestMapping("/size") public CommandResponse size(@RequestParam(value = "name") String name) { IMap<Integer, String> map = jetClient.getMap(name); int size = map.size(); return new CommandResponse(Integer.toString(size)); }
/** * Dumps contents of the IMap named {@code mapName} to the output stream */ private static void dumpMap(JetInstance instance, String mapName) { IMap sinkMap = instance.getMap(mapName); System.out.println("Sink map size: " + sinkMap.size()); System.out.println("Sink map entries: "); sinkMap.forEach((k, v) -> System.out.println(k + " - " + v)); }
/** * Prints state transitions from IMap, generates the markov chain and prints it */ private static void printTransitionsAndMarkovChain(JetInstance jet) { IMapJet<String, SortedMap<Double, String>> transitions = jet.getMap("stateTransitions"); printTransitions(transitions); String chain = generateMarkovChain(1000, transitions); System.out.println(chain); }
private void setup() throws Exception { dbDirectory = Files.createTempDirectory(JdbcSink.class.getName()).toString(); createTable(); jet = Jet.newJetInstance(); Jet.newJetInstance(); IMapJet<Integer, User> map = jet.getMap(MAP_NAME); // populate the source IMap for (int i = 0; i < 100; i++) { map.put(i, new User(i, "name-" + i)); } }
private void validateCoGroupResults() { IMap<Integer, Tuple3<List<PageVisit>, List<AddToCart>, List<Payment>>> result = jet.getMap(RESULT); printImap(result); for (int userId = 11; userId < 13; userId++) { Tuple3<List<PageVisit>, List<AddToCart>, List<Payment>> r = result.get(userId); assertEqual(userId2PageVisit.get(userId), r.f0()); assertEqual(userId2AddToCart.get(userId), r.f1()); assertEqual(userId2Payment.get(userId), r.f2()); } System.out.println("BatchCoGroup results are valid"); }
private void validateCoGroupResults() { IMap<Integer, Tuple3<List<PageVisit>, List<AddToCart>, List<Payment>>> result = jet.getMap(RESULT); printImap(result); for (int userId = 11; userId < 13; userId++) { Tuple3<List<PageVisit>, List<AddToCart>, List<Payment>> r = result.get(userId); assertEqual(userId2PageVisit.get(userId), r.f0()); assertEqual(userId2AddToCart.get(userId), r.f1()); assertEqual(userId2Payment.get(userId), r.f2()); } System.out.println("BatchCoGroup results are valid"); }
public static void main(String[] args) { JetInstance jet = Jet.newJetInstance(); Pipeline pipeline = buildPipeline(); addListener(jet.getMap(TAKE_OFF_MAP), a -> System.out.println("New aircraft taking off: " + a)); addListener(jet.getMap(LANDING_MAP), a -> System.out.println("New aircraft landing " + a)); try { Job job = jet.newJob(pipeline, new JobConfig().setName("FlightTelemetry").setProcessingGuarantee(ProcessingGuarantee.EXACTLY_ONCE)); job.join(); } finally { Jet.shutdownAll(); } }
private void go() { try { setup(); jet.newJob(buildPipeline()).join(); IMapJet<String, User> map = jet.getMap(AvroSink.MAP_NAME); System.out.println("Map Size: " + map.size()); map.forEach((key, value) -> System.out.println(key + " - " + value)); } finally { Jet.shutdownAll(); } }
private void setup() { jet = Jet.newJetInstance(); Jet.newJetInstance(); IMapJet<String, User> map = jet.getMap(MAP_NAME); for (int i = 0; i < 100; i++) { User user = new User("User" + i, "pass" + i, i, i % 2 == 0); map.put(user.getUsername(), user); } }
@Before public void setup() { JetConfig cfg = new JetConfig(); cfg.getHazelcastConfig().addEventJournalConfig(new EventJournalConfig().setMapName(SOURCE_NAME)); jet = createJetMember(cfg); baosOut = new ByteArrayOutputStream(); baosErr = new ByteArrayOutputStream(); out = new PrintStream(baosOut); err = new PrintStream(baosErr); sourceMap = jet.getMap(SOURCE_NAME); IntStream.range(0, ITEM_COUNT).forEach(i -> sourceMap.put(i, i)); sinkList = jet.getList(SINK_NAME); }
private void go() { prepareSampleData(); try { jet.newJob(coGroupDirect()).join(); validateCoGroupResults(); jet.getMap(RESULT).clear(); jet.newJob(coGroupBuild()).join(); validateCoGroupResults(); } finally { Jet.shutdownAll(); } }
private void go() { prepareSampleData(); try { jet.newJob(coGroupDirect()).join(); validateCoGroupResults(); jet.getMap(RESULT).clear(); jet.newJob(coGroupBuild()).join(); validateCoGroupResults(); } finally { Jet.shutdownAll(); } }