@Override public <OutputT> FnDataReceiver<OutputT> create(String pCollectionId) { final ProcessBundleDescriptors.TimerSpec timerSpec = timerOutputIdToSpecMap.get(pCollectionId); return receivedElement -> { WindowedValue windowedValue = (WindowedValue) receivedElement; Timer timer = Preconditions.checkNotNull( (Timer) ((KV) windowedValue.getValue()).getValue(), "Received null Timer from SDK harness: %s", receivedElement); LOG.debug("Timer received: {} {}", pCollectionId, timer); for (Object window : windowedValue.getWindows()) { StateNamespace namespace = StateNamespaces.window(windowCoder, (BoundedWindow) window); TimeDomain timeDomain = timerSpec.getTimerSpec().getTimeDomain(); String timerId = timerSpec.inputCollectionId(); TimerInternals.TimerData timerData = TimerInternals.TimerData.of(timerId, namespace, timer.getTimestamp(), timeDomain); timerDataConsumer.accept(windowedValue, timerData); } }; } }
@Override public <OutputT> FnDataReceiver<OutputT> create(String pCollectionId) { final ProcessBundleDescriptors.TimerSpec timerSpec = timerOutputIdToSpecMap.get(pCollectionId); return receivedElement -> { WindowedValue windowedValue = (WindowedValue) receivedElement; Timer timer = Preconditions.checkNotNull( (Timer) ((KV) windowedValue.getValue()).getValue(), "Received null Timer from SDK harness: %s", receivedElement); LOG.debug("Timer received: {} {}", pCollectionId, timer); for (Object window : windowedValue.getWindows()) { StateNamespace namespace = StateNamespaces.window(windowCoder, (BoundedWindow) window); TimeDomain timeDomain = timerSpec.getTimerSpec().getTimeDomain(); String timerId = timerSpec.inputCollectionId(); TimerInternals.TimerData timerData = TimerInternals.TimerData.of(timerId, namespace, timer.getTimestamp(), timeDomain); timerDataConsumer.accept(windowedValue, timerData); } }; } }
public static RunnerApi.TimerSpec translateTimerSpec(TimerSpec timer, SdkComponents components) { return RunnerApi.TimerSpec.newBuilder() .setTimeDomain(translateTimeDomain(timer.getTimeDomain())) // TODO: Add support for timer payloads to the SDK // We currently assume that all payloads are unspecified. .setTimerCoderId(registerCoderOrThrow(components, Timer.Coder.of(VoidCoder.of()))) .build(); }
namespace, timer.getTimestamp(), timerSpec.getTimerSpec().getTimeDomain()); timerRegistration.accept(windowedValue, timerData);
namespace, timer.getTimestamp(), timerSpec.getTimerSpec().getTimeDomain()); setTimer(windowedValue, timerData);