Example usage for com.google.common.util.concurrent SettableFuture set

List of usage examples for com.google.common.util.concurrent SettableFuture set

Introduction

In this page you can find the example usage for com.google.common.util.concurrent SettableFuture set.

Prototype

@Override
    public boolean set(@Nullable V value) 

Source Link

Usage

From source file:c5db.log.LogService.java

@Override
public ListenableFuture<ReplicatorLog> getReplicatorLog(String quorumId) {
    SettableFuture<ReplicatorLog> logFuture = SettableFuture.create();

    fiber.execute(() -> {/* w  w  w .  j a va2  s .co m*/
        if (moorings.containsKey(quorumId)) {
            logFuture.set(moorings.get(quorumId));
            return;
        }

        try {
            // TODO this blocks on a fiber, and should be changed to use a callback.
            Mooring mooring = new Mooring(oLog, quorumId);
            moorings.put(quorumId, mooring);
            logFuture.set(mooring);

        } catch (IOException e) {
            logFuture.setException(e);
        }
    });

    return logFuture;
}

From source file:com.twitter.heron.statemgr.localfs.LocalFileSystemStateManager.java

protected ListenableFuture<Boolean> setData(String path, byte[] data, boolean overwrite) {
    final SettableFuture<Boolean> future = SettableFuture.create();
    boolean ret = FileUtils.writeToFile(path, data, overwrite);
    future.set(ret);

    return future;
}

From source file:co.cask.cdap.explore.jdbc.MockExploreClient.java

@Override
public ListenableFuture<ExploreExecutionResult> submit(Id.Namespace namespace, final String statement) {
    SettableFuture<ExploreExecutionResult> futureDelegate = SettableFuture.create();
    futureDelegate.set(new MockExploreExecutionResult(statementsToResults.get(statement).iterator(),
            statementsToMetadata.get(statement)));
    return new MockStatementExecutionFuture(futureDelegate, statement, statementsToMetadata,
            statementsToResults);/*from  ww  w. j a  va2  s . co  m*/
}

From source file:co.cask.cdap.explore.jdbc.MockExploreClient.java

@Override
public ListenableFuture<ExploreExecutionResult> catalogs() {
    SettableFuture<ExploreExecutionResult> futureDelegate = SettableFuture.create();
    futureDelegate.set(new MockExploreExecutionResult(statementsToResults.get("catalogs_stmt").iterator(),
            statementsToMetadata.get("catalogs_stmt")));
    return new MockStatementExecutionFuture(futureDelegate, "catalogs_stmt", statementsToMetadata,
            statementsToResults);/*from   www . j  a  v a 2s. c o m*/
}

From source file:co.cask.cdap.explore.jdbc.MockExploreClient.java

@Override
public ListenableFuture<ExploreExecutionResult> tableTypes() {
    SettableFuture<ExploreExecutionResult> futureDelegate = SettableFuture.create();
    futureDelegate.set(new MockExploreExecutionResult(statementsToResults.get("tableTypes_stmt").iterator(),
            statementsToMetadata.get("tableTypes_stmt")));
    return new MockStatementExecutionFuture(futureDelegate, "tableTypes_stmt", statementsToMetadata,
            statementsToResults);// w ww .  j av a2  s  . c  o m
}

From source file:co.cask.cdap.explore.jdbc.MockExploreClient.java

@Override
public ListenableFuture<ExploreExecutionResult> dataTypes() {
    SettableFuture<ExploreExecutionResult> futureDelegate = SettableFuture.create();
    futureDelegate.set(new MockExploreExecutionResult(statementsToResults.get("dataTypes_stmt").iterator(),
            statementsToMetadata.get("dataTypes_stmt")));
    return new MockStatementExecutionFuture(futureDelegate, "dataTypes_stmt", statementsToMetadata,
            statementsToResults);/*from  ww  w . java2  s. c  o m*/
}

From source file:com.spotify.apollo.test.experimental.AsyncRequester.java

public <T> ListenableFuture<Void> pump(final int rps, final int runtimeSeconds, final ResponseTimeMetric metric,
        final Callable<ListenableFuture<T>> request) {

    final AtomicInteger rate = new AtomicInteger();
    final int hundredth = rps / 100;

    final Runnable command = new Runnable() {
        @Override/*from  w w w  .  j a  va  2  s  .  c  o  m*/
        public void run() {
            try {
                for (int i = 0; i < 100; i++) {
                    if (metric.activeTracked.get() > 10000) {
                        metric.totalRejected.incrementAndGet();
                        continue;
                    }

                    final long t0 = nanoTime();
                    final ListenableFuture<T> future = request.call();
                    metric.track(future, t0, rate.get());
                }
            } catch (Exception e) {
                LOG.error("exception", e);
            }
        }
    };

    class PhaseSwitcher implements Runnable {

        private final ScheduledFuture<?> prev;
        final int factor;

        PhaseSwitcher(ScheduledFuture<?> prev, int factor) {
            this.prev = prev;
            this.factor = factor;
        }

        PhaseSwitcher(int factor) {
            this(null, factor);
        }

        @Override
        public void run() {
            if (prev != null) {
                prev.cancel(false);
            }

            if (factor == 100) {
                LOG.info("running @ 100% = " + rps + " rps");
            } else {
                LOG.info("running @ " + factor + "% = " + rps * factor / 100 + " rps");
            }
            rate.set(factor * hundredth);
            final ScheduledFuture<?> phaseSchedule = executor.scheduleAtFixedRate(command, 0,
                    1000000 / (hundredth * factor / 100), TimeUnit.MICROSECONDS);

            if (factor < 100) {
                final int step = factor < 80 ? 10 : 5;
                executor.schedule(new PhaseSwitcher(phaseSchedule, factor + step), 20, TimeUnit.SECONDS);
            }
        }
    }

    executor.execute(new PhaseSwitcher(10));

    final SettableFuture<Void> finish = SettableFuture.create();

    executor.schedule(new Runnable() {
        @Override
        public void run() {
            finish.set(null);
        }
    }, runtimeSeconds, TimeUnit.SECONDS);

    return finish;
}

From source file:co.cask.cdap.explore.jdbc.MockExploreClient.java

@Override
public ListenableFuture<ExploreExecutionResult> columns(@Nullable String catalog,
        @Nullable String schemaPattern, String tableNamePattern, String columnNamePattern) {
    SettableFuture<ExploreExecutionResult> futureDelegate = SettableFuture.create();
    futureDelegate.set(new MockExploreExecutionResult(statementsToResults.get("columns_stmt").iterator(),
            statementsToMetadata.get("columns_stmt")));
    return new MockStatementExecutionFuture(futureDelegate, "columns_stmt", statementsToMetadata,
            statementsToResults);//from ww  w  .ja v a 2 s.c o  m
}

From source file:co.cask.cdap.explore.jdbc.MockExploreClient.java

@Override
public ListenableFuture<ExploreExecutionResult> schemas(@Nullable String catalog,
        @Nullable String schemaPattern) {
    SettableFuture<ExploreExecutionResult> futureDelegate = SettableFuture.create();
    futureDelegate.set(new MockExploreExecutionResult(statementsToResults.get("schemas_stmt").iterator(),
            statementsToMetadata.get("schemas_stmt")));
    return new MockStatementExecutionFuture(futureDelegate, "schemas_stmt", statementsToMetadata,
            statementsToResults);/*from  w  ww  .  j  av  a 2 s  .co  m*/
}

From source file:co.cask.cdap.explore.jdbc.MockExploreClient.java

@Override
public ListenableFuture<ExploreExecutionResult> functions(@Nullable String catalog,
        @Nullable String schemaPattern, String functionNamePattern) {
    SettableFuture<ExploreExecutionResult> futureDelegate = SettableFuture.create();
    futureDelegate.set(new MockExploreExecutionResult(statementsToResults.get("functions_stmt").iterator(),
            statementsToMetadata.get("functions_stmt")));
    return new MockStatementExecutionFuture(futureDelegate, "functions_stmt", statementsToMetadata,
            statementsToResults);/*from   w  w  w . j a  va 2s  .  co  m*/
}