本文整理了Java中com.twitter.util.Duration
类的一些代码示例,展示了Duration
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Duration
类的具体详情如下:
包路径:com.twitter.util.Duration
类名称:Duration
暂无
代码示例来源:origin: twitter/distributedlog
@Override
public RecordMetadata get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
try {
FutureUtils.result(dlsnFuture, Duration.apply(timeout, unit));
// TODO: align the DLSN concepts with kafka concepts
return new RecordMetadata(new TopicPartition(topic, 0), -1L, -1L);
} catch (DLInterruptedException e) {
throw new InterruptedException("Interrupted on waiting for response");
} catch (IOException e) {
throw new ExecutionException("Error on waiting for response", e);
}
}
}
代码示例来源:origin: twitter/distributedlog
public MovingAverageRateFactory(Timer timer) {
this.avgs = new CopyOnWriteArrayList<SampledMovingAverageRate>();
this.timer = timer;
Function0<BoxedUnit> sampleTask = new Function0<BoxedUnit>() {
public BoxedUnit apply() {
sampleAll();
return null;
}
};
this.timerTask = timer.schedulePeriodically(
Time.now(), Duration.fromSeconds(DEFAULT_INTERVAL_SECS), sampleTask);
}
代码示例来源: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
@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
/**
* Await for the transmit to be complete
*
* @param timeout
* wait timeout
* @param unit
* wait timeout unit
*/
int awaitTransmitComplete(long timeout, TimeUnit unit)
throws Exception {
return Await.result(transmitComplete,
Duration.fromTimeUnit(timeout, unit));
}
代码示例来源:origin: org.apache.distributedlog/distributedlog-service
closeWaitDuration = Duration.Top();
} else {
closeWaitDuration = Duration.fromMilliseconds(writerCloseTimeoutMs);
代码示例来源:origin: io.zipkin.finagle2/zipkin-finagle
SpanRecorder(Reporter<zipkin2.Span> reporter, StatsReceiver stats, Timer timer) {
this.reporter = reporter;
this.unhandledReceiver = stats.scope("record").scope("unhandled");
this.flusher = timer.schedule(ttl.$div(2L), () -> {
flush(ttl.ago());
return null;
});
}
代码示例来源: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: twitter/distributedlog
/**
* Wait for the result until it completes.
*
* @param result result to wait
* @return the result
* @throws IOException when encountered exceptions on the result
*/
public static <T> T result(Future<T> result) throws IOException {
return result(result, Duration.Top());
}
代码示例来源: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
logger.info("Waiting for closing all streams ...");
try {
Await.result(closeResult, Duration.fromTimeUnit(5, TimeUnit.MINUTES));
logger.info("Closed all streams in {} millis.",
closeStreamsStopwatch.elapsed(TimeUnit.MILLISECONDS));
代码示例来源:origin: io.zipkin.finagle/zipkin-finagle
SpanRecorder(Reporter<Span> reporter, StatsReceiver stats, Timer timer) {
this.reporter = reporter;
this.unhandledReceiver = stats.scope("record").scope("unhandled");
this.flusher = timer.schedule(ttl.$div(2L), () -> {
flush(ttl.ago());
return null;
});
}
代码示例来源:origin: twitter/distributedlog
logger.info("Using thriftmux.");
Tuple2<Transport.Liveness, Stack.Param<Transport.Liveness>> livenessParam = new Transport.Liveness(
Duration.Top(), Duration.Top(), Option.apply((Object) Boolean.valueOf(true))).mk();
serverBuilder = serverBuilder.stack(ThriftMuxServer$.MODULE$.configured(livenessParam._1(), livenessParam._2()));
代码示例来源:origin: pinterest/secor
public void start() {
Duration[] defaultLatchIntervals = {Duration.apply(1, TimeUnit.MINUTES)};
@SuppressWarnings("deprecation")
AdminServiceFactory adminServiceFactory = new AdminServiceFactory(
this.mPort,
20,
List$.MODULE$.<StatsFactory>empty(),
Option.<String>empty(),
List$.MODULE$.<Regex>empty(),
Map$.MODULE$.<String, CustomHttpHandler>empty(),
JavaConversions
.asScalaBuffer(Arrays.asList(defaultLatchIntervals)).toList()
);
RuntimeEnvironment runtimeEnvironment = new RuntimeEnvironment(this);
adminServiceFactory.apply(runtimeEnvironment);
try {
Properties properties = new Properties();
properties.load(this.getClass().getResource("build.properties").openStream());
String buildRevision = properties.getProperty("build_revision", "unknown");
LOG.info("build.properties build_revision: {}",
properties.getProperty("build_revision", "unknown"));
StatsUtil.setLabel("secor.build_revision", buildRevision);
} catch (Throwable t) {
LOG.error("Failed to load properties from build.properties", t);
}
}
}
代码示例来源:origin: twitter/distributedlog
public static <T> T validateFutureSucceededAndGetResult(Future<T> future) throws Exception {
try {
return Await.result(future, Duration.fromSeconds(10));
} catch (Exception ex) {
fail("unexpected exception " + ex.getClass().getName());
throw ex;
}
}
}
代码示例来源: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: twitter/distributedlog
private void advance(TimeControl time, MockTimer timer, int timeMs) {
Duration duration = Duration.fromMilliseconds(timeMs);
time.advance(duration);
timer.tick();
}
代码示例来源:origin: com.twitter.common/net-http-handlers-pprof
@Override
protected final void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
final int profileDurationSecs = HttpServletRequestParams.getInt(req, "seconds", 10);
final int profilePollRate = HttpServletRequestParams.getInt(req, "hz", 100);
LOG.info("Collecting CPU profile for " + profileDurationSecs + " seconds at "
+ profilePollRate + " Hz");
Duration sampleDuration = Duration.fromTimeUnit(profileDurationSecs, TimeUnit.SECONDS);
CpuProfile profile =
CpuProfile.recordInThread(sampleDuration, profilePollRate, stateToProfile).get();
resp.setHeader("Content-Type", "pprof/raw");
resp.setStatus(HttpServletResponse.SC_OK);
OutputStream responseBody = resp.getOutputStream();
try {
profile.writeGoogleProfile(responseBody);
} finally {
Closeables.close(responseBody, /* swallowIOException */ true);
}
}
}
代码示例来源:origin: openzipkin/zipkin-finagle
SpanRecorder(Reporter<zipkin2.Span> reporter, StatsReceiver stats, Timer timer) {
this.reporter = reporter;
this.unhandledReceiver = stats.scope("record").scope("unhandled");
this.flusher = timer.schedule(ttl.$div(2L), () -> {
flush(ttl.ago());
return null;
});
}
代码示例来源:origin: org.apache.distributedlog/distributedlog-service
logger.info("Using thriftmux.");
Tuple2<Transport.Liveness, Stack.Param<Transport.Liveness>> livenessParam = new Transport.Liveness(
Duration.Top(), Duration.Top(), Option.apply((Object) Boolean.valueOf(true))).mk();
serverBuilder = serverBuilder.stack(
ThriftMuxServer$.MODULE$.configured(livenessParam._1(), livenessParam._2()));
内容来源于网络,如有侵权,请联系作者删除!