com.twitter.util.Duration.fromMilliseconds()方法的使用及代码示例

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

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

Duration.fromMilliseconds介绍

暂无

代码示例

代码示例来源:origin: twitter/distributedlog

@Override
public void unlock() {
  Future<BoxedUnit> unlockResult = asyncUnlock();
  try {
    Await.result(unlockResult, Duration.fromMilliseconds(lockOpTimeout));
  } catch (TimeoutException toe) {
    // This shouldn't happen unless we lose a watch, and may result in a leaked lock.
    LOG.error("Timeout unlocking {} owned by {} : ", new Object[] { lockPath, lockId, toe });
  } catch (Exception e) {
    LOG.warn("{} failed to unlock {} : ", new Object[] { lockId, lockPath, e });
  }
}

代码示例来源:origin: twitter/distributedlog

synchronized String sendNextWrite() {
  long elapsedMs = stopwatch.elapsed(TimeUnit.MILLISECONDS);
  if (elapsedMs > requestTimeoutMs || numTriedStreams >= numStreams) {
    fail(new IndividualRequestTimeoutException(Duration.fromMilliseconds(elapsedMs)));
    return null;
  }
  try {
    return sendWriteToStream(nextStream);
  } finally {
    nextStream = (nextStream + 1) % numStreams;
    ++numTriedStreams;
  }
}

代码示例来源:origin: twitter/distributedlog

private ClientBuilder getDefaultClientBuilder() {
  return ClientBuilder.get()
    .hostConnectionLimit(1)
    .tcpConnectTimeout(Duration.fromMilliseconds(200))
    .connectTimeout(Duration.fromMilliseconds(200))
    .requestTimeout(Duration.fromSeconds(1));
}

代码示例来源:origin: twitter/distributedlog

private void advance(TimeControl time, MockTimer timer, int timeMs) {
  Duration duration = Duration.fromMilliseconds(timeMs);
  time.advance(duration);
  timer.tick();
}

代码示例来源:origin: twitter/distributedlog

void send(SocketAddress address) {
  long elapsedMs = stopwatch.elapsed(TimeUnit.MILLISECONDS);
  if (clientConfig.getMaxRedirects() > 0 &&
      tries.get() >= clientConfig.getMaxRedirects()) {
    fail(address, new RequestTimeoutException(Duration.fromMilliseconds(elapsedMs),
        "Exhausted max redirects in " + elapsedMs + " ms"));
    return;
  } else if (clientConfig.getRequestTimeoutMs() > 0 &&
      elapsedMs >= clientConfig.getRequestTimeoutMs()) {
    fail(address, new RequestTimeoutException(Duration.fromMilliseconds(elapsedMs),
        "Exhausted max request timeout " + clientConfig.getRequestTimeoutMs()
            + " in " + elapsedMs + " ms"));
    return;
  }
  synchronized (this) {
    String addrStr = address.toString();
    if (ctx.isSetTriedHosts() && ctx.getTriedHosts().contains(addrStr)) {
      nextAddressToSend = address;
      dlTimer.newTimeout(this,
          Math.min(clientConfig.getRedirectBackoffMaxMs(),
              tries.get() * clientConfig.getRedirectBackoffStartMs()),
          TimeUnit.MILLISECONDS);
    } else {
      doSend(address);
    }
  }
}

代码示例来源:origin: twitter/distributedlog

LockWaiter waiter;
try {
  waiter = Await.result(tryFuture, Duration.fromMilliseconds(lockOpTimeout));
  success = true;
} catch (LockStateChangedException ex) {

代码示例来源:origin: twitter/distributedlog

final Future<LogRecordWithDLSN> readFuture = reader.readNext();
try {
  Await.result(readFuture, Duration.fromMilliseconds(2000));
  fail("Should not read any data beyond an empty inprogress log segment");
} catch (TimeoutException e) {

代码示例来源:origin: twitter/distributedlog

Await.result(readFuture, Duration.fromMilliseconds(1000));
  fail("Should fail reading next when there is a corrupted log segment");
} catch (TimeoutException te) {
  Await.result(readFuture, Duration.fromMilliseconds(1000));
  fail("Should fail reading next when there is a corrupted log segment");
} catch (TimeoutException te) {

代码示例来源:origin: pinterest/pinlater

/**
 * Turn on graceful shutdown on the finagle server passed in with the grace period of 10 seconds.
 *
 * @param server the finagle server instance built by finagle ServerBuilder
 */
public static void register(final Server server) {
 register(server, Duration.fromMilliseconds(DEFAULT_GRACE_PERIOD_MILLIS));
}

代码示例来源:origin: org.apache.distributedlog/distributedlog-client

synchronized String sendNextWrite() {
  long elapsedMs = stopwatch.elapsed(TimeUnit.MILLISECONDS);
  if (elapsedMs > requestTimeoutMs || numTriedStreams >= numStreams) {
    fail(new IndividualRequestTimeoutException(Duration.fromMilliseconds(elapsedMs)));
    return null;
  }
  try {
    return sendWriteToStream(nextStream);
  } finally {
    nextStream = (nextStream + 1) % numStreams;
    ++numTriedStreams;
  }
}

代码示例来源:origin: com.twitter/distributedlog-client

synchronized String sendNextWrite() {
  long elapsedMs = stopwatch.elapsed(TimeUnit.MILLISECONDS);
  if (elapsedMs > requestTimeoutMs || numTriedStreams >= numStreams) {
    fail(new IndividualRequestTimeoutException(Duration.fromMilliseconds(elapsedMs)));
    return null;
  }
  try {
    return sendWriteToStream(nextStream);
  } finally {
    nextStream = (nextStream + 1) % numStreams;
    ++numTriedStreams;
  }
}

代码示例来源:origin: com.twitter/distributedlog-client

private ClientBuilder getDefaultClientBuilder() {
  return ClientBuilder.get()
    .hostConnectionLimit(1)
    .tcpConnectTimeout(Duration.fromMilliseconds(200))
    .connectTimeout(Duration.fromMilliseconds(200))
    .requestTimeout(Duration.fromSeconds(1));
}

代码示例来源:origin: org.apache.distributedlog/distributedlog-client

private ClientBuilder getDefaultClientBuilder(ClientConfig clientConfig) {
  ClientBuilder builder = ClientBuilder.get()
    .tcpConnectTimeout(Duration.fromMilliseconds(200))
    .connectTimeout(Duration.fromMilliseconds(200))
    .requestTimeout(Duration.fromSeconds(1));
  if (!clientConfig.getThriftMux()) {
    builder = builder.hostConnectionLimit(1);
  }
  return builder;
}

代码示例来源:origin: org.apache.distributedlog/distributedlog-client

void send(SocketAddress address) {
  long elapsedMs = stopwatch.elapsed(TimeUnit.MILLISECONDS);
  if (clientConfig.getMaxRedirects() > 0
    && tries.get() >= clientConfig.getMaxRedirects()) {
    fail(address, new RequestTimeoutException(Duration.fromMilliseconds(elapsedMs),
        "Exhausted max redirects in " + elapsedMs + " ms"));
    return;
  } else if (shouldTimeout(elapsedMs)) {
    fail(address, new RequestTimeoutException(Duration.fromMilliseconds(elapsedMs),
        "Exhausted max request timeout " + clientConfig.getRequestTimeoutMs()
            + " in " + elapsedMs + " ms"));
    return;
  }
  synchronized (this) {
    String addrStr = address.toString();
    if (ctx.isSetTriedHosts() && ctx.getTriedHosts().contains(addrStr)) {
      nextAddressToSend = address;
      dlTimer.newTimeout(this,
          Math.min(clientConfig.getRedirectBackoffMaxMs(),
              tries.get() * clientConfig.getRedirectBackoffStartMs()),
          TimeUnit.MILLISECONDS);
    } else {
      doSend(address);
    }
  }
}

代码示例来源:origin: com.twitter/distributedlog-client

void send(SocketAddress address) {
  long elapsedMs = stopwatch.elapsed(TimeUnit.MILLISECONDS);
  if (clientConfig.getMaxRedirects() > 0 &&
      tries.get() >= clientConfig.getMaxRedirects()) {
    fail(address, new RequestTimeoutException(Duration.fromMilliseconds(elapsedMs),
        "Exhausted max redirects in " + elapsedMs + " ms"));
    return;
  } else if (clientConfig.getRequestTimeoutMs() > 0 &&
      elapsedMs >= clientConfig.getRequestTimeoutMs()) {
    fail(address, new RequestTimeoutException(Duration.fromMilliseconds(elapsedMs),
        "Exhausted max request timeout " + clientConfig.getRequestTimeoutMs()
            + " in " + elapsedMs + " ms"));
    return;
  }
  synchronized (this) {
    String addrStr = address.toString();
    if (ctx.isSetTriedHosts() && ctx.getTriedHosts().contains(addrStr)) {
      nextAddressToSend = address;
      dlTimer.newTimeout(this,
          Math.min(clientConfig.getRedirectBackoffMaxMs(),
              tries.get() * clientConfig.getRedirectBackoffStartMs()),
          TimeUnit.MILLISECONDS);
    } else {
      doSend(address);
    }
  }
}

代码示例来源:origin: org.apache.distributedlog/distributedlog-service

closeWaitDuration = Duration.Top();
} else {
  closeWaitDuration = Duration.fromMilliseconds(writerCloseTimeoutMs);

代码示例来源:origin: openzipkin/zipkin-finagle

@Test public void flushesIncompleteSpans() throws Exception {
 advanceAndRecord(0, root, new Annotation.Rpc("GET"));
 advanceAndRecord(15, root, new Annotation.ServiceName("frontend"));
 advanceAndRecord(0, root, Annotation.ServerRecv$.MODULE$);
 // Note: there's no ServerSend() which would complete the span.
 time.advance(recorder.ttl.plus(Duration.fromMilliseconds(1))); // advance timer
 timer.tick(); // invokes a flush
 Span span = spansSent.take();
 assertThat(span.id()).isEqualTo(root.spanId().toString());
 assertThat(span.name()).isEqualTo("get");
 assertThat(span.kind()).isEqualTo(Span.Kind.SERVER);
 assertThat(span.annotations()).extracting(zipkin2.Annotation::value).containsExactly(
   "finagle.flush"
 );
 assertThat(span.duration()).isNull();
}

代码示例来源:origin: openzipkin/zipkin-finagle

private void advanceAndRecord(int millis, TraceId traceId, Annotation annotation) {
 time.advance(Duration.fromMilliseconds(millis));
 recorder.record(new Record(traceId, Time.now(), annotation, empty()));
}

代码示例来源:origin: org.apache.distributedlog/distributedlog-client

if (null == builder) {
  builder = ClientBuilder.get()
      .tcpConnectTimeout(Duration.fromMilliseconds(200))
      .connectTimeout(Duration.fromMilliseconds(200))
      .requestTimeout(Duration.fromSeconds(1))
      .retries(20);

相关文章