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

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

Introduction

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

Prototype

@GwtIncompatible("TODO")
public static ListeningScheduledExecutorService listeningDecorator(ScheduledExecutorService delegate) 

Source Link

Document

Creates a ScheduledExecutorService whose submit and invokeAll methods submit ListenableFutureTask instances to the given delegate executor.

Usage

From source file:com.facebook.buck.util.BlockingHttpEndpoint.java

public BlockingHttpEndpoint(String url, int maxParallelRequests, int timeoutMillis)
        throws MalformedURLException {
    this.url = new URL(url);
    this.timeoutMillis = timeoutMillis;

    // Create an ExecutorService that blocks after N requests are in flight.  Taken from
    // http://www.springone2gx.com/blog/billy_newport/2011/05/there_s_more_to_configuring_threadpools_than_thread_pool_size
    LinkedBlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<>(maxParallelRequests);
    ExecutorService executor = new ThreadPoolExecutor(maxParallelRequests, maxParallelRequests, 2L,
            TimeUnit.MINUTES, workQueue, threadFactory, new ThreadPoolExecutor.CallerRunsPolicy());
    requestService = MoreExecutors.listeningDecorator(executor);
}

From source file:com.linkedin.pinot.core.query.scheduler.QueryScheduler.java

public QueryScheduler(@Nullable QueryExecutor queryExecutor) {
    numQueryRunnerThreads = DEFAULT_QUERY_RUNNER_THREADS;
    numQueryWorkerThreads = DEFAULT_QUERY_WORKER_THREADS;
    this.queryExecutor = queryExecutor;
    queryRunners = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(numQueryRunnerThreads));
    queryWorkers = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(numQueryWorkerThreads));
}

From source file:com.metamx.druid.indexing.coordinator.ThreadPoolTaskRunner.java

public ThreadPoolTaskRunner(TaskToolboxFactory toolboxFactory, ExecutorService exec) {
    this.toolboxFactory = toolboxFactory;
    this.exec = MoreExecutors.listeningDecorator(exec);
}

From source file:org.jclouds.gae.config.CurrentRequestExecutorServiceModule.java

public static ListeningExecutorService currentRequestExecutorService() {
    ThreadFactory factory = checkNotNull(ThreadManager.currentRequestThreadFactory(),
            "ThreadManager.currentRequestThreadFactory()");
    // GAE requests cannot exceed 10 threads per request
    int maxThreads = 10;
    long keepAlive = ApiProxy.getCurrentEnvironment().getRemainingMillis();
    ExecutorService pool = newScalingThreadPool(0, maxThreads, keepAlive, factory);
    return WithSubmissionTrace.wrap(MoreExecutors.listeningDecorator(pool));
}

From source file:co.cask.cdap.explore.client.AbstractExploreClient.java

protected AbstractExploreClient() {
    executor = MoreExecutors.listeningDecorator(Executors
            .newSingleThreadScheduledExecutor(Threads.createDaemonThreadFactory("explore-client-executor")));
}

From source file:org.glassfish.jersey.client.rx.guava.JerseyRxListenableFutureInvoker.java

JerseyRxListenableFutureInvoker(final Invocation.Builder builder, final ExecutorService executor) {
    super(builder, executor);

    service = MoreExecutors.listeningDecorator(executor);
}

From source file:org.jenkinsci.plugins.mesos.MesosCleanupThread.java

@Override
protected void execute(TaskListener listener) {
    final ImmutableList.Builder<ListenableFuture<?>> deletedNodesBuilder = ImmutableList
            .<ListenableFuture<?>>builder();
    ListeningExecutorService executor = MoreExecutors.listeningDecorator(Computer.threadPoolForRemoting);
    final ImmutableList.Builder<MesosComputer> computersToDeleteBuilder = ImmutableList
            .<MesosComputer>builder();

    for (final Computer c : Jenkins.getInstance().getComputers()) {
        if (MesosComputer.class.isInstance(c)) {
            MesosSlave mesosSlave = (MesosSlave) c.getNode();

            if (mesosSlave != null && mesosSlave.isPendingDelete()) {
                final MesosComputer comp = (MesosComputer) c;
                computersToDeleteBuilder.add(comp);
                logger.log(Level.INFO, "Marked " + comp.getName() + " for deletion");
                ListenableFuture<?> f = executor.submit(new Runnable() {
                    public void run() {
                        logger.log(Level.INFO, "Deleting pending node " + comp.getName());
                        try {
                            comp.getNode().terminate();
                        } catch (RuntimeException e) {
                            logger.log(Level.WARNING, "Failed to disconnect and delete " + comp.getName() + ": "
                                    + e.getMessage());
                            throw e;
                        }/*from w w  w  .  j  av  a2 s.  c  om*/
                    }
                });
                deletedNodesBuilder.add(f);
            } else {
                logger.log(Level.FINE, c.getName() + " with slave " + mesosSlave
                        + " is not pending deletion or the slave is null");
            }
        } else {
            logger.log(Level.FINER,
                    c.getName() + " is not a mesos computer, it is a " + c.getClass().getName());
        }
    }

    Futures.getUnchecked(Futures.successfulAsList(deletedNodesBuilder.build()));

    for (MesosComputer c : computersToDeleteBuilder.build()) {
        try {
            c.deleteSlave();
        } catch (IOException e) {
            logger.log(Level.WARNING, "Failed to disconnect and delete " + c.getName() + ": " + e.getMessage());
        } catch (InterruptedException e) {
            logger.log(Level.WARNING, "Failed to disconnect and delete " + c.getName() + ": " + e.getMessage());
        }

    }
}

From source file:io.druid.indexing.overlord.ThreadPoolTaskRunner.java

@Inject
public ThreadPoolTaskRunner(TaskToolboxFactory toolboxFactory, QueryRunnerFactoryConglomerate conglomerate) {
    this.toolboxFactory = Preconditions.checkNotNull(toolboxFactory, "toolboxFactory");
    this.exec = MoreExecutors.listeningDecorator(Execs.singleThreaded("task-runner-%d"));
    this.conglomerate = conglomerate;
}

From source file:io.druid.query.GroupByMergedQueryRunner.java

public GroupByMergedQueryRunner(ExecutorService exec, Supplier<GroupByQueryConfig> configSupplier,
        QueryWatcher queryWatcher, StupidPool<ByteBuffer> bufferPool, Iterable<QueryRunner<T>> queryables) {
    this.exec = MoreExecutors.listeningDecorator(exec);
    this.queryWatcher = queryWatcher;
    this.queryables = Iterables.unmodifiableIterable(Iterables.filter(queryables, Predicates.notNull()));
    this.configSupplier = configSupplier;
    this.bufferPool = bufferPool;
}

From source file:org.apache.gobblin.compliance.ComplianceJob.java

public ComplianceJob(Properties properties) {
    this.properties = properties;
    ExecutorService executor = ScalingThreadPoolExecutor.newScalingThreadPool(0,
            Integer.parseInt(properties.getProperty(ComplianceConfigurationKeys.MAX_CONCURRENT_DATASETS,
                    ComplianceConfigurationKeys.DEFAULT_MAX_CONCURRENT_DATASETS)),
            100,/*www . j  a v  a2 s  .c  o m*/
            ExecutorsUtils.newThreadFactory(Optional.<Logger>absent(), Optional.of("complaince-job-pool-%d")));
    this.service = MoreExecutors.listeningDecorator(executor);
    this.closer = Closer.create();
    List<Tag<?>> tags = Lists.newArrayList();
    tags.addAll(Tag.fromMap(AzkabanTags.getAzkabanTags()));
    this.metricContext = this.closer
            .register(Instrumented.getMetricContext(new State(properties), ComplianceJob.class, tags));
    this.isMetricEnabled = GobblinMetrics.isEnabled(properties);
    this.eventSubmitter = new EventSubmitter.Builder(this.metricContext, ComplianceEvents.NAMESPACE).build();
    this.throwables = Lists.newArrayList();
}