當前位置: 首頁>>代碼示例>>Java>>正文


Java Instant.isBefore方法代碼示例

本文整理匯總了Java中org.joda.time.Instant.isBefore方法的典型用法代碼示例。如果您正苦於以下問題:Java Instant.isBefore方法的具體用法?Java Instant.isBefore怎麽用?Java Instant.isBefore使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.joda.time.Instant的用法示例。


在下文中一共展示了Instant.isBefore方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: retireBids

import org.joda.time.Instant; //導入方法依賴的package包/類
/**
 * Retire bids which are strictly before {@code cutoff}. Return true if there are any bids
 * remaining.
 */
private boolean retireBids(Instant cutoff) {
  boolean anyRemain = false;
  for (Map.Entry<Long, List<Instant>> entry : bids.entrySet()) {
    long auction = entry.getKey();
    Iterator<Instant> itr = entry.getValue().iterator();
    while (itr.hasNext()) {
      Instant bid = itr.next();
      if (bid.isBefore(cutoff)) {
        NexmarkUtils.info("retire: %s for %s", bid, auction);
        itr.remove();
      } else {
        anyRemain = true;
      }
    }
  }
  return anyRemain;
}
 
開發者ID:apache,項目名稱:beam,代碼行數:22,代碼來源:Query5Model.java

示例2: checkTimestamp

import org.joda.time.Instant; //導入方法依賴的package包/類
@SuppressWarnings("deprecation") // Allowed Skew is deprecated for users, but must be respected
private void checkTimestamp(Instant timestamp) {
  // The documentation of getAllowedTimestampSkew explicitly permits Long.MAX_VALUE to be used
  // for infinite skew. Defend against underflow in that case for timestamps before the epoch
  if (fn.getAllowedTimestampSkew().getMillis() != Long.MAX_VALUE
      && timestamp.isBefore(elem.getTimestamp().minus(fn.getAllowedTimestampSkew()))) {
    throw new IllegalArgumentException(
        String.format(
            "Cannot output with timestamp %s. Output timestamps must be no earlier than the "
                + "timestamp of the current input (%s) minus the allowed skew (%s). See the "
                + "DoFn#getAllowedTimestampSkew() Javadoc for details on changing the allowed "
                + "skew.",
            timestamp,
            elem.getTimestamp(),
            PeriodFormat.getDefault().print(fn.getAllowedTimestampSkew().toPeriod())));
  }
}
 
開發者ID:apache,項目名稱:beam,代碼行數:18,代碼來源:SimpleDoFnRunner.java

示例3: awaitWatermarksOrTimeout

import org.joda.time.Instant; //導入方法依賴的package包/類
private static void awaitWatermarksOrTimeout(
    TestSparkPipelineOptions testSparkPipelineOptions, SparkPipelineResult result) {
  Long timeoutMillis = Duration.standardSeconds(
      checkNotNull(testSparkPipelineOptions.getTestTimeoutSeconds())).getMillis();
  Long batchDurationMillis = testSparkPipelineOptions.getBatchIntervalMillis();
  Instant stopPipelineWatermark =
      new Instant(testSparkPipelineOptions.getStopPipelineWatermark());
  // we poll for pipeline status in batch-intervals. while this is not in-sync with Spark's
  // execution clock, this is good enough.
  // we break on timeout or end-of-time WM, which ever comes first.
  Instant globalWatermark;
  result.waitUntilFinish(Duration.millis(batchDurationMillis));
  do {
    SparkTimerInternals sparkTimerInternals =
        SparkTimerInternals.global(GlobalWatermarkHolder.get(batchDurationMillis));
    sparkTimerInternals.advanceWatermark();
    globalWatermark = sparkTimerInternals.currentInputWatermarkTime();
    // let another batch-interval period of execution, just to reason about WM propagation.
    Uninterruptibles.sleepUninterruptibly(batchDurationMillis, TimeUnit.MILLISECONDS);
  } while ((timeoutMillis -= batchDurationMillis) > 0
        && globalWatermark.isBefore(stopPipelineWatermark));
}
 
開發者ID:apache,項目名稱:beam,代碼行數:23,代碼來源:TestSparkRunner.java

示例4: readThroughAndGetEarliestHold

import org.joda.time.Instant; //導入方法依賴的package包/類
public Instant readThroughAndGetEarliestHold(StateTable readTo) {
  Instant earliestHold = BoundedWindow.TIMESTAMP_MAX_VALUE;
  for (StateNamespace namespace : underlying.getNamespacesInUse()) {
    for (Map.Entry<StateTag, State> existingState :
        underlying.getTagsInUse(namespace).entrySet()) {
      if (!((InMemoryState<?>) existingState.getValue()).isCleared()) {
        // Only read through non-cleared values to ensure that completed windows are
        // eventually discarded, and remember the earliest watermark hold from among those
        // values.
        State state =
            readTo.get(namespace, existingState.getKey(), StateContexts.nullContext());
        if (state instanceof WatermarkHoldState) {
          Instant hold = ((WatermarkHoldState) state).read();
          if (hold != null && hold.isBefore(earliestHold)) {
            earliestHold = hold;
          }
        }
      }
    }
  }
  return earliestHold;
}
 
開發者ID:apache,項目名稱:beam,代碼行數:23,代碼來源:CopyOnAccessInMemoryStateInternals.java

示例5: commit

import org.joda.time.Instant; //導入方法依賴的package包/類
/**
 * Copies all values in the underlying table to this table, then discards the underlying table.
 *
 * <p>If there is an underlying table, this replaces the existing
 * {@link CopyOnBindBinderFactory} with a {@link ReadThroughBinderFactory}, then reads all of
 * the values in the existing table, binding the state values to this table. The old StateTable
 * should be discarded after the call to {@link #commit()}.
 *
 * <p>After copying all of the existing values, replace the binder factory with an instance of
 * {@link InMemoryStateBinderFactory} to construct new values, since all existing values
 * are bound in this {@link StateTable table} and this table represents the canonical state.
 */
private void commit() {
  Instant earliestHold = getEarliestWatermarkHold();
  if (underlying.isPresent()) {
    ReadThroughBinderFactory readThroughBinder =
        new ReadThroughBinderFactory<>(underlying.get());
    binderFactory = readThroughBinder;
    Instant earliestUnderlyingHold = readThroughBinder.readThroughAndGetEarliestHold(this);
    if (earliestUnderlyingHold.isBefore(earliestHold)) {
      earliestHold = earliestUnderlyingHold;
    }
  }
  earliestWatermarkHold = Optional.of(earliestHold);
  clearEmpty();
  binderFactory = new InMemoryStateBinderFactory();
  underlying = Optional.absent();
}
 
開發者ID:apache,項目名稱:beam,代碼行數:29,代碼來源:CopyOnAccessInMemoryStateInternals.java

示例6: VotingWeb

import org.joda.time.Instant; //導入方法依賴的package包/類
public VotingWeb(Voting v, boolean canVote) {
    this.id = v.getId();
    this.name = v.getName();
    this.beginTimestamp = v.getBeginTimestamp();
    this.endTimestamp = v.getEndTimestamp();
    final Instant now = Instant.now();
    this.isActive = now.isAfter(beginTimestamp) && now.isBefore(endTimestamp);
    this.canVote = true; //TODO: use canVote in production
}
 
開發者ID:dsx-tech,項目名稱:e-voting,代碼行數:10,代碼來源:VotingWeb.java

示例7: getWatermarkThatGuaranteesFiring

import org.joda.time.Instant; //導入方法依賴的package包/類
@Internal
@Override
public Instant getWatermarkThatGuaranteesFiring(BoundedWindow window) {
  // This trigger will fire after the latest of its sub-triggers.
  Instant deadline = BoundedWindow.TIMESTAMP_MIN_VALUE;
  for (Trigger subTrigger : subTriggers) {
    Instant subDeadline = subTrigger.getWatermarkThatGuaranteesFiring(window);
    if (deadline.isBefore(subDeadline)) {
      deadline = subDeadline;
    }
  }
  return deadline;
}
 
開發者ID:apache,項目名稱:beam,代碼行數:14,代碼來源:AfterAll.java

示例8: getWatermarkThatGuaranteesFiring

import org.joda.time.Instant; //導入方法依賴的package包/類
@Override
public Instant getWatermarkThatGuaranteesFiring(BoundedWindow window) {
  // This trigger fires once either the trigger or the until trigger fires.
  Instant actualDeadline = subTriggers.get(ACTUAL).getWatermarkThatGuaranteesFiring(window);
  Instant untilDeadline = subTriggers.get(UNTIL).getWatermarkThatGuaranteesFiring(window);
  return actualDeadline.isBefore(untilDeadline) ? actualDeadline : untilDeadline;
}
 
開發者ID:apache,項目名稱:beam,代碼行數:8,代碼來源:OrFinallyTrigger.java

示例9: getOutputTime

import org.joda.time.Instant; //導入方法依賴的package包/類
/**
 * 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.
 */
@Experimental(Kind.OUTPUT_TIME)
@Override
public Instant getOutputTime(Instant inputTimestamp, IntervalWindow window) {
  Instant startOfLastSegment = window.maxTimestamp().minus(period);
  return startOfLastSegment.isBefore(inputTimestamp)
      ? inputTimestamp
      : startOfLastSegment.plus(1);
}
 
開發者ID:apache,項目名稱:beam,代碼行數:15,代碼來源:SlidingWindows.java

示例10: addMessage

import org.joda.time.Instant; //導入方法依賴的package包/類
protected void addMessage(Message message) throws Exception {
  Instant currentMessageTimestamp = new Instant(message.getJMSTimestamp());
  if (currentMessageTimestamp.isBefore(oldestPendingTimestamp)) {
    oldestPendingTimestamp = currentMessageTimestamp;
  }
  messages.add(message);
}
 
開發者ID:apache,項目名稱:beam,代碼行數:8,代碼來源:JmsCheckpointMark.java

示例11: earliestWatermarkHold

import org.joda.time.Instant; //導入方法依賴的package包/類
/** Return the earliest output watermark hold in state, or null if none. */
public Instant earliestWatermarkHold() {
  Instant minimum = null;
  for (State storage : inMemoryState.values()) {
    if (storage instanceof WatermarkHoldState) {
      Instant hold = ((WatermarkHoldState) storage).read();
      if (minimum == null || (hold != null && hold.isBefore(minimum))) {
        minimum = hold;
      }
    }
  }
  return minimum;
}
 
開發者ID:apache,項目名稱:beam,代碼行數:14,代碼來源:TestInMemoryStateInternals.java

示例12: addElementHold

import org.joda.time.Instant; //導入方法依賴的package包/類
/**
 * Attempt to add an 'element hold'. Return the {@link Instant} at which the hold was
 * added (ie the element timestamp plus any forward shift requested by the
 * {@link WindowingStrategy#getTimestampCombiner}), or {@literal null} if no hold was added.
 * The hold is only added if both:
 * <ol>
 * <li>The backend will be able to respect it. In other words the output watermark cannot
 * be ahead of the proposed hold time.
 * <li>A timer will be set (by {@link ReduceFnRunner}) to clear the hold by the end of the
 * window. In other words the input watermark cannot be ahead of the end of the window.
 * </ol>
 * The hold ensures the pane which incorporates the element is will not be considered late by
 * any downstream computation when it is eventually emitted.
 */
@Nullable
private Instant addElementHold(ReduceFn<?, ?, ?, W>.ProcessValueContext context) {
  // Give the window function a chance to move the hold timestamp forward to encourage progress.
  // (A later hold implies less impediment to the output watermark making progress, which in
  // turn encourages end-of-window triggers to fire earlier in following computations.)
  Instant elementHold = shift(context.timestamp(), context.window());

  Instant outputWM = timerInternals.currentOutputWatermarkTime();
  Instant inputWM = timerInternals.currentInputWatermarkTime();

  String which;
  boolean tooLate;
  // TODO: These case labels could be tightened.
  // See the case analysis in addHolds above for the motivation.
  if (outputWM != null && elementHold.isBefore(outputWM)) {
    which = "too late to effect output watermark";
    tooLate = true;
  } else if (context.window().maxTimestamp().isBefore(inputWM)) {
    which = "too late for end-of-window timer";
    tooLate = true;
  } else {
    which = "on time";
    tooLate = false;
    checkState(!elementHold.isAfter(BoundedWindow.TIMESTAMP_MAX_VALUE),
        "Element hold %s is beyond end-of-time", elementHold);
    context.state().access(elementHoldTag).add(elementHold);
  }
  WindowTracing.trace(
      "WatermarkHold.addHolds: element hold at {} is {} for "
      + "key:{}; window:{}; inputWatermark:{}; outputWatermark:{}",
      elementHold, which, context.key(), context.window(), inputWM,
      outputWM);

  return tooLate ? null : elementHold;
}
 
開發者ID:apache,項目名稱:beam,代碼行數:50,代碼來源:WatermarkHold.java

示例13: forStreamFromSources

import org.joda.time.Instant; //導入方法依賴的package包/類
/** Build the {@link TimerInternals} according to the feeding streams. */
public static SparkTimerInternals forStreamFromSources(
    List<Integer> sourceIds,
    Map<Integer, SparkWatermarks> watermarks) {
  // if watermarks are invalid for the specific ids, use defaults.
  if (watermarks == null || watermarks.isEmpty()
      || Collections.disjoint(sourceIds, watermarks.keySet())) {
    return new SparkTimerInternals(
        BoundedWindow.TIMESTAMP_MIN_VALUE, BoundedWindow.TIMESTAMP_MIN_VALUE, new Instant(0));
  }
  // there might be more than one stream feeding this stream, slowest WM is the right one.
  Instant slowestLowWatermark = BoundedWindow.TIMESTAMP_MAX_VALUE;
  Instant slowestHighWatermark = BoundedWindow.TIMESTAMP_MAX_VALUE;
  // synchronized processing time should clearly be synchronized.
  Instant synchronizedProcessingTime = null;
  for (Integer sourceId: sourceIds) {
    SparkWatermarks sparkWatermarks = watermarks.get(sourceId);
    if (sparkWatermarks != null) {
      // keep slowest WMs.
      slowestLowWatermark = slowestLowWatermark.isBefore(sparkWatermarks.getLowWatermark())
          ? slowestLowWatermark : sparkWatermarks.getLowWatermark();
      slowestHighWatermark = slowestHighWatermark.isBefore(sparkWatermarks.getHighWatermark())
          ? slowestHighWatermark : sparkWatermarks.getHighWatermark();
      if (synchronizedProcessingTime == null) {
        // firstime set.
        synchronizedProcessingTime = sparkWatermarks.getSynchronizedProcessingTime();
      } else {
        // assert on following.
        checkArgument(
            sparkWatermarks.getSynchronizedProcessingTime().equals(synchronizedProcessingTime),
            "Synchronized time is expected to keep synchronized across sources.");
      }
    }
  }
  return new SparkTimerInternals(
      slowestLowWatermark, slowestHighWatermark, synchronizedProcessingTime);
}
 
開發者ID:apache,項目名稱:beam,代碼行數:38,代碼來源:SparkTimerInternals.java

示例14: getEarliestWatermarkHold

import org.joda.time.Instant; //導入方法依賴的package包/類
/**
 * Get the earliest watermark hold in this table. Ignores the contents of any underlying table.
 */
private Instant getEarliestWatermarkHold() {
  Instant earliest = BoundedWindow.TIMESTAMP_MAX_VALUE;
  for (State existingState : this.values()) {
    if (existingState instanceof WatermarkHoldState) {
      Instant hold = ((WatermarkHoldState) existingState).read();
      if (hold != null && hold.isBefore(earliest)) {
        earliest = hold;
      }
    }
  }
  return earliest;
}
 
開發者ID:apache,項目名稱:beam,代碼行數:16,代碼來源:CopyOnAccessInMemoryStateInternals.java

示例15: add

import org.joda.time.Instant; //導入方法依賴的package包/類
public void add(Message message, Instant timestamp) {
  if (timestamp.isBefore(oldestMessageTimestamp)) {
    oldestMessageTimestamp = timestamp;
  }
  messages.add(message);
}
 
開發者ID:apache,項目名稱:beam,代碼行數:7,代碼來源:MqttIO.java


注:本文中的org.joda.time.Instant.isBefore方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。