/** * Returns a stream of aggregated results based on the given window configuration which uses inmemory windowing tuple store. * * @param windowConfig window configuration like window length and slide length. * @param inputFields input fields * @param aggregator aggregator to run on the window of tuples to compute the result and emit to the stream. * @param functionFields fields of values to emit with aggregation. * @return the new stream with this operation. */ public Stream window(WindowConfig windowConfig, Fields inputFields, Aggregator aggregator, Fields functionFields) { // this store is used only for storing triggered aggregated results but not tuples as storeTuplesInStore is set // as false int he below call. InMemoryWindowsStoreFactory inMemoryWindowsStoreFactory = new InMemoryWindowsStoreFactory(); return window(windowConfig, inMemoryWindowsStoreFactory, inputFields, aggregator, functionFields, false); }
public static void main(String[] args) throws Exception { Config conf = new Config(); WindowsStoreFactory mapState = new InMemoryWindowsStoreFactory(); String topoName = "wordCounter"; if (args.length > 0) { topoName = args[0]; } conf.setNumWorkers(3); StormSubmitter.submitTopologyWithProgressBar(topoName, conf, buildTopology(mapState, SlidingCountWindow.of(1000, 100))); } }
@Override public TridentTopology createTopology() { ITridentDataSource source = KafkaSpoutFactory.getTridentSpout(config, true); TridentTopology topology = new TridentTopology(); topology.newStream("kafka", source) .each(new Fields("str"), new Parser(), new Fields("ip", "time")) .project(new Fields("ip", "time")) .parallelismHint(config.spoutThreads) .groupBy(new Fields("ip")).toStream() .slidingWindow(new BaseWindowedBolt.Duration((int) config.windowDuration, TimeUnit.MILLISECONDS), new BaseWindowedBolt.Duration((int) config.windowSlideStep, TimeUnit.MILLISECONDS), new InMemoryWindowsStoreFactory(), new Fields("ip", "time"), new Count(config), new Fields("ip", "count")) .parallelismHint(config.boltThreads); return topology; }
/** * Returns a stream of aggregated results based on the given window configuration which uses inmemory windowing tuple store. * * @param windowConfig window configuration like window length and slide length. * @param inputFields input fields * @param aggregator aggregator to run on the window of tuples to compute the result and emit to the stream. * @param functionFields fields of values to emit with aggregation. * * @return the new stream with this operation. */ public Stream window(WindowConfig windowConfig, Fields inputFields, Aggregator aggregator, Fields functionFields) { // this store is used only for storing triggered aggregated results but not tuples as storeTuplesInStore is set // as false int he below call. InMemoryWindowsStoreFactory inMemoryWindowsStoreFactory = new InMemoryWindowsStoreFactory(); return window(windowConfig, inMemoryWindowsStoreFactory, inputFields, aggregator, functionFields, false); }