List of usage examples for org.joda.time Instant plus
public Instant plus(ReadableDuration duration)
From source file:com.auth10.federation.SamlTokenValidator.java
License:Open Source License
private boolean validateExpiration(Instant notBefore, Instant notOnOrAfter) { Instant now = new Instant(); Duration skew = new Duration(MAX_CLOCK_SKEW_IN_MINUTES * 60 * 1000); if (now.plus(skew).isBefore(notBefore)) { return true; }// ww w .j a v a2 s. c o m if (now.minus(skew).isAfter(notOnOrAfter)) { return true; } return false; }
From source file:com.google.cloud.dataflow.examples.opinionanalysis.StatsCalcPipelineUtils.java
License:Apache License
private static String[] buildDailyStatsCalcQueries(String[] statsCalcDays, String sFromDate, String sToDate, String bigQueryDataset, StatsQueryGenerator gen) throws Exception { ArrayList<String> querySequenceList = new ArrayList<String>(); String query;//from w w w. j a v a 2s . com if (statsCalcDays != null) { String timeMarkerList = StatsCalcPipelineUtils.buildTimeMarkerList(statsCalcDays); // DELETE the previous snapshots, if they exist, in one DELETE operation, to save resources query = buildDeleteByTimeMarkerQuery(timeMarkerList, bigQueryDataset, gen); querySequenceList.add(query); // Create INSERT operations for all days individually for (int i = 0; i < statsCalcDays.length; i++) { String daylabel = statsCalcDays[i]; // Insert the records of the new daily snapshot query = buildInsertByTimeMarkerQuery(daylabel, bigQueryDataset, gen); querySequenceList.add(query); } } else if (sFromDate != null) { Long lFromDate = IndexerPipelineUtils.parseDateToLong(sFromDate); Instant fromDate = new Instant(lFromDate); Long lToDate = null; if (sToDate != null) lToDate = IndexerPipelineUtils.parseDateToLong(sToDate); Instant toDate = null; if (lToDate != null) toDate = new Instant(lToDate); else toDate = Instant.now(); ArrayList<Integer> snapshotDateIds = new ArrayList<Integer>(); Instant t = fromDate; while (t.getMillis() <= toDate.getMillis()) { Integer dateId = IndexerPipelineUtils.getDateIdFromTimestamp(t.getMillis()); snapshotDateIds.add(dateId); t = t.plus(24L * 3600L * 1000L); //add one day } // Add the DELETE statement for previous snapshots in the range Integer[] snapshotIdArray = new Integer[(snapshotDateIds.size())]; snapshotDateIds.toArray(snapshotIdArray); String snapshotIdList = buildIntegerList(snapshotIdArray); query = buildDeleteByDateIdQuery(snapshotIdList, bigQueryDataset, gen); querySequenceList.add(query); for (int i = 0; i < snapshotDateIds.size(); i++) { Integer dateId = snapshotDateIds.get(i); // Add the INSERTs for new daily snapshot query = buildInsertByDateIdQuery(dateId, bigQueryDataset, gen); querySequenceList.add(query); } } else { throw new Exception("Unsufficient time parameters to calculate stats."); } String[] querySequence = new String[querySequenceList.size()]; querySequenceList.toArray(querySequence); return querySequence; }
From source file:com.google.cloud.dataflow.sdk.transforms.windowing.FixedWindows.java
License:Apache License
@Override public IntervalWindow assignWindow(Instant timestamp) { long start = timestamp.getMillis() - timestamp.plus(size).minus(offset).getMillis() % size.getMillis(); return new IntervalWindow(new Instant(start), size); }
From source file:com.google.cloud.dataflow.sdk.transforms.windowing.IntervalWindow.java
License:Apache License
public IntervalWindow(Instant start, ReadableDuration size) { this.start = start; this.end = start.plus(size); }
From source file:com.google.cloud.dataflow.sdk.transforms.windowing.SlidingWindows.java
License:Apache License
/** * Return the last start of a sliding window that contains the timestamp. *///w w w . ja va 2s . com private long lastStartFor(Instant timestamp) { return timestamp.getMillis() - timestamp.plus(period).minus(offset).getMillis() % period.getMillis(); }
From source file:com.google.cloud.dataflow.sdk.transforms.windowing.SlidingWindows.java
License:Apache License
/** * Ensures that later sliding windows have an output time that is past the end of earlier windows. * * <p>If this is the earliest sliding window containing {@code inputTimestamp}, that's fine. * Otherwise, we pick the earliest time that doesn't overlap with earlier windows. *//* w w w . j ava2 s . c o m*/ @Experimental(Kind.OUTPUT_TIME) @Override public OutputTimeFn<? super IntervalWindow> getOutputTimeFn() { return new OutputTimeFn.Defaults<BoundedWindow>() { @Override public Instant assignOutputTime(Instant inputTimestamp, BoundedWindow window) { Instant startOfLastSegment = window.maxTimestamp().minus(period); return startOfLastSegment.isBefore(inputTimestamp) ? inputTimestamp : startOfLastSegment.plus(1); } @Override public boolean dependsOnlyOnEarliestInputTimestamp() { return true; } }; }
From source file:com.google.cloud.dataflow.sdk.transforms.windowing.TimeTrigger.java
License:Apache License
/** * Adds some delay to the original target time. * * @param delay the delay to add/*from ww w . jav a 2 s . c o m*/ * @return An updated time trigger that will wait the additional time before firing. */ public T plusDelayOf(final Duration delay) { return newWith(new SerializableFunction<Instant, Instant>() { private static final long serialVersionUID = 0L; @Override public Instant apply(Instant input) { return input.plus(delay); } }); }
From source file:com.google.cloud.dataflow.sdk.transforms.windowing.TimeTrigger.java
License:Apache License
@VisibleForTesting static Instant alignedTo(Instant point, Duration size, Instant offset) { long millisSinceStart = new Duration(offset, point).getMillis() % size.getMillis(); return millisSinceStart == 0 ? point : point.plus(size).minus(millisSinceStart); }
From source file:com.google.cloud.dataflow.sdk.util.GroupAlsoByWindowsProperties.java
License:Apache License
/** * Tests that for a simple sequence of elements on the same key, the given GABW implementation * correctly groups them according to fixed windows and also sets the output timestamp * according to a custom {@link OutputTimeFn}. *//*from ww w . j a va 2s . co m*/ public static void groupsElementsIntoFixedWindowsWithCustomTimestamp( GroupAlsoByWindowsDoFnFactory<String, String, Iterable<String>> gabwFactory) throws Exception { WindowingStrategy<?, IntervalWindow> windowingStrategy = WindowingStrategy .of(FixedWindows.of(Duration.millis(10))) .withOutputTimeFn(new OutputTimeFn.Defaults<IntervalWindow>() { @Override public Instant assignOutputTime(Instant inputTimestamp, IntervalWindow window) { return inputTimestamp.isBefore(window.maxTimestamp()) ? inputTimestamp.plus(1) : window.maxTimestamp(); } @Override public Instant combine(Instant outputTime, Instant otherOutputTime) { return outputTime.isBefore(otherOutputTime) ? outputTime : otherOutputTime; } @Override public boolean dependsOnlyOnEarliestInputTimestamp() { return true; } }); List<WindowedValue<KV<String, Iterable<String>>>> result = runGABW(gabwFactory, windowingStrategy, "key", WindowedValue.of("v1", new Instant(1), Arrays.asList(window(0, 10)), PaneInfo.NO_FIRING), WindowedValue.of("v2", new Instant(2), Arrays.asList(window(0, 10)), PaneInfo.NO_FIRING), WindowedValue.of("v3", new Instant(13), Arrays.asList(window(10, 20)), PaneInfo.NO_FIRING)); assertThat(result.size(), equalTo(2)); assertThat(result, containsInAnyOrder(gabwResult(window(0, 10), new Instant(2), "v1", "v2"), gabwResult(window(10, 20), new Instant(14), "v3"))); }
From source file:com.google.cloud.dataflow.sdk.util.ReduceFnRunner.java
License:Apache License
/** * Return when {@code window} should be garbage collected. If the window is the GlobalWindow, * that will be the end of the window. Otherwise, add the allowed lateness to the end of * the window./*from w w w . ja v a2s. com*/ */ private Instant garbageCollectionTime(W window) { Instant maxTimestamp = window.maxTimestamp(); if (maxTimestamp.isBefore(GlobalWindow.INSTANCE.maxTimestamp())) { return maxTimestamp.plus(windowingStrategy.getAllowedLateness()); } else { return maxTimestamp; } }