All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.prestosql.jdbc.$internal.airlift.concurrent.ExtendedSettableFuture Maven / Gradle / Ivy

There is a newer version: 350
Show newest version
package io.prestosql.jdbc.$internal.airlift.concurrent;

import io.prestosql.jdbc.$internal.guava.annotations.VisibleForTesting;
import io.prestosql.jdbc.$internal.guava.util.concurrent.AbstractFuture;
import io.prestosql.jdbc.$internal.guava.util.concurrent.ListenableFuture;

import io.prestosql.jdbc.$internal.javax.annotation.Nullable;

import java.util.concurrent.ExecutionException;

import static io.prestosql.jdbc.$internal.guava.util.concurrent.Futures.getDone;
import static io.prestosql.jdbc.$internal.guava.util.concurrent.MoreExecutors.directExecutor;

public final class ExtendedSettableFuture
        extends AbstractFuture
{
    public static  ExtendedSettableFuture create()
    {
        return new ExtendedSettableFuture<>();
    }

    private ExtendedSettableFuture() {}

    @Override
    public boolean set(@Nullable V value)
    {
        return super.set(value);
    }

    @Override
    public boolean setException(Throwable throwable)
    {
        return super.setException(throwable);
    }

    /**
     * Sets this current future with the result of the delegate.
     * 

* Values and exceptions are both propagated to this Future. * If this Future is cancelled, than the delegate will also be cancelled * with the same interrupt flag. */ public void setAsync(ListenableFuture delegate) { delegate.addListener(() -> { if (super.isDone()) { // Opportunistically avoid calling getDone. This is critical for the performance // of whenAnyCompleteCancelOthers because calling getDone for cancelled Future // constructs CancellationException and populates stack trace. // See BenchmarkWhenAnyCompleteCancelOthers for benchmark numbers. return; } try { set(getDone(delegate)); } catch (ExecutionException e) { setException(e.getCause()); } catch (RuntimeException | Error e) { setException(e); } }, directExecutor()); super.addListener(() -> { if (super.isCancelled()) { delegate.cancel(super.wasInterrupted()); } }, directExecutor()); } /** * @return true if the Future was interrupted when cancelled. */ @VisibleForTesting boolean checkWasInterrupted() { return super.wasInterrupted(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy