@Override public void processTuple(Tuple tuple) { try { T reduceValue = reduceList.get(slideInWindow); T value = (T) tuple.getValue(0); if (null == reduceValue) reduceList.set(slideInWindow, value); else { reduceList.set(slideInWindow, fun.reduce(reduceValue, value)); } } catch (Exception e) { logger.error(e.toString()); } }
@Override public void processSlide(BasicOutputCollector collector) { try { T reduceValue = null; // TODO: implement window data structure with tree, no need to for loop for (T t : reduceList) { if (null == reduceValue) { reduceValue = t; } else { reduceValue = fun.reduce(reduceValue, t); } } collector.emit(new Values(slideIndexInBuffer, reduceValue)); // clear data reduceList.set((slideInWindow + 1) % WINDOW_SIZE, null); } catch (Exception e) { logger.error(e.toString()); } }