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)); } }
/** * Returns the {@link JobStateSnapshot} object representing an exported * snapshot with the given name. Returns {@code null} if no such snapshot * exists. */ @Nullable default JobStateSnapshot getJobStateSnapshot(@Nonnull String name) { String mapName = exportedSnapshotMapName(name); if (!((AbstractJetInstance) this).existsDistributedObject(MapService.SERVICE_NAME, mapName)) { return null; } IMapJet<Object, Object> map = getMap(mapName); Object validationRecord = map.get(SnapshotValidationRecord.KEY); if (validationRecord instanceof SnapshotValidationRecord) { // update the cache - for robustness. For example after the map was copied getMap(JobRepository.EXPORTED_SNAPSHOTS_DETAIL_CACHE).set(name, validationRecord); return new JobStateSnapshot(this, name, (SnapshotValidationRecord) validationRecord); } else { return null; } }
public static void main(String[] args) throws Exception { System.setProperty("hazelcast.logging.type", "log4j"); Jet.newJetInstance(); JetInstance jet = Jet.newJetInstance(); try { IMapJet<Object, Object> map = jet.getMap("map"); range(0, COUNT).parallel().forEach(i -> map.put("key-" + i, i)); DAG dag = new DAG(); Vertex source = dag.newVertex("map-source", SourceProcessors.readMapP(map.getName())); Vertex sink = dag.newVertex("file-sink", new WriteFilePSupplier(OUTPUT_FOLDER)); dag.edge(between(source, sink)); jet.newJob(dag).join(); System.out.println("\nHazelcast IMap dumped to folder " + new File(OUTPUT_FOLDER).getAbsolutePath()); } finally { Jet.shutdownAll(); } } }
private void go() { setup(); buildInvertedIndex(); System.out.println("size=" + jet.getMap(INVERTED_INDEX).size()); new SearchGui(jet.getMap(INVERTED_INDEX), docLines("stopwords.txt").collect(toSet())); }
private void go() { prepareSampleData(); try { jet.newJob(coGroupDirect()).join(); validateCoGroupResults(); jet.getMap(RESULT).clear(); jet.newJob(coGroupBuild()).join(); validateCoGroupResults(); } finally { Jet.shutdownAll(); } }
double trend = 0.0; for (int i = 0; i < NUM_PREDICTIONS; i++) { Double newTrend = trendMap.get(new TrendKey(cc.location, cc.time - DAYS.toMillis(7))); if (newTrend != null) { trend = newTrend;
public static void main(String[] args) throws Exception { System.setProperty("hazelcast.logging.type", "log4j"); JetConfig jetConfig = getJetConfig(); JetInstance jet = Jet.newJetInstance(jetConfig); Jet.newJetInstance(jetConfig); try { Pipeline p = Pipeline.create(); p.drawFrom(Sources.<Integer, Integer>mapJournal(MAP_NAME, START_FROM_OLDEST)) .map(Entry::getValue) .drainTo(Sinks.list(SINK_NAME)); jet.newJob(p); IMapJet<Integer, Integer> map = jet.getMap(MAP_NAME); for (int i = 0; i < 1000; i++) { map.set(i, i); } TimeUnit.SECONDS.sleep(3); System.out.println("Read " + jet.getList(SINK_NAME).size() + " entries from map journal."); } finally { Jet.shutdownAll(); } }
private void run() throws Exception { JetConfig cfg = new JetConfig(); cfg.setInstanceConfig(new InstanceConfig().setCooperativeThreadCount( Math.max(1, getRuntime().availableProcessors() / 2))); try { createKafkaCluster(); fillTopics(); JetInstance instance = Jet.newJetInstance(cfg); Jet.newJetInstance(cfg); IMapJet<String, Integer> sinkMap = instance.getMap(SINK_NAME); Pipeline p = buildPipeline(); long start = System.nanoTime(); Job job = instance.newJob(p); while (true) { int mapSize = sinkMap.size(); System.out.format("Received %d entries in %d milliseconds.%n", mapSize, NANOSECONDS.toMillis(System.nanoTime() - start)); if (mapSize == MESSAGE_COUNT_PER_TOPIC * 2) { job.cancel(); break; } Thread.sleep(100); } } finally { Jet.shutdownAll(); shutdownKafkaCluster(); } }
private void go() { prepareSampleData(); try { jet.newJob(coGroupDirect()).join(); validateCoGroupResults(); jet.getMap(RESULT).clear(); jet.newJob(coGroupBuild()).join(); validateCoGroupResults(); } finally { Jet.shutdownAll(); } }
SnapshotValidationRecord validationRecord = (SnapshotValidationRecord) jetInstance.getMap(sourceMapName) .get(SnapshotValidationRecord.KEY); jobRepository.cacheValidationRecord(name, validationRecord); if (cancelJob) {
private static void updatePrices(JetInstance jet) { IMapJet<String, Tuple2<Integer, Long>> prices = jet.getMap(PRICES_MAP_NAME); int price = 100; long timestamp = 0; while (true) { for (String ticker : TICKER_LIST) { prices.put(ticker, tuple2(price, timestamp)); } price++; timestamp += 1000; try { Thread.sleep(1000); } catch (InterruptedException e) { return; } } } }
public static void main(String[] args) throws Exception { System.setProperty("hazelcast.logging.type", "log4j"); NettyServer nettyServer = new NettyServer(PORT, DistributedConsumer.noop(), msg -> COUNTER.incrementAndGet()); nettyServer.start(); JetInstance jet = Jet.newJetInstance(); Jet.newJetInstance(); try { System.out.println("Populating map..."); IMapJet<Integer, Integer> map = jet.getMap(SOURCE_NAME); IntStream.range(0, SOURCE_ITEM_COUNT).parallel().forEach(i -> map.put(i, i)); Pipeline p = Pipeline.create(); p.drawFrom(Sources.map(SOURCE_NAME)) .drainTo(Sinks.socket(HOST, PORT, e -> e.getValue().toString(), UTF_8)); System.out.println("Executing job..."); jet.newJob(p).join(); } finally { nettyServer.stop(); Jet.shutdownAll(); } System.out.println("Server read " + COUNTER.get() + " items from the socket."); } }
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); }
readLines("products.txt").forEach(e -> productMap.put(e.getKey(), new Product(e.getKey(), e.getValue()))); System.out.println("Loaded product map:"); printMap(productMap); readLines("brokers.txt").forEach(e -> brokerMap.put(e.getKey(), new Broker(e.getKey(), e.getValue()))); System.out.println("Loaded brokers map:"); printMap(brokerMap);