Example usage for com.google.common.util.concurrent MoreExecutors directExecutor

List of usage examples for com.google.common.util.concurrent MoreExecutors directExecutor

Introduction

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

Prototype

public static Executor directExecutor() 

Source Link

Document

Returns an Executor that runs each task in the thread that invokes Executor#execute execute , as in CallerRunsPolicy .

Usage

From source file:net.javacrumbs.futureconverter.common.test.guava.GuavaConvertedFutureTestHelper.java

@Override
public void waitForCalculationToFinish(
        com.google.common.util.concurrent.ListenableFuture<String> convertedFuture)
        throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);

    Futures.addCallback(convertedFuture, new FutureCallback<String>() {
        @Override/*from ww w  .  ja  va2s  . c o m*/
        public void onSuccess(String result) {
            latch.countDown();
        }

        @Override
        public void onFailure(Throwable t) {
            latch.countDown();
        }
    }, MoreExecutors.directExecutor());

    latch.await(1, TimeUnit.SECONDS);
}

From source file:com.google.android.apps.forscience.whistlepunk.sensordb.InMemorySensorDatabase.java

@NonNull
private DataControllerImpl makeDataControllerImpl(MemoryMetadataManager manager) {
    Map<String, ExternalSensorProvider> providerMap = null;
    return new DataControllerImpl(this, MoreExecutors.directExecutor(), MoreExecutors.directExecutor(),
            MoreExecutors.directExecutor(), manager, new MonotonicClock(), providerMap);
}

From source file:com.orangerhymelabs.helenus.cassandra.database.DatabaseService.java

public void read(String name, FutureCallback<Database> callback) {
    Futures.addCallback(read(name), callback, MoreExecutors.directExecutor());
}

From source file:com.google.android.apps.forscience.whistlepunk.sensorapi.ManualSensor.java

public ManualSensor(String sensorId, long defaultGraphRange, int zoomLevelBetweenResolutionTiers) {
    super(sensorId, defaultGraphRange, MoreExecutors.directExecutor(), zoomLevelBetweenResolutionTiers,
            new UptimeClock());
}

From source file:org.opendaylight.unimgr.mef.nrp.ovs.DataStoreTestUtils.java

public static void delete(InstanceIdentifier<?> instanceIdentifier, DataBroker dataBroker) {
    ReadWriteTransaction transaction = dataBroker.newReadWriteTransaction();
    transaction.delete(LogicalDatastoreType.OPERATIONAL, instanceIdentifier);

    Futures.addCallback(transaction.commit(), new FutureCallback<CommitInfo>() {
        @Override/*from   w  ww .  j ava2 s  .  com*/
        public void onSuccess(@Nullable CommitInfo result) {
            LOG.debug("Object: {} deleted.", instanceIdentifier.toString());
        }

        @Override
        public void onFailure(Throwable t) {
            LOG.debug("Object: {} wasn't deleted due to a error: {}", instanceIdentifier.toString(),
                    t.getMessage());
            fail("Object wasn't deleted due to a error: " + t.getMessage());
        }
    }, MoreExecutors.directExecutor());
}

From source file:com.orangerhymelabs.helenus.cassandra.database.DatabaseService.java

public void readAll(FutureCallback<List<Database>> callback, Object... parms) {
    Futures.addCallback(readAll(parms), callback, MoreExecutors.directExecutor());
}

From source file:io.crate.testing.RowSender.java

/**
 * Generates N rows where each row will just have 1 integer column, the current range iteration value.
 * N is defined by the given <p>start</p> and <p>end</p> arguments.
 *
 * @param start       range start for generating rows (inclusive)
 * @param end         range end for generating rows (exclusive)
 * @param rowReceiver rows will be emitted on that RowReceiver
 * @return the last emitted integer value
 *///  www .  j ava2s  .  c om
public static long generateRowsInRangeAndEmit(int start, int end, RowReceiver rowReceiver) {
    RowSender rowSender = new RowSender(RowGenerator.range(start, end), rowReceiver,
            MoreExecutors.directExecutor());
    rowSender.run();
    if (rowSender.iterator.hasNext()) {
        long nextValue = (long) rowSender.iterator.next().get(0);
        return start > end ? nextValue + 1L : nextValue - 1L;
    } else {
        return end;
    }
}

From source file:com.orangerhymelabs.helenus.cassandra.view.ViewService.java

public ListenableFuture<View> create(View view) {
    ListenableFuture<Boolean> tableFuture = tables.exists(view.databaseName(), view.tableName());
    return Futures.transformAsync(tableFuture, new AsyncFunction<Boolean, View>() {
        @Override//w  w w  .j  av a2s .  c  o  m
        public ListenableFuture<View> apply(Boolean exists) throws Exception {
            if (exists) {
                try {
                    ValidationEngine.validateAndThrow(view);
                    return views.create(view);
                } catch (ValidationException e) {
                    return Futures.immediateFailedFuture(e);
                }
            } else {
                return Futures.immediateFailedFuture(
                        new ItemNotFoundException("Table not found: " + view.tableName()));
            }
        }
    }, MoreExecutors.directExecutor());
}

From source file:com.facebook.buck.remoteexecution.grpc.GrpcAsyncBlobFetcher.java

@Override
public ListenableFuture<ByteBuffer> fetch(Protocol.Digest digest) {
    /** Payload received on a fetch request. */
    class Data {
        ByteString data = ByteString.EMPTY;

        public ByteBuffer get() {
            return data.asReadOnlyByteBuffer();
        }//from ww w.ja  va2s.c o m

        public void concat(ByteString bytes) {
            data = data.concat(bytes);
        }
    }

    Data data = new Data();
    return closeScopeWhenFutureCompletes(CasBlobDownloadEvent.sendEvent(buckEventBus, 1, digest.getSize()),
            Futures.transform(GrpcRemoteExecutionClients.readByteStream(instanceName, digest, byteStreamStub,
                    data::concat), ignored -> data.get(), MoreExecutors.directExecutor()));
}

From source file:org.glowroot.central.util.Sessions.java

public static ResultSetFuture executeAsyncWithOnFailure(Session session, BoundStatement boundStatement,
        Runnable onFailure) {/*from   www.jav  a  2s . c  o m*/
    ResultSetFuture future = session.executeAsync(boundStatement);
    future.addListener(new Runnable() {
        @Override
        public void run() {
            try {
                // TODO report checker framework issue that occurs without checkNotNull
                checkNotNull(future).getUninterruptibly();
            } catch (Exception e) {
                logger.debug(e.getMessage(), e);
                onFailure.run();
            }
        }
    }, MoreExecutors.directExecutor());
    return future;
}