use of com.google.common.util.concurrent.TimeLimiter in project instrumentation-java by census-instrumentation.
the class TimeLimitedHandler method export.
@Override
public void export(final Collection<SpanData> spanDataList) {
final Scope exportScope = newExportScope();
try {
TimeLimiter timeLimiter = SimpleTimeLimiter.create(Executors.newSingleThreadExecutor());
timeLimiter.callWithTimeout(new Callable<Void>() {
@Override
public Void call() throws Exception {
timeLimitedExport(spanDataList);
return null;
}
}, deadline.toMillis(), TimeUnit.MILLISECONDS);
} catch (TimeoutException e) {
handleException(e, "Timeout when exporting traces: " + e);
} catch (InterruptedException e) {
handleException(e, "Interrupted when exporting traces: " + e);
} catch (Exception e) {
handleException(e, "Failed to export traces: " + e);
} finally {
exportScope.close();
}
}
Aggregations