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.pulsar.discovery.service.BaseDiscoveryTestSetup.java

protected MockZooKeeper createMockZooKeeper() throws Exception {
    MockZooKeeper zk = MockZooKeeper.newInstance(MoreExecutors.sameThreadExecutor());

    ZkUtils.createFullPathOptimistic(zk, LOADBALANCE_BROKERS_ROOT,
            "".getBytes(ZookeeperClientFactoryImpl.ENCODING_SCHEME), ZooDefs.Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);/*from   w w  w  .jav a2  s.  c o  m*/
    return zk;
}

From source file:io.druid.indexing.worker.WorkerCuratorCoordinator.java

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

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

    this.baseAnnouncementsPath = getPath(
            Arrays.asList(indexerZkConfig.getAnnouncementsPath(), worker.getHost()));
    this.baseTaskPath = getPath(Arrays.asList(indexerZkConfig.getTasksPath(), worker.getHost()));
    this.baseStatusPath = getPath(Arrays.asList(indexerZkConfig.getStatusPath(), worker.getHost()));
}

From source file:org.trinity.shell.plugin.impl.ShellPluginsRunnerImpl.java

@Override
public void startAll() {
    for (final ShellPlugin shellPlugin : this.shellPlugins) {
        shellPlugin.addListener(new Listener() {
            @Override// w  w  w.  j  a  v  a  2s  .com
            public void terminated(final State from) {
                System.err.println(String.format("%s TERMINATED (was %s)", shellPlugin, from));
            }

            @Override
            public void stopping(final State from) {
                System.err.println(String.format("%s STOPPING (was %s)", shellPlugin, from));
            }

            @Override
            public void starting() {
                System.err.println(String.format("%s STARTING", shellPlugin));
            }

            @Override
            public void running() {
                System.err.println(String.format("%s RUNNING", shellPlugin));
            }

            @Override
            public void failed(final State from, final Throwable failure) {
                System.err.println(String.format("%s FAILED (was %s)", shellPlugin, from));
                failure.printStackTrace();
            }
        }, MoreExecutors.sameThreadExecutor());
        shellPlugin.start();
    }
}

From source file:msi.gama.kernel.simulation.SimulationPopulation.java

protected ExecutorService getExecutorService() {
    if (executor == null) {
        final boolean isMultiThreaded = getHost().getSpecies().isMulticore();
        final int numberOfThreads = GamaPreferences.NUMBERS_OF_THREADS.getValue();
        executor = isMultiThreaded/*from ww w.  j a  va 2  s . co  m*/
                ? new ThreadPoolExecutor(1, numberOfThreads, 100L, TimeUnit.MILLISECONDS,
                        new SynchronousQueue<Runnable>())
                : MoreExecutors.sameThreadExecutor();
        if (executor instanceof ThreadPoolExecutor) {
            final ThreadPoolExecutor tpe = (ThreadPoolExecutor) executor;
            tpe.setRejectedExecutionHandler(new CallerRunsPolicy());
            tpe.allowCoreThreadTimeOut(true);
        }
    }
    return executor;
}

From source file:org.glassfish.jersey.process.internal.ProcessingExecutorsFactory.java

private static ExecutorService createRequestingExecutor(final Set<ProcessingExecutorsProvider> providers) {
    for (ProcessingExecutorsProvider provider : providers) {
        ExecutorService es = provider.getRequestingExecutor();
        if (es != null) {
            LOGGER.config(String.format("Using custom requesting executor [%s] provided by [%s].",
                    es.getClass().getName(), provider.getClass().getName()));
            return es;
        }/*w w  w .j ava 2  s.  c  om*/
    }

    LOGGER.config("Using default requesting executor.");
    return MoreExecutors.sameThreadExecutor();
}

From source file:org.voltdb.exportclient.ExportDecoderBase.java

public ListeningExecutorService getExecutor() {
    return MoreExecutors.sameThreadExecutor();
}

From source file:org.robobninjas.riemann.spring.RiemannWebsocketClientConfiguration.java

@Bean
public RiemannPubSubClient pubsubClient() {
    final NioClientSocketChannelFactory channelFactory = new NioClientSocketChannelFactory(boss, worker);
    return new RiemannPubSubClient(host, port, new WebSocketClientHandshakerFactory(),
            new Supplier<ClientBootstrap>() {
                @Override// ww w . j av  a2  s .  c  o  m
                public ClientBootstrap get() {
                    return new ClientBootstrap(channelFactory);
                }
            }, MoreExecutors.sameThreadExecutor());
}

From source file:com.netflix.curator.framework.recipes.shared.SharedCount.java

@Override
public void addListener(SharedCountListener listener) {
    addListener(listener, MoreExecutors.sameThreadExecutor());
}

From source file:org.solovyev.tasks.ListenableFutureTask.java

public void addListener(@Nonnull final FutureCallback<V> callback) {
    addListener(callback, MoreExecutors.sameThreadExecutor());
}

From source file:org.jenkinsci.plugins.workflow.support.concurrent.ListFuture.java

private void init(final Executor listenerExecutor) {
    // First, schedule cleanup to execute when the Future is done.
    addListener(new Runnable() {
        @Override//  w ww.j  ava2 s.c om
        public void run() {
            // By now the values array has either been set as the Future's value,
            // or (in case of failure) is no longer useful.
            ListFuture.this.values = null;

            // Let go of the memory held by other futures
            ListFuture.this.futures = null;
        }
    }, MoreExecutors.sameThreadExecutor());

    // Now begin the "real" initialization.

    // Corner case: List is empty.
    if (futures.isEmpty()) {
        set(Lists.newArrayList(values));
        return;
    }

    // Populate the results list with null initially.
    for (int i = 0; i < futures.size(); ++i) {
        values.add(null);
    }

    // Register a listener on each Future in the list to update
    // the state of this future.
    // Note that if all the futures on the list are done prior to completing
    // this loop, the last call to addListener() will callback to
    // setOneValue(), transitively call our cleanup listener, and set
    // this.futures to null.
    // We store a reference to futures to avoid the NPE.
    ImmutableList<? extends ListenableFuture<? extends V>> localFutures = futures;
    for (int i = 0; i < localFutures.size(); i++) {
        final ListenableFuture<? extends V> listenable = localFutures.get(i);
        final int index = i;
        listenable.addListener(new Runnable() {
            @Override
            public void run() {
                setOneValue(index, listenable);
            }
        }, listenerExecutor);
    }
}