Search in sources :

Example 11 with TimeLimiter

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();
    }
}
Also used : SimpleTimeLimiter(com.google.common.util.concurrent.SimpleTimeLimiter) TimeLimiter(com.google.common.util.concurrent.TimeLimiter) Scope(io.opencensus.common.Scope) TimeoutException(java.util.concurrent.TimeoutException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

SimpleTimeLimiter (com.google.common.util.concurrent.SimpleTimeLimiter)11 TimeLimiter (com.google.common.util.concurrent.TimeLimiter)11 ImmutableList (com.google.common.collect.ImmutableList)2 Scope (io.opencensus.common.Scope)2 IOException (java.io.IOException)2 ExecutorService (java.util.concurrent.ExecutorService)2 TimeoutException (java.util.concurrent.TimeoutException)2 IExpr (org.matheclipse.core.interfaces.IExpr)2 MathException (org.matheclipse.parser.client.math.MathException)2 BoundedExecutor (com.facebook.airlift.concurrent.BoundedExecutor)1 ExecutorServiceAdapter (com.facebook.airlift.concurrent.ExecutorServiceAdapter)1 PrestoConnection (com.facebook.presto.jdbc.PrestoConnection)1 PrestoStatement (com.facebook.presto.jdbc.PrestoStatement)1 QueryStats (com.facebook.presto.jdbc.QueryStats)1 QueryBody (com.facebook.presto.sql.tree.QueryBody)1 QuerySpecification (com.facebook.presto.sql.tree.QuerySpecification)1 SingleColumn (com.facebook.presto.sql.tree.SingleColumn)1 State (com.facebook.presto.verifier.QueryResult.State)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Stopwatch (com.google.common.base.Stopwatch)1