io.opencensus.common.Duration类的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(191)

本文整理了Java中io.opencensus.common.Duration类的一些代码示例,展示了Duration类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Duration类的具体详情如下:
包路径:io.opencensus.common.Duration
类名称:Duration

Duration介绍

[英]Represents a signed, fixed-length span of time represented as a count of seconds and fractions of seconds at nanosecond resolution. It is independent of any calendar and concepts like "day" or "month". Range is approximately +-10,000 years.
[中]表示有符号、固定长度的时间跨度,以纳秒分辨率表示为秒数和秒分数。它独立于任何日历和“日”或“月”等概念。范围约为+-10000年。

代码示例

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

/**
 * Creates a new {@code Duration} from given milliseconds.
 *
 * @param millis the duration in milliseconds.
 * @return a new {@code Duration} from given milliseconds. For invalid inputs, a {@code Duration}
 *     of zero is returned.
 */
public static Duration fromMillis(long millis) {
 long seconds = millis / MILLIS_PER_SECOND;
 int nanos = (int) (millis % MILLIS_PER_SECOND * NANOS_PER_MILLI);
 return Duration.create(seconds, nanos);
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void duration_CompareLength() {
 assertThat(Duration.create(0, 0).compareTo(Duration.create(0, 0))).isEqualTo(0);
 assertThat(Duration.create(24, 42).compareTo(Duration.create(24, 42))).isEqualTo(0);
 assertThat(Duration.create(-24, -42).compareTo(Duration.create(-24, -42))).isEqualTo(0);
 assertThat(Duration.create(25, 42).compareTo(Duration.create(24, 42))).isEqualTo(1);
 assertThat(Duration.create(24, 45).compareTo(Duration.create(24, 42))).isEqualTo(1);
 assertThat(Duration.create(24, 42).compareTo(Duration.create(25, 42))).isEqualTo(-1);
 assertThat(Duration.create(24, 42).compareTo(Duration.create(24, 45))).isEqualTo(-1);
 assertThat(Duration.create(-24, -45).compareTo(Duration.create(-24, -42))).isEqualTo(-1);
 assertThat(Duration.create(-24, -42).compareTo(Duration.create(-25, -42))).isEqualTo(1);
 assertThat(Duration.create(24, 42).compareTo(Duration.create(-24, -42))).isEqualTo(1);
}

代码示例来源:origin: census-instrumentation/opencensus-java

private static Timestamp subtractDuration(Timestamp timestamp, Duration duration) {
  return timestamp.addDuration(Duration.create(-duration.getSeconds(), -duration.getNanos()));
 }
}

代码示例来源:origin: census-instrumentation/opencensus-java

private static double toDoubleSeconds(Duration duration) {
 return duration.getNanos() / NANOS_PER_SECOND + duration.getSeconds();
}

代码示例来源:origin: census-instrumentation/opencensus-java

double getFraction(Timestamp now) {
 Duration elapsedTime = now.subtractTimestamp(start);
 checkArgument(
   elapsedTime.compareTo(ZERO) >= 0 && elapsedTime.compareTo(duration) < 0,
   "This bucket must be current.");
 return ((double) elapsedTime.toMillis()) / duration.toMillis();
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
 public void toMillis() {
  assertThat(Duration.create(10, 0).toMillis()).isEqualTo(10000L);
  assertThat(Duration.create(10, 1000).toMillis()).isEqualTo(10000L);
  assertThat(Duration.create(0, (int) 1e6).toMillis()).isEqualTo(1L);
  assertThat(Duration.create(0, 0).toMillis()).isEqualTo(0L);
  assertThat(Duration.create(-10, 0).toMillis()).isEqualTo(-10000L);
  assertThat(Duration.create(-10, -1000).toMillis()).isEqualTo(-10000L);
  assertThat(Duration.create(0, -(int) 1e6).toMillis()).isEqualTo(-1L);
 }
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void testDurationFromMillisNegative() {
 assertThat(Duration.fromMillis(-1)).isEqualTo(Duration.create(0, -1000000));
 assertThat(Duration.fromMillis(-999)).isEqualTo(Duration.create(0, -999000000));
 assertThat(Duration.fromMillis(-1000)).isEqualTo(Duration.create(-1, 0));
 assertThat(Duration.fromMillis(-3456)).isEqualTo(Duration.create(-3, -456000000));
}

代码示例来源:origin: census-instrumentation/opencensus-java

IntervalBucket(Timestamp start, Duration duration, Aggregation aggregation, Measure measure) {
 this.start = checkNotNull(start, "Start");
 this.duration = checkNotNull(duration, "Duration");
 checkArgument(duration.compareTo(ZERO) > 0, "Duration must be positive");
 this.aggregation = checkNotNull(aggregation, "Aggregation");
 this.measure = checkNotNull(measure, "measure");
}

代码示例来源:origin: census-instrumentation/opencensus-java

OcAgentMetricsExporterWorker(
  String endPoint,
  boolean useInsecure,
  Duration exportInterval,
  Duration retryInterval,
  String serviceName,
  MetricProducerManager metricProducerManager) {
 this.endPoint = endPoint;
 this.useInsecure = useInsecure;
 this.exportIntervalMillis = exportInterval.toMillis();
 this.retryIntervalMillis = retryInterval.toMillis();
 this.serviceName = serviceName;
 this.metricProducerManager = metricProducerManager;
}

代码示例来源:origin: census-instrumentation/opencensus-java

private IntervalMutableViewData(View view, Timestamp start) {
 super(view);
 Duration totalDuration = ((View.AggregationWindow.Interval) view.getWindow()).getDuration();
 this.totalDuration = totalDuration;
 this.bucketDuration = Duration.fromMillis(totalDuration.toMillis() / N);
 // When initializing. add N empty buckets prior to the start timestamp of this
 // IntervalMutableViewData, so that the last bucket will be the current one in effect.
 shiftBucketList(N + 1, start);
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void fromMillis_TooLow() {
 thrown.expect(IllegalArgumentException.class);
 thrown.expectMessage("'seconds' is less than minimum (-315576000000): -315576000001");
 Duration.fromMillis(-315576000001000L);
}

代码示例来源:origin: census-instrumentation/opencensus-java

private static long durationToNanos(Duration duration) {
 return TimeUnit.SECONDS.toNanos(duration.getSeconds()) + duration.getNanos();
}

代码示例来源:origin: io.opencensus/opencensus-impl-core

double getFraction(Timestamp now) {
 Duration elapsedTime = now.subtractTimestamp(start);
 checkArgument(
   elapsedTime.compareTo(ZERO) >= 0 && elapsedTime.compareTo(duration) < 0,
   "This bucket must be current.");
 return ((double) elapsedTime.toMillis()) / duration.toMillis();
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void testDurationFromMillis() {
 assertThat(Duration.fromMillis(0)).isEqualTo(Duration.create(0, 0));
 assertThat(Duration.fromMillis(987)).isEqualTo(Duration.create(0, 987000000));
 assertThat(Duration.fromMillis(3456)).isEqualTo(Duration.create(3, 456000000));
}

代码示例来源:origin: io.opencensus/opencensus-impl-core

IntervalBucket(Timestamp start, Duration duration, Aggregation aggregation, Measure measure) {
 this.start = checkNotNull(start, "Start");
 this.duration = checkNotNull(duration, "Duration");
 checkArgument(duration.compareTo(ZERO) > 0, "Duration must be positive");
 this.aggregation = checkNotNull(aggregation, "Aggregation");
 this.measure = checkNotNull(measure, "measure");
}

代码示例来源:origin: census-instrumentation/opencensus-java

private Worker(int bufferSize, Duration scheduleDelay) {
 spans = new ArrayList<RecordEventsSpanImpl>(bufferSize);
 this.bufferSize = bufferSize;
 this.scheduleDelayMillis = scheduleDelay.toMillis();
}

代码示例来源:origin: io.opencensus/opencensus-impl-core

private IntervalMutableViewData(View view, Timestamp start) {
 super(view);
 Duration totalDuration = ((View.AggregationWindow.Interval) view.getWindow()).getDuration();
 this.totalDuration = totalDuration;
 this.bucketDuration = Duration.fromMillis(totalDuration.toMillis() / N);
 // When initializing. add N empty buckets prior to the start timestamp of this
 // IntervalMutableViewData, so that the last bucket will be the current one in effect.
 shiftBucketList(N + 1, start);
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void fromMillis_TooHigh() {
 thrown.expect(IllegalArgumentException.class);
 thrown.expectMessage("'seconds' is greater than maximum (315576000000): 315576000001");
 Duration.fromMillis(315576000001000L);
}

代码示例来源:origin: census-instrumentation/opencensus-java

/**
 * Creates a new {@code Duration} from given milliseconds.
 *
 * @param millis the duration in milliseconds.
 * @return a new {@code Duration} from given milliseconds.
 * @throws IllegalArgumentException if the number of milliseconds is out of the range that can be
 *     represented by {@code Duration}.
 * @since 0.5
 */
public static Duration fromMillis(long millis) {
 long seconds = millis / MILLIS_PER_SECOND;
 int nanos = (int) (millis % MILLIS_PER_SECOND * NANOS_PER_MILLI);
 return Duration.create(seconds, nanos);
}

代码示例来源:origin: io.opencensus/opencensus-impl-core

private static Timestamp subtractDuration(Timestamp timestamp, Duration duration) {
  return timestamp.addDuration(Duration.create(-duration.getSeconds(), -duration.getNanos()));
 }
}

相关文章