@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); } } }
@ProcessElement public void processElement(ProcessContext c, @StateId(stateId) ValueState<Integer> state) { Integer currentValue = MoreObjects.firstNonNull(state.read(), 0); 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( ProcessContext context, @StateId("counter") ValueState<Long> count) { long currentCount = Optional.ofNullable(count.read()).orElse(0L); currentCount = currentCount + 1; count.write(currentCount); KV<String, Long> currentElement = context.element(); if (currentCount == currentElement.getValue()) { context.output(currentElement); } } };
@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); } };
@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); } };
@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)); } };
@ProcessElement public void processElement( ProcessContext context, @TimerId(timerId) Timer timer, @StateId(stateId) ValueState<String> state, BoundedWindow window) { timer.set(window.maxTimestamp()); state.write(context.element().getKey()); context.output( KV.of(context.element().getKey(), context.element().getValue() + offset)); }
@ProcessElement public void processElement( ProcessContext context, @TimerId(timerId) Timer timer, @StateId(stateId) ValueState<String> state, BoundedWindow window) { timer.set(window.maxTimestamp()); state.write(context.element().getKey()); context.output( KV.of(context.element().getKey(), context.element().getValue() + offset)); }
@ProcessElement public void processElement( ProcessContext context, @TimerId(timerId) Timer timer, @StateId(stateId) ValueState<String> state, BoundedWindow window) { timer.set(window.maxTimestamp()); state.write(context.element().getKey()); context.output( KV.of(context.element().getKey(), context.element().getValue() + offset)); }
@ProcessElement public void processElement( ProcessContext context, @TimerId(timerId) Timer timer, @StateId(stateId) ValueState<String> state, BoundedWindow window) { timer.set(window.maxTimestamp()); state.write(context.element().getKey()); context.output( KV.of(context.element().getKey(), context.element().getValue() + offset)); }
@ProcessElement public void processElement( ProcessContext context, @TimerId(timerId) Timer timer, @StateId(stateId) ValueState<String> state, BoundedWindow window) { timer.set(window.maxTimestamp()); state.write(context.element().getKey()); context.output( KV.of(context.element().getKey(), context.element().getValue() + offset)); }