List of usage examples for org.joda.time Instant isEqual
public boolean isEqual(long instant)
From source file:com.google.cloud.dataflow.sdk.util.ReduceFnRunner.java
License:Apache License
/** * Run the {@link ReduceFn#onTrigger} method and produce any necessary output. * * @return output watermark hold added, or {@literal null} if none. *//*from w ww .ja v a2 s . co m*/ @Nullable private Instant onTrigger(final ReduceFn<K, InputT, OutputT, W>.Context directContext, ReduceFn<K, InputT, OutputT, W>.Context renamedContext, boolean isFinished, boolean isEndOfWindow) throws Exception { Instant inputWM = timerInternals.currentInputWatermarkTime(); // Prefetch necessary states ReadableState<WatermarkHold.OldAndNewHolds> outputTimestampFuture = watermarkHold .extractAndRelease(renamedContext, isFinished).readLater(); ReadableState<PaneInfo> paneFuture = paneInfoTracker.getNextPaneInfo(directContext, isFinished).readLater(); ReadableState<Boolean> isEmptyFuture = nonEmptyPanes.isEmpty(renamedContext.state()).readLater(); reduceFn.prefetchOnTrigger(directContext.state()); triggerRunner.prefetchOnFire(directContext.window(), directContext.state()); // Calculate the pane info. final PaneInfo pane = paneFuture.read(); // Extract the window hold, and as a side effect clear it. WatermarkHold.OldAndNewHolds pair = outputTimestampFuture.read(); final Instant outputTimestamp = pair.oldHold; @Nullable Instant newHold = pair.newHold; if (newHold != null) { // We can't be finished yet. Preconditions.checkState(!isFinished, "new hold at %s but finished %s", newHold, directContext.window()); // The hold cannot be behind the input watermark. Preconditions.checkState(!newHold.isBefore(inputWM), "new hold %s is before input watermark %s", newHold, inputWM); if (newHold.isAfter(directContext.window().maxTimestamp())) { // The hold must be for garbage collection, which can't have happened yet. Preconditions.checkState(newHold.isEqual(garbageCollectionTime(directContext.window())), "new hold %s should be at garbage collection for window %s plus %s", newHold, directContext.window(), windowingStrategy.getAllowedLateness()); } else { // The hold must be for the end-of-window, which can't have happened yet. Preconditions.checkState(newHold.isEqual(directContext.window().maxTimestamp()), "new hold %s should be at end of window %s", newHold, directContext.window()); Preconditions.checkState(!isEndOfWindow, "new hold at %s for %s but this is the watermark trigger", newHold, directContext.window()); } } // Only emit a pane if it has data or empty panes are observable. if (needToEmit(isEmptyFuture.read(), isFinished, pane.getTiming())) { // Run reduceFn.onTrigger method. final List<W> windows = Collections.singletonList(directContext.window()); ReduceFn<K, InputT, OutputT, W>.OnTriggerContext renamedTriggerContext = contextFactory.forTrigger( directContext.window(), paneFuture, StateStyle.RENAMED, new OnTriggerCallbacks<OutputT>() { @Override public void output(OutputT toOutput) { // We're going to output panes, so commit the (now used) PaneInfo. // TODO: This is unnecessary if the trigger isFinished since the saved // state will be immediately deleted. paneInfoTracker.storeCurrentPaneInfo(directContext, pane); // Output the actual value. outputter.outputWindowedValue(KV.of(key, toOutput), outputTimestamp, windows, pane); } }); reduceFn.onTrigger(renamedTriggerContext); } return newHold; }
From source file:org.apache.beam.runners.core.ReduceFnRunner.java
License:Apache License
/** * Run the {@link ReduceFn#onTrigger} method and produce any necessary output. * * @return output watermark hold added, or {@literal null} if none. *///w ww .j a v a 2 s.co m @Nullable private Instant onTrigger(final ReduceFn<K, InputT, OutputT, W>.Context directContext, ReduceFn<K, InputT, OutputT, W>.Context renamedContext, final boolean isFinished, boolean isEndOfWindow) throws Exception { // Extract the window hold, and as a side effect clear it. final WatermarkHold.OldAndNewHolds pair = watermarkHold.extractAndRelease(renamedContext, isFinished) .read(); // TODO: This isn't accurate if the elements are late. See BEAM-2262 final Instant outputTimestamp = pair.oldHold; @Nullable Instant newHold = pair.newHold; final boolean isEmpty = nonEmptyPanes.isEmpty(renamedContext.state()).read(); if (isEmpty && windowingStrategy.getClosingBehavior() == ClosingBehavior.FIRE_IF_NON_EMPTY && windowingStrategy.getOnTimeBehavior() == Window.OnTimeBehavior.FIRE_IF_NON_EMPTY) { return newHold; } Instant inputWM = timerInternals.currentInputWatermarkTime(); if (newHold != null) { // We can't be finished yet. checkState(!isFinished, "new hold at %s but finished %s", newHold, directContext.window()); // The hold cannot be behind the input watermark. checkState(!newHold.isBefore(inputWM), "new hold %s is before input watermark %s", newHold, inputWM); if (newHold.isAfter(directContext.window().maxTimestamp())) { // The hold must be for garbage collection, which can't have happened yet. checkState( newHold.isEqual( LateDataUtils.garbageCollectionTime(directContext.window(), windowingStrategy)), "new hold %s should be at garbage collection for window %s plus %s", newHold, directContext.window(), windowingStrategy.getAllowedLateness()); } else { // The hold must be for the end-of-window, which can't have happened yet. checkState(newHold.isEqual(directContext.window().maxTimestamp()), "new hold %s should be at end of window %s", newHold, directContext.window()); checkState(!isEndOfWindow, "new hold at %s for %s but this is the watermark trigger", newHold, directContext.window()); } } // Calculate the pane info. final PaneInfo pane = paneInfoTracker.getNextPaneInfo(directContext, isFinished).read(); // Only emit a pane if it has data or empty panes are observable. if (needToEmit(isEmpty, isFinished, pane.getTiming())) { // Run reduceFn.onTrigger method. final List<W> windows = Collections.singletonList(directContext.window()); ReduceFn<K, InputT, OutputT, W>.OnTriggerContext renamedTriggerContext = contextFactory .forTrigger(directContext.window(), pane, StateStyle.RENAMED, toOutput -> { // We're going to output panes, so commit the (now used) PaneInfo. // This is unnecessary if the trigger isFinished since the saved // state will be immediately deleted. if (!isFinished) { paneInfoTracker.storeCurrentPaneInfo(directContext, pane); } // Output the actual value. outputter.outputWindowedValue(KV.of(key, toOutput), outputTimestamp, windows, pane); }); reduceFn.onTrigger(renamedTriggerContext); } return newHold; }
From source file:org.joda.example.time.Examples.java
License:Apache License
private void runInstant() { System.out.println("Instant"); System.out.println("======="); System.out//from w w w . j av a2 s .com .println("Instant stores a point in the datetime continuum as millisecs from 1970-01-01T00:00:00Z"); System.out.println("Instant is immutable and thread-safe"); System.out.println(" in = new Instant()"); Instant in = new Instant(); System.out.println("Millisecond time: in.getMillis(): " + in.getMillis()); System.out.println("ISO string version: in.toString(): " + in.toString()); System.out.println("ISO chronology: in.getChronology(): " + in.getChronology()); System.out.println("UTC time zone: in.getDateTimeZone(): " + in.getZone()); System.out.println("Change millis: in.withMillis(0): " + in.withMillis(0L)); System.out.println(""); System.out.println("Convert to Instant: in.toInstant(): " + in.toInstant()); System.out.println("Convert to DateTime: in.toDateTime(): " + in.toDateTime()); System.out.println("Convert to MutableDT: in.toMutableDateTime(): " + in.toMutableDateTime()); System.out.println("Convert to Date: in.toDate(): " + in.toDate()); System.out.println(""); System.out.println(" in2 = new Instant(in.getMillis() + 10)"); Instant in2 = new Instant(in.getMillis() + 10); System.out.println("Equals ms and chrono: in.equals(in2): " + in.equals(in2)); System.out.println("Compare millisecond: in.compareTo(in2): " + in.compareTo(in2)); System.out.println("Compare millisecond: in.isEqual(in2): " + in.isEqual(in2)); System.out.println("Compare millisecond: in.isAfter(in2): " + in.isAfter(in2)); System.out.println("Compare millisecond: in.isBefore(in2): " + in.isBefore(in2)); }