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:org.glowroot.central.util.MoreFutures.java

public static <V> ListenableFuture<V> onSuccessAndFailure(ListenableFuture<V> future, Runnable onSuccess,
        Runnable onFailure) {//from www .  j a  v a2s .c o  m
    SettableFuture<V> outerFuture = SettableFuture.create();
    Futures.addCallback(future, new FutureCallback<V>() {
        @Override
        public void onSuccess(V result) {
            onSuccess.run();
            outerFuture.set(result);
        }

        @Override
        public void onFailure(Throwable t) {
            logger.debug(t.getMessage(), t);
            onFailure.run();
            outerFuture.setException(t);
        }
    }, MoreExecutors.directExecutor());
    return outerFuture;
}

From source file:com.google.api.showcase.ShowcaseTransportChannelProvider.java

@Override
public TransportChannel getTransportChannel() {
    GrpcHeaderInterceptor headerInterceptor = new GrpcHeaderInterceptor(headerProvider.getHeaders());

    ManagedChannelBuilder builder = ManagedChannelBuilder.forAddress(host, port).usePlaintext()
            .intercept(headerInterceptor).userAgent(headerInterceptor.getUserAgentHeader())
            .executor(MoreExecutors.directExecutor());

    return GrpcTransportChannel.create(builder.build());
}

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

public void update(Database database, FutureCallback<Database> callback) {
    Futures.addCallback(update(database), callback, MoreExecutors.directExecutor());
}

From source file:com.facebook.buck.distributed.LocalFsContentsProvider.java

@Override
public ListenableFuture<Boolean> materializeFileContentsAsync(BuildJobStateFileHashEntry entry,
        Path targetAbsPath) {/*from  ww  w . j  av a 2  s.  c  o m*/
    RuleKey key = new RuleKey(entry.getSha1());
    return Futures.transform(dirCache.fetchAsync(null, key, LazyPath.ofInstance(targetAbsPath)),
            (CacheResult result) -> result.getType() == CacheResultType.HIT, MoreExecutors.directExecutor());
}

From source file:io.atomix.core.multimap.DistributedMultimap.java

/**
 * Registers the specified listener to be notified whenever the map is updated.
 *
 * @param listener listener to notify about map events
 *//*from w ww.j ava 2 s.co  m*/
default void addListener(MultimapEventListener<K, V> listener) {
    addListener(listener, MoreExecutors.directExecutor());
}

From source file:io.atomix.rest.resources.WorkQueueResource.java

@GET
@Path("/{name}")
@Produces(MediaType.APPLICATION_JSON)/* ww w.  j av a  2 s .c  om*/
public void take(@PathParam("name") String name, @Context EventManager events,
        @Suspended AsyncResponse response) {
    EventLog<Consumer<String>, String> eventLog = events.getOrCreateEventLog(AsyncWorkQueue.class, name,
            l -> e -> l.addEvent(e));
    if (eventLog.open()) {
        getPrimitive(name).thenCompose(
                queue -> queue.registerTaskProcessor(eventLog.listener(), 1, MoreExecutors.directExecutor()))
                .whenComplete((result, error) -> {
                    if (error == null) {
                        takeTask(eventLog, response);
                    } else {
                        LOGGER.warn("{}", error);
                        response.resume(Response.serverError().build());
                    }
                });
    } else {
        takeTask(eventLog, response);
    }
}

From source file:com.epam.wilma.engine.bootstrap.WilmaBootstrap.java

/**
 * Initializes Spring context, and starts the application engine. Closes application context if exception is catched.
 * Loads properties from configuration file and sets them into the application context.
 *
 *//*  www  . ja v  a  2  s .c o m*/
public void bootstrap() {
    ClassPathXmlApplicationContext applicationContext = null;
    try {
        applicationContext = getApplicationContext();
        WilmaEngine wilmaEngine = applicationContext.getBean(WilmaEngine.class);
        WilmaServiceListener wilmaServiceListener = applicationContext.getBean(WilmaServiceListener.class);
        wilmaEngine.addListener(wilmaServiceListener, MoreExecutors.directExecutor());
        wilmaEngine.start();
    } catch (Exception e) {
        logErrorByTypeOfException(e);
        closeApplicationContext(applicationContext);
    }
}

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

public void read(String database, String table, String view, FutureCallback<View> callback) {
    Futures.addCallback(read(database, table, view), callback, MoreExecutors.directExecutor());
}

From source file:com.facebook.presto.execution.QueuedExecution.java

public void start() {
    // Only execute if the query is not already completed (e.g. cancelled)
    if (listenableFuture.isDone()) {
        return;/*  w ww.  ja v  a  2 s  . c o  m*/
    }
    if (nextQueues.isEmpty()) {
        executor.execute(() -> {
            try (SetThreadName setThreadName = new SetThreadName("Query-%s",
                    queryExecution.getQueryInfo().getQueryId())) {
                stats.queryStarted();
                listenableFuture.addListener(stats::queryStopped, MoreExecutors.directExecutor());

                queryExecution.start();
            }
        });
    } else {
        nextQueues.get(0).enqueue(new QueuedExecution(queryExecution, nextQueues.subList(1, nextQueues.size()),
                executor, stats, listenableFuture));
    }
}

From source file:io.crate.operation.merge.IteratorPageDownstream.java

public IteratorPageDownstream(final RowReceiver rowReceiver, final PagingIterator<Void, Row> pagingIterator,
        Optional<Executor> executor) {
    this.pagingIterator = pagingIterator;
    lastIterator = pagingIterator;//  w ww  .j ava  2s.  co m
    this.executor = executor.or(MoreExecutors.directExecutor());
    this.rowReceiver = rowReceiver;
}