Java Code Examples for com.google.protobuf.Duration#getNanos()

The following examples show how to use com.google.protobuf.Duration#getNanos() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MemoryInstance.java    From bazel-buildfarm with Apache License 2.0 6 votes vote down vote up
@Override
protected void validateAction(
    String operationName,
    Action action,
    PreconditionFailure.Builder preconditionFailure,
    RequestMetadata requestMetadata)
    throws InterruptedException, StatusException {
  if (action.hasTimeout() && config.hasMaximumActionTimeout()) {
    Duration timeout = action.getTimeout();
    Duration maximum = config.getMaximumActionTimeout();
    if (timeout.getSeconds() > maximum.getSeconds()
        || (timeout.getSeconds() == maximum.getSeconds()
            && timeout.getNanos() > maximum.getNanos())) {
      preconditionFailure
          .addViolationsBuilder()
          .setType(VIOLATION_TYPE_INVALID)
          .setSubject(Durations.toString(timeout) + " > " + Durations.toString(maximum))
          .setDescription(TIMEOUT_OUT_OF_BOUNDS);
    }
  }

  super.validateAction(operationName, action, preconditionFailure, requestMetadata);
}
 
Example 2
Source File: ShardInstance.java    From bazel-buildfarm with Apache License 2.0 6 votes vote down vote up
@Override
protected void validateAction(
    Action action,
    @Nullable Command command,
    Map<Digest, Directory> directoriesIndex,
    Consumer<Digest> onInputDigest,
    PreconditionFailure.Builder preconditionFailure) {
  if (action.hasTimeout() && hasMaxActionTimeout()) {
    Duration timeout = action.getTimeout();
    if (timeout.getSeconds() > maxActionTimeout.getSeconds()
        || (timeout.getSeconds() == maxActionTimeout.getSeconds()
            && timeout.getNanos() > maxActionTimeout.getNanos())) {
      preconditionFailure
          .addViolationsBuilder()
          .setType(VIOLATION_TYPE_INVALID)
          .setSubject(Durations.toString(timeout) + " > " + Durations.toString(maxActionTimeout))
          .setDescription(TIMEOUT_OUT_OF_BOUNDS);
    }
  }

  super.validateAction(action, command, directoriesIndex, onInputDigest, preconditionFailure);
}
 
Example 3
Source File: Poller.java    From bazel-buildfarm with Apache License 2.0 5 votes vote down vote up
private void waitForNextDeadline() {
  try {
    Duration waitTime = getWaitTime();
    if (waitTime.getSeconds() != 0 || waitTime.getNanos() != 0) {
      wait(
          waitTime.getSeconds() * 1000 + waitTime.getNanos() / 1000000,
          waitTime.getNanos() % 1000000);
    }
  } catch (InterruptedException e) {
    running = false;
  }
}
 
Example 4
Source File: InputFetcher.java    From bazel-buildfarm with Apache License 2.0 5 votes vote down vote up
private boolean isQueuedOperationValid(QueuedOperation queuedOperation) {
  Action action = queuedOperation.getAction();

  if (action.hasTimeout() && workerContext.hasMaximumActionTimeout()) {
    Duration timeout = action.getTimeout();
    Duration maximum = workerContext.getMaximumActionTimeout();
    if (timeout.getSeconds() > maximum.getSeconds()
        || (timeout.getSeconds() == maximum.getSeconds()
            && timeout.getNanos() > maximum.getNanos())) {
      return false;
    }
  }

  return !queuedOperation.getCommand().getArgumentsList().isEmpty();
}
 
Example 5
Source File: PutOperationStage.java    From bazel-buildfarm with Apache License 2.0 5 votes vote down vote up
private static float millisecondBetween(Timestamp from, Timestamp to) {
  // The time unit we want is millisecond.
  // 1 second = 1000 milliseconds
  // 1 millisecond = 1000,000 nanoseconds
  Duration d = Timestamps.between(from, to);
  return d.getSeconds() * 1000.0f + d.getNanos() / (1000.0f * 1000.0f);
}
 
Example 6
Source File: Poller.java    From bazel-buildfarm with Apache License 2.0 4 votes vote down vote up
public Poller(Duration period) {
  checkState(period.getSeconds() > 0 || period.getNanos() >= 1000);
  periodMicros = period.getSeconds() * 1000000 + period.getNanos() / 1000;
  periodDeadline = Deadline.after(periodMicros, MICROSECONDS);
}
 
Example 7
Source File: Watchdog.java    From bazel-buildfarm with Apache License 2.0 4 votes vote down vote up
private synchronized void reset(Duration timeout) {
  start = System.nanoTime();
  timeoutNanos = timeout.getSeconds() * 1000000000L + timeout.getNanos();
  this.notify();
}