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:org.apache.druid.client.cache.BackgroundCachePopulator.java

public BackgroundCachePopulator(final ExecutorService exec, final ObjectMapper objectMapper,
        final CachePopulatorStats cachePopulatorStats, final long maxEntrySize) {
    this.exec = MoreExecutors.listeningDecorator(exec);
    this.objectMapper = Preconditions.checkNotNull(objectMapper, "objectMapper");
    this.cachePopulatorStats = Preconditions.checkNotNull(cachePopulatorStats, "cachePopulatorStats");
    this.maxEntrySize = maxEntrySize;
}

From source file:com.dangdang.ddframe.rdb.sharding.executor.ExecutorEngine.java

public ExecutorEngine(final ShardingProperties shardingProperties) {
    int executorMinIdleSize = shardingProperties.getValue(ShardingPropertiesConstant.EXECUTOR_MIN_IDLE_SIZE);
    int executorMaxSize = shardingProperties.getValue(ShardingPropertiesConstant.EXECUTOR_MAX_SIZE);
    long executorMaxIdleTimeoutMilliseconds = shardingProperties
            .getValue(ShardingPropertiesConstant.EXECUTOR_MAX_IDLE_TIMEOUT_MILLISECONDS);
    executorService = MoreExecutors.listeningDecorator(MoreExecutors.getExitingExecutorService(
            new ThreadPoolExecutor(executorMinIdleSize, executorMaxSize, executorMaxIdleTimeoutMilliseconds,
                    TimeUnit.MILLISECONDS, new SynchronousQueue<Runnable>())));
}

From source file:com.microsoft.alm.plugin.authentication.facades.VsoAuthInfoProvider.java

private VsoAuthInfoProvider() {
    accessTokenStore = new InsecureInMemoryStore<TokenPair>();
    tokenStore = new InsecureInMemoryStore<Token>();

    //Only allow 5 threads to start polling
    executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(5));

    deviceFlowResponsePrompt = PluginServiceProvider.getInstance().getDeviceFlowResponsePrompt();

    vstsPatAuthenticator = new VstsPatAuthenticator(CLIENT_ID, REDIRECT_URL, accessTokenStore, tokenStore);
}

From source file:net.nikore.gozer.marathon.MarathonAppCache.java

@Inject
public MarathonAppCache(MarathonHost client, GozerMarathonConfig config) {
    this.client = client;

    this.appClients = CacheBuilder.newBuilder()
            .refreshAfterWrite(config.getRefreshInterval(), TimeUnit.MILLISECONDS)
            .build(new CacheLoader<String, LoadBalancingHttpClient<ByteBuf, ByteBuf>>() {
                final ListeningExecutorService refresh = MoreExecutors
                        .listeningDecorator(Executors.newFixedThreadPool(10));

                @Override// w w  w .j  a va  2s  . c o  m
                public LoadBalancingHttpClient<ByteBuf, ByteBuf> load(String key) throws Exception {
                    App app = client.getApp(key);

                    List<Server> servers = app.getTasks().stream()
                            .map(task -> new Server(task.getHost(), task.getPorts().get(0)))
                            .collect(Collectors.toList());

                    return RibbonTransport.newHttpClient(
                            LoadBalancerBuilder.newBuilder().buildFixedServerListLoadBalancer(servers));
                }

                @Override
                public ListenableFuture<LoadBalancingHttpClient<ByteBuf, ByteBuf>> reload(String key,
                        LoadBalancingHttpClient<ByteBuf, ByteBuf> prevClient) {
                    return refresh.submit(() -> load(key));
                }
            });
}

From source file:com.cloudera.oryx.kmeans.computation.local.ClusteringEvaluation.java

@Override
public List<KMeansEvaluationData> call() throws InterruptedException, ExecutionException {
    Config config = ConfigUtils.getDefaultConfig();
    EvaluationSettings settings = EvaluationSettings.create(config);

    ListeningExecutorService exec = MoreExecutors
            .listeningDecorator(Executors.newFixedThreadPool(config.getInt("model.parallelism"),
                    new ThreadFactoryBuilder().setNameFormat("KMEANS-%d").setDaemon(true).build()));
    List<ListenableFuture<KMeansEvaluationData>> futures = Lists.newArrayList();
    for (Integer nc : settings.getKValues()) {
        int loops = nc == 1 ? 1 : settings.getReplications();
        for (int i = 0; i < loops; i++) {
            futures.add(exec.submit(new EvaluationRun(weightedPoints, nc, i, settings)));
        }/*  ww  w.  j  a  v a 2 s  .  c o m*/
    }

    try {
        List<KMeansEvaluationData> evalData = Futures.allAsList(futures).get();
        KMeansEvalStrategy evalStrategy = settings.getEvalStrategy();
        if (evalStrategy != null) {
            List<ClusterValidityStatistics> best = evalStrategy.evaluate(
                    Lists.transform(evalData, new Function<KMeansEvaluationData, ClusterValidityStatistics>() {
                        @Override
                        public ClusterValidityStatistics apply(KMeansEvaluationData input) {
                            return input.getClusterValidityStatistics();
                        }
                    }));
            if (best.size() == 1) {
                ClusterValidityStatistics cvs = best.get(0);
                for (KMeansEvaluationData ed : evalData) {
                    if (cvs.getK() == ed.getK() && cvs.getReplica() == ed.getReplica()) {
                        return ImmutableList.of(ed);
                    }
                }
            }
        }
        return evalData;
    } finally {
        ExecutorUtils.shutdownAndAwait(exec);
    }
}

From source file:com.facebook.buck.util.network.thrift.ThriftScribeLogger.java

public ThriftScribeLogger(ThriftService<FrontendRequest, FrontendResponse> thriftService) {
    this.thriftService = thriftService;
    this.executorService = MoreExecutors.listeningDecorator(
            MostExecutors.newMultiThreadExecutor("ThriftScribeLogger", MAX_PARALLEL_REQUESTS));
}

From source file:org.apache.bookkeeper.common.util.BoundedScheduledExecutorService.java

public BoundedScheduledExecutorService(ScheduledThreadPoolExecutor thread, int maxTasksInQueue) {
    this.queue = thread.getQueue();
    this.thread = MoreExecutors.listeningDecorator(thread);
    this.maxTasksInQueue = maxTasksInQueue;
}

From source file:org.kaaproject.kaa.server.appenders.flume.appender.client.async.AvroAsyncRpcClient.java

/**
 * Create new instance of <code>AvroAsyncRpcClient</code>.
 *
 * @param starterProp the properties of starter
 * @param numberOfClientThreads is number of client's threads
 *//*from   w w  w  .j a  va 2 s.  c o m*/
public AvroAsyncRpcClient(Properties starterProp, int numberOfClientThreads) {
    clientQueue = new ArrayBlockingQueue<RpcClient>(numberOfClientThreads);

    for (int i = 0; i < numberOfClientThreads; i++) {
        RpcClient client = RpcClientFactory.getInstance(starterProp);
        clientQueue.add(client);
    }

    LOG.info("Number of Threads:" + numberOfClientThreads);
    executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(numberOfClientThreads));
}

From source file:io.v.syncslides.lib.DeckImporter.java

public DeckImporter(ContentResolver contentResolver, DB db) {
    mExecutorService = MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor());
    mContentResolver = contentResolver;
    mDB = db;
}

From source file:com.abiquo.bond.api.EventDispatcher.java

public EventDispatcher(final Set<PluginInterface> plugins, final int numThreads) {
    this.plugins = plugins;
    eventDispatcher = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(numThreads));
}