@ProcessElement public void processElement( ProcessContext context, @StateId("counter") ValueState<Integer> counterState) { int current = (counterState.read() != null ? counterState.read() : 0); if (current < limitCount) { context.output(context.element().getValue()); counterState.write(current + 1); } } }
@OnTimer(timerId) public void onTimer(OnTimerContext context, @StateId(stateId) ValueState<String> state) { context.output(KV.of(state.read(), timerOutput)); } };
@OnTimer(timerId) public void onTimer(OnTimerContext context, @StateId(stateId) ValueState<String> state) { context.output(KV.of(state.read(), timerOutput)); } };
@OnTimer(timerId) public void onTimer( @StateId(stateId) ValueState<String> state, OutputReceiver<KV<String, Integer>> r) { r.output(KV.of(state.read(), timerOutput)); } };
@ProcessElement public void processElement(ProcessContext c, @StateId(stateId) ValueState<Integer> state) { Integer currentValue = MoreObjects.firstNonNull(state.read(), 0); state.write(currentValue + 1); } }
@OnTimer(timerId) public void onTimer(OnTimerContext context, @StateId(stateId) ValueState<String> state) { context.output(KV.of(state.read(), timerOutput)); } };
@ProcessElement public void processElement(@StateId(NEXT_ID) ValueState<Long> nextIdState, ProcessContext ctx) { long nextId = MoreObjects.firstNonNull(nextIdState.read(), 0L); int shard = ctx.element().getKey(); for (TimestampedValue<KV<K, V>> value : ctx.element().getValue()) { ctx.output(KV.of(shard, KV.of(nextId, value))); nextId++; } nextIdState.write(nextId); } }
@ProcessElement public void processElement(ProcessContext c, @StateId(stateId) ValueState<Integer> state) { Integer currentValue = MoreObjects.firstNonNull(state.read(), 0); c.output(currentValue); state.write(currentValue + 1); } };
@OnTimer(timerId) public void onTimer( @StateId(stateId) ValueState<String> state, OutputReceiver<KV<String, Integer>> r) { r.output(KV.of(state.read(), timerOutput)); } };
@ProcessElement public void processElement( @StateId(stateId) ValueState<Integer> state, OutputReceiver<Integer> r) { Integer currentValue = MoreObjects.firstNonNull(state.read(), 0); r.output(currentValue); state.write(currentValue + 1); } };
@ProcessElement public void processElement( @StateId(stateId) ValueState<Integer> state, OutputReceiver<Integer> r) { Integer currentValue = MoreObjects.firstNonNull(state.read(), 0); r.output(currentValue); state.write(currentValue + 1); } };
@ProcessElement public void processElement(@StateId(NEXT_ID) ValueState<Long> nextIdState, ProcessContext ctx) { long nextId = MoreObjects.firstNonNull(nextIdState.read(), 0L); int shard = ctx.element().getKey(); for (TimestampedValue<KV<K, V>> value : ctx.element().getValue()) { ctx.output(KV.of(shard, KV.of(nextId, value))); nextId++; } nextIdState.write(nextId); } }
@ProcessElement public void processElement( @StateId(stateId) ValueState<Integer> state, OutputReceiver<Integer> r) { Integer currentValue = MoreObjects.firstNonNull(state.read(), 13); r.output(currentValue); state.write(currentValue + 13); } };
public MergingActiveWindowSet(WindowFn<Object, W> windowFn, StateInternals state) { this.windowFn = windowFn; StateTag<ValueState<Map<W, Set<W>>>> tag = StateTags.makeSystemTagInternal( StateTags.value( "tree", MapCoder.of(windowFn.windowCoder(), SetCoder.of(windowFn.windowCoder())))); valueState = state.state(StateNamespaces.global(), tag); // Little use trying to prefetch this state since the ReduceFnRunner // is stymied until it is available. activeWindowToStateAddressWindows = emptyIfNull(valueState.read()); originalActiveWindowToStateAddressWindows = deepCopy(activeWindowToStateAddressWindows); }
@ProcessElement public void processElement( @Element KV<Integer, Integer> element, @StateId(stateId) ValueState<Integer> seenState, OutputReceiver<Integer> r) { Integer seen = MoreObjects.firstNonNull(seenState.read(), 0); if (seen == 0) { seenState.write(seen + 1); r.output(element.getValue()); } } };
@ProcessElement public void processElement( @StateId(stateId) ValueState<Integer> state, OutputReceiver<KV<String, Integer>> r) { Integer currentValue = MoreObjects.firstNonNull(state.read(), 0); r.output(KV.of("sizzle", currentValue)); state.write(currentValue + 1); } };
@ProcessElement public void processElement( @StateId(stateId) ValueState<Integer> state, MultiOutputReceiver r) { Integer currentValue = MoreObjects.firstNonNull(state.read(), 0); if (currentValue % 2 == 0) { r.get(evenTag).output(currentValue); } else { r.get(oddTag).output(currentValue); } state.write(currentValue + 1); } };
@ProcessElement public void processElement( ProcessContext c, @StateId(stateId) ValueState<MyInteger> state, OutputReceiver<MyInteger> r) { MyInteger currentValue = MoreObjects.firstNonNull(state.read(), new MyInteger(0)); r.output(currentValue); state.write(new MyInteger(currentValue.getValue() + 1)); } };
@ProcessElement public void processElement( @StateId(stateId) ValueState<MyInteger> state, OutputReceiver<MyInteger> r) { MyInteger currentValue = MoreObjects.firstNonNull(state.read(), new MyInteger(0)); r.output(currentValue); state.write(new MyInteger(currentValue.getValue() + 1)); } };
@ProcessElement public void processElement( @StateId(stateId) ValueState<MyInteger> state, OutputReceiver<MyInteger> r) { MyInteger currentValue = MoreObjects.firstNonNull(state.read(), new MyInteger(0)); r.output(currentValue); state.write(new MyInteger(currentValue.getValue() + 1)); } };