/** {@inheritDoc} */ @Nullable @Override public Map<String, Collection<?>> run(GridStreamerContext ctx, Collection<Bar> bars) throws GridException { ConcurrentMap<String, Bar> loc = ctx.localSpace(); GridStreamerWindow win = ctx.window("stage2"); // Add numbers to window. win.enqueueAll(bars); Collection<Bar> polled = win.pollEvictedBatch(); if (!polled.isEmpty()) { Map<String, Bar> map = new HashMap<>(); for (Bar polledBar : polled) { String symbol = polledBar.symbol(); Bar bar = map.get(symbol); if (bar == null) map.put(symbol, bar = new Bar(symbol)); bar.update(polledBar); } loc.putAll(map); } return null; }
/** {@inheritDoc} */ @Nullable @Override public Map<String, Collection<?>> run(GridStreamerContext ctx, Collection<Quote> quotes) throws GridException { GridStreamerWindow win = ctx.window("stage1"); // Add numbers to window. win.enqueueAll(quotes); Collection<Quote> polled = win.pollEvictedBatch(); if (!polled.isEmpty()) { Map<String, Bar> map = new HashMap<>(); for (Quote quote : polled) { String symbol = quote.symbol(); Bar bar = map.get(symbol); if (bar == null) map.put(symbol, bar = new Bar(symbol)); bar.update(quote.price()); } return Collections.<String, Collection<?>>singletonMap(ctx.nextStageName(), map.values()); } return null; }