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

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

Introduction

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

Prototype

@Deprecated
@GwtIncompatible("TODO")
public static ListeningExecutorService sameThreadExecutor() 

Source Link

Document

Creates an executor service that runs each task in the thread that invokes execute/submit , as in CallerRunsPolicy .

Usage

From source file:org.apache.druid.server.QueryManager.java

@Override
public void registerQuery(Query query, final ListenableFuture future) {
    final String id = query.getId();
    final List<String> datasources = query.getDataSource().getNames();
    queries.put(id, future);/*from  w  w w .j  av a 2  s .c o m*/
    queryDatasources.putAll(id, datasources);
    future.addListener(new Runnable() {
        @Override
        public void run() {
            queries.remove(id, future);
            for (String datasource : datasources) {
                queryDatasources.remove(id, datasource);
            }
        }
    }, MoreExecutors.sameThreadExecutor());
}

From source file:com.android.camera.async.Observables.java

@Nonnull
@CheckReturnValue/*ww w.ja  v  a 2 s. c om*/
public static <T> SafeCloseable addThreadSafeCallback(final Observable<T> observable,
        final Updatable<T> callback) {
    return observable.addCallback(new Runnable() {
        @Override
        public void run() {
            callback.update(observable.get());
        }
    }, MoreExecutors.sameThreadExecutor());
}

From source file:org.icgc.dcc.release.client.config.WorkflowConfig.java

@Bean
public ExecutorService executorService(@Value("${workflow.parallel}") boolean parallel) {
    if (parallel) {
        // Many threads: spawned
        return Executors.newCachedThreadPool();
    } else {//from w  w w  . j  a v a  2  s  . co m
        // Only one thread: main
        return MoreExecutors.sameThreadExecutor();
    }
}

From source file:uk.ac.susx.tag.method51.core.pipeline.AbstractConsumer.java

private void initialize() {
    sourceChannel.addReceiver(this);
    this.addListener(new Listener() {
        @Override/*from  w  w  w. ja v a 2  s.co  m*/
        public void terminated(Agent source, State from) {
            sourceChannel.removeReceiver(AbstractConsumer.this);
        }

        @Override
        public void failed(Agent source, State from, Throwable failure) {
            sourceChannel.removeReceiver(AbstractConsumer.this);
        }
    }, MoreExecutors.sameThreadExecutor());

    registerEvent("consume");
}

From source file:io.druid.guice.DruidProcessingModule.java

@Provides
@BackgroundCaching//from w ww .j  av  a2 s . c om
@LazySingleton
public ExecutorService getBackgroundExecutorService(CacheConfig cacheConfig) {
    if (cacheConfig.getNumBackgroundThreads() > 0) {
        return Executors.newFixedThreadPool(cacheConfig.getNumBackgroundThreads(),
                new ThreadFactoryBuilder().setNameFormat("background-cacher-%d").setDaemon(true)
                        .setPriority(Thread.MIN_PRIORITY).build());
    } else {
        return MoreExecutors.sameThreadExecutor();
    }
}

From source file:uk.ac.susx.tag.method51.core.pipeline.AbstractConsumerProducer.java

private void initialize() {
    sinkChannel.addCaster(this);
    this.addListener(new Listener() {
        @Override/*  w  w w . jav a2  s  .co m*/
        public void terminated(Agent source, State from) {
            sinkChannel.removeCaster(AbstractConsumerProducer.this);
        }

        @Override
        public void failed(Agent source, State from, Throwable failure) {
            sinkChannel.removeCaster(AbstractConsumerProducer.this);
        }
    }, MoreExecutors.sameThreadExecutor());
}

From source file:org.teiid.translator.cassandra.CassandraUpdateExecution.java

@Override
public void execute() throws TranslatorException {
    internalExecute();//from  www  . j av  a  2s  .c  om
    resultSetFuture.addListener(new Runnable() {
        @Override
        public void run() {
            executionContext.dataAvailable();
        }
    }, MoreExecutors.sameThreadExecutor());
}

From source file:uk.ac.susx.tag.method51.core.pipeline.AbstractProducer.java

private void initialize() {
    sinkChannel.addCaster(this);
    this.addListener(new Listener() {
        @Override//from w  w  w  .  j a va 2 s .  com
        public void terminated(Agent source, State from) {
            sinkChannel.removeCaster(AbstractProducer.this);
        }

        @Override
        public void failed(Agent source, State from, Throwable failure) {
            sinkChannel.removeCaster(AbstractProducer.this);
        }
    }, MoreExecutors.sameThreadExecutor());
}

From source file:com.metamx.druid.indexing.worker.WorkerCuratorCoordinator.java

public WorkerCuratorCoordinator(ObjectMapper jsonMapper, IndexerZkConfig config,
        CuratorFramework curatorFramework, Worker worker) {
    this.jsonMapper = jsonMapper;
    this.curatorFramework = curatorFramework;
    this.worker = worker;
    this.config = config;

    this.announcer = new Announcer(curatorFramework, MoreExecutors.sameThreadExecutor());

    this.baseAnnouncementsPath = getPath(Arrays.asList(config.getIndexerAnnouncementPath(), worker.getHost()));
    this.baseTaskPath = getPath(Arrays.asList(config.getIndexerTaskPath(), worker.getHost()));
    this.baseStatusPath = getPath(Arrays.asList(config.getIndexerStatusPath(), worker.getHost()));
}

From source file:org.locationtech.geogig.api.plumbing.diff.RevObjectTestSupport.java

public static RevTreeBuilder2 createLargeFeaturesTreeBuilder(ObjectDatabase source, final String namePrefix,
        final int numEntries, final int startIndex, boolean randomIds) {

    Platform platform = new DefaultPlatform();// for tmp directory lookup
    ExecutorService executorService = MoreExecutors.sameThreadExecutor();
    RevTreeBuilder2 tree = new RevTreeBuilder2(source, RevTree.EMPTY, ObjectId.NULL, platform, executorService);

    for (int i = startIndex; i < startIndex + numEntries; i++) {
        tree.put(featureNode(namePrefix, i, randomIds));
    }/*from w  w  w.  jav a 2 s  . c om*/
    return tree;
}