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:com.facebook.buck.core.build.engine.cache.manager.ManifestRuleKeyServiceImpl.java

@Override
public ListenableFuture<CacheResult> fetchManifest(final RuleKey manifestKey,
        final LazyPath downloadedManifest) {
    String key = toManifestServiceKey(manifestKey);
    final ListenableFuture<Manifest> future = manifestService.fetchManifest(key);
    final ListenableFuture<CacheResult> cacheResultFuture = Futures.transform(future,
            (manifest) -> writeManifestToFile(manifest, downloadedManifest), MoreExecutors.directExecutor());
    return Futures.catching(cacheResultFuture, IOException.class, (exception) -> {
        String msg = String.format("Failed to fetch manifest with error [%s].", exception);
        LOG.error(exception, msg);//w ww .ja v a 2  s.c  om
        return CacheResult.error(MANIFEST_SERVICE_SOURCE, ArtifactCacheMode.unknown, msg);
    }, MoreExecutors.directExecutor());
}

From source file:com.orangerhymelabs.helenus.cassandra.table.TableService.java

public ListenableFuture<List<Table>> readAll(String database, Object... parms) {
    ListenableFuture<Boolean> dbFuture = databases.exists(database);
    return Futures.transformAsync(dbFuture, new AsyncFunction<Boolean, List<Table>>() {
        @Override//  www  .  ja v  a  2s  .c  o  m
        public ListenableFuture<List<Table>> apply(Boolean exists) throws Exception {
            if (exists) {
                return tables.readAll(parms);
            } else {
                return Futures
                        .immediateFailedFuture(new ItemNotFoundException("Database not found: " + database));
            }
        }
    }, MoreExecutors.directExecutor());
}

From source file:net.derquinse.common.util.concurrent.DefaultRefCounted.java

@Override
public Future<Long> shutdown() {
    return shutdown(MoreExecutors.directExecutor());
}

From source file:org.opendaylight.controller.cluster.sharding.PrefixedShardConfigWriter.java

private static ListenableFuture<Void> doSubmit(final DOMStoreThreePhaseCommitCohort cohort) {
    final AsyncFunction<Boolean, Void> validateFunction = input -> cohort.preCommit();
    final AsyncFunction<Void, Void> prepareFunction = input -> cohort.commit();

    final ListenableFuture<Void> prepareFuture = Futures.transformAsync(cohort.canCommit(), validateFunction,
            MoreExecutors.directExecutor());
    return Futures.transformAsync(prepareFuture, prepareFunction, MoreExecutors.directExecutor());
}

From source file:com.google.cloud.bigtable.grpc.io.RetryingCall.java

private void retryCall(RequestT message, Metadata requestHeaders, Listener<ResponseT> listener) {
    final ClientCall<RequestT, ResponseT> delegate = channel.newCall(method, callOptions);
    delegate.start(listener, requestHeaders);
    delegate.request(1);/*ww  w .j  a  va 2 s .c o m*/
    cancelled.addListener(new Runnable() {
        @Override
        public void run() {
            delegate.cancel();
        }
    }, MoreExecutors.directExecutor());

    delegate.sendMessage(message);
    delegate.halfClose();
}

From source file:com.facebook.buck.distributed.build_slave.DelegateAndGraphsInitializer.java

public ListenableFuture<ActionGraphAndBuilder> getActionGraphAndBuilder() {
    return Futures.transform(delegateAndGraphs, x -> x.getActionGraphAndBuilder(),
            MoreExecutors.directExecutor());
}

From source file:com.orangerhymelabs.helenus.cassandra.table.TableService.java

public void readAll(String database, FutureCallback<List<Table>> callback) {
    Futures.addCallback(readAll(database), callback, MoreExecutors.directExecutor());
}

From source file:com.google.devtools.build.remote.worker.WatcherServer.java

@Override
public void watch(Request wr, StreamObserver<ChangeBatch> responseObserver) {
    final String opName = wr.getTarget();
    ListenableFuture<ActionResult> future = operationsCache.get(opName);
    if (future == null) {
        responseObserver.onError(StatusProto.toStatusRuntimeException(Status.newBuilder()
                .setCode(Code.NOT_FOUND.getNumber()).setMessage("Operation not found: " + opName).build()));
        return;//from w w  w  .  j  ava2s.  c  om
    }

    future.addListener(() -> {
        try {
            try {
                ActionResult result = future.get();
                responseObserver.onNext(packExists(Operation.newBuilder().setName(opName).setDone(true)
                        .setResponse(Any.pack(ExecuteResponse.newBuilder().setResult(result).build()))));
                responseObserver.onCompleted();
            } catch (ExecutionException e) {
                Throwables.throwIfUnchecked(e.getCause());
                throw (Exception) e.getCause();
            }
        } catch (Exception e) {
            ExecuteResponse resp;
            if (e instanceof ExecutionStatusException) {
                resp = ((ExecutionStatusException) e).getResponse();
            } else {
                logger.log(Level.SEVERE, "Work failed: " + opName, e);
                resp = ExecuteResponse.newBuilder().setStatus(StatusUtils.internalErrorStatus(e)).build();
            }
            responseObserver.onNext(ChangeBatch.newBuilder()
                    .addChanges(Change
                            .newBuilder().setState(Change.State.EXISTS).setData(Any.pack(Operation.newBuilder()
                                    .setName(opName).setDone(true).setResponse(Any.pack(resp)).build()))
                            .build())
                    .build());
            responseObserver.onCompleted();
            if (e instanceof InterruptedException) {
                Thread.currentThread().interrupt();
            }
        } finally {
            operationsCache.remove(opName);
        }
    }, MoreExecutors.directExecutor());
}

From source file:org.dcache.poolmanager.RemotePoolManagerHandler.java

protected <T extends Serializable> ListenableFuture<T> submit(CellEndpoint endpoint, CellPath path,
        Serializable msg, Class<T> reply, long timeout) {
    FutureCellMessageAnswerable<T> callback = new FutureCellMessageAnswerable<>(reply);
    endpoint.sendMessage(new CellMessage(path, msg), callback, MoreExecutors.directExecutor(), timeout);
    return callback;
}

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

public ListenableFuture<View> update(View view) {
    ListenableFuture<Boolean> tableFuture = tables.exists(view.databaseName(), view.tableName());
    return Futures.transformAsync(tableFuture, new AsyncFunction<Boolean, View>() {
        @Override/*from   w  w  w .  ja v a 2  s  .  c om*/
        public ListenableFuture<View> apply(Boolean exists) throws Exception {
            if (exists) {
                try {
                    ValidationEngine.validateAndThrow(view);
                    return views.update(view);
                } catch (ValidationException e) {
                    return Futures.immediateFailedFuture(e);
                }
            } else {
                return Futures.immediateFailedFuture(
                        new ItemNotFoundException("Database not found: " + view.databaseName()));
            }
        }
    }, MoreExecutors.directExecutor());
}