public void start() { timerService.registerTimer(timerService.getCurrentProcessingTime() + interval, this); }
private void scheduleNextIdleDetectionTask() { if (idleTimeout != -1) { // reset flag; if it remains true when task fires, we have detected idleness failOnNextCheck = true; nextCheck = this.timeService.registerTimer( this.timeService.getCurrentProcessingTime() + idleTimeout, new IdlenessDetectionTask()); } }
@Override public void onProcessingTime(long timestamp) throws Exception { final long currentTime = processingTimeService.getCurrentProcessingTime(); buckets.onProcessingTime(currentTime); processingTimeService.registerTimer(currentTime + bucketCheckInterval, this); }
@Override public void onProcessingTime(long timestamp) throws Exception { long currentProcessingTime = processingTimeService.getCurrentProcessingTime(); closePartFilesByTime(currentProcessingTime); processingTimeService.registerTimer(currentProcessingTime + inactiveBucketCheckInterval, this); }
@Override protected void init() throws Exception { getProcessingTimeService().registerTimer(0, new ProcessingTimeCallback() { @Override public void onProcessingTime(long timestamp) throws Exception { classLoaders.add(Thread.currentThread().getContextClassLoader()); syncLatch.trigger(); } }); }
@Override public void processElement(StreamRecord<String> element) throws Exception { if (!semaphore.tryAcquire()) { Assert.fail("Concurrent invocation of operator functions."); } if (first) { getProcessingTimeService().registerTimer(System.currentTimeMillis() + 100, this); first = false; } numElements++; semaphore.release(); }
@Override public void processElement2(StreamRecord<String> element) throws Exception { if (!semaphore.tryAcquire()) { Assert.fail("Concurrent invocation of operator functions."); } if (first) { getProcessingTimeService().registerTimer(System.currentTimeMillis() + 100, this); first = false; } numElements++; semaphore.release(); }
@Override public void registerProcessingTimeTimer(N namespace, long time) { InternalTimer<K, N> oldHead = processingTimeTimersQueue.peek(); if (processingTimeTimersQueue.add(new TimerHeapInternalTimer<>(time, (K) keyContext.getCurrentKey(), namespace))) { long nextTriggerTime = oldHead != null ? oldHead.getTimestamp() : Long.MAX_VALUE; // check if we need to re-schedule our timer to earlier if (time < nextTriggerTime) { if (nextTimer != null) { nextTimer.cancel(false); } nextTimer = processingTimeService.registerTimer(time, this); } } }
@Override public void processElement1(StreamRecord<String> element) throws Exception { if (!semaphore.tryAcquire()) { Assert.fail("Concurrent invocation of operator functions."); } if (first) { getProcessingTimeService().registerTimer(System.currentTimeMillis() + 100, this); first = false; } numElements++; semaphore.release(); }
@Override public void open(Configuration parameters) throws Exception { super.open(parameters); this.processingTimeService = ((StreamingRuntimeContext) getRuntimeContext()).getProcessingTimeService(); long currentProcessingTime = processingTimeService.getCurrentProcessingTime(); processingTimeService.registerTimer(currentProcessingTime + bucketCheckInterval, this); }
@Override public void onProcessingTime(long time) throws Exception { if (!semaphore.tryAcquire()) { Assert.fail("Concurrent invocation of operator functions."); } try { numTimers++; throwIfDone(); getProcessingTimeService().registerTimer(System.currentTimeMillis() + 1, this); } finally { semaphore.release(); } }
@Override public void onProcessingTime(long time) throws Exception { if (!semaphore.tryAcquire()) { Assert.fail("Concurrent invocation of operator functions."); } try { numTimers++; throwIfDone(); getProcessingTimeService().registerTimer(System.currentTimeMillis() + 1, this); } finally { semaphore.release(); } }
@Override public void open(Configuration parameters) throws Exception { super.open(parameters); state = new State<>(); processingTimeService = ((StreamingRuntimeContext) getRuntimeContext()).getProcessingTimeService(); long currentProcessingTime = processingTimeService.getCurrentProcessingTime(); processingTimeService.registerTimer(currentProcessingTime + inactiveBucketCheckInterval, this); this.clock = new Clock() { @Override public long currentTimeMillis() { return processingTimeService.getCurrentProcessingTime(); } }; }
@Override public void open() throws Exception { super.open(); currentWatermark = Long.MIN_VALUE; watermarkInterval = getExecutionConfig().getAutoWatermarkInterval(); if (watermarkInterval > 0) { long now = getProcessingTimeService().getCurrentProcessingTime(); getProcessingTimeService().registerTimer(now + watermarkInterval, this); } }
@Override public void onProcessingTime(long timestamp) throws Exception { // register next timer long newWatermark = userFunction.getCurrentWatermark(); if (newWatermark > currentWatermark) { currentWatermark = newWatermark; // emit watermark output.emitWatermark(new Watermark(currentWatermark)); } long now = getProcessingTimeService().getCurrentProcessingTime(); getProcessingTimeService().registerTimer(now + watermarkInterval, this); }
@Override public void open() throws Exception { super.open(); watermarkInterval = getExecutionConfig().getAutoWatermarkInterval(); if (watermarkInterval > 0) { long now = getProcessingTimeService().getCurrentProcessingTime(); getProcessingTimeService().registerTimer(now + watermarkInterval, this); } currentWatermark = Long.MIN_VALUE; }
private AutomaticWatermarkContext( final Output<StreamRecord<T>> output, final long watermarkInterval, final ProcessingTimeService timeService, final Object checkpointLock, final StreamStatusMaintainer streamStatusMaintainer, final long idleTimeout) { super(timeService, checkpointLock, streamStatusMaintainer, idleTimeout); this.output = Preconditions.checkNotNull(output, "The output cannot be null."); Preconditions.checkArgument(watermarkInterval >= 1L, "The watermark interval cannot be smaller than 1 ms."); this.watermarkInterval = watermarkInterval; this.reuse = new StreamRecord<>(null); this.lastRecordTime = Long.MIN_VALUE; long now = this.timeService.getCurrentProcessingTime(); this.nextWatermarkTimer = this.timeService.registerTimer(now + watermarkInterval, new WatermarkEmittingTask(this.timeService, checkpointLock, output)); }
@Override public void onProcessingTime(long timestamp) throws Exception { // register next timer Watermark newWatermark = userFunction.getCurrentWatermark(); if (newWatermark != null && newWatermark.getTimestamp() > currentWatermark) { currentWatermark = newWatermark.getTimestamp(); // emit watermark output.emitWatermark(newWatermark); } long now = getProcessingTimeService().getCurrentProcessingTime(); getProcessingTimeService().registerTimer(now + watermarkInterval, this); }
@Test public void testExceptionReporting() throws InterruptedException { final AtomicBoolean exceptionWasThrown = new AtomicBoolean(false); final OneShotLatch latch = new OneShotLatch(); final Object lock = new Object(); ProcessingTimeService timeServiceProvider = new SystemProcessingTimeService( new AsyncExceptionHandler() { @Override public void handleAsyncException(String message, Throwable exception) { exceptionWasThrown.set(true); latch.trigger(); } }, lock); timeServiceProvider.registerTimer(System.currentTimeMillis(), new ProcessingTimeCallback() { @Override public void onProcessingTime(long timestamp) throws Exception { throw new Exception("Exception in Timer"); } }); latch.await(); assertTrue(exceptionWasThrown.get()); }
@Override public void onProcessingTime(long time) throws Exception { // null out the timer in case the Triggerable calls registerProcessingTimeTimer() // inside the callback. nextTimer = null; InternalTimer<K, N> timer; while ((timer = processingTimeTimersQueue.peek()) != null && timer.getTimestamp() <= time) { processingTimeTimersQueue.poll(); keyContext.setCurrentKey(timer.getKey()); triggerTarget.onProcessingTime(timer); } if (timer != null && nextTimer == null) { nextTimer = processingTimeService.registerTimer(timer.getTimestamp(), this); } }