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.jclouds.chef.strategy.internal.ListCookbookVersionsInEnvironmentImpl.java

@Override
public Iterable<? extends CookbookVersion> execute(ExecutorService executor, String environmentName,
        String numVersions) {/*from ww  w  . j ava  2 s . co m*/
    return this.executeConcurrently(MoreExecutors.listeningDecorator(executor), environmentName, numVersions);
}

From source file:org.n52.lod.triplestore.AbstractWorkerTripleSink.java

@Override
protected int addRecordsToModel(Map<String, GetRecordByIdResponseDocument> records, final Model m,
        final Report report) {
    final MutableInt counter = new MutableInt(0);
    final long modelSizeBefore = m.size();

    ListeningExecutorService executorService = MoreExecutors
            .listeningDecorator(Executors.newFixedThreadPool(NUM_THREADS));

    for (Entry<String, GetRecordByIdResponseDocument> entry : records.entrySet()) {

        final String id = entry.getKey();
        log.debug("Adding {} to the model", id);

        CallableMapper c = new CallableMapper(this.mapper.replicate(), entry.getValue());
        ListenableFuture<Model> modelFuture = executorService.submit(c);

        Futures.addCallback(modelFuture, new FutureCallback<Model>() {

            @Override/*  ww w.j a v  a  2  s  .co  m*/
            public void onFailure(Throwable t) {
                log.error("Error mapping xml to model", t);
                report.issues.put(id, "Error while adding to model: " + t.getMessage());
            }

            @Override
            public void onSuccess(Model result) {
                log.trace("Adding result to model: {}", result);
                m.add(result);
                log.trace("ADDED result to mode.");

                counter.increment();
                report.added++;
                report.addedIds.add(id);
            }

        });
    }

    executorService.shutdown();
    while (!executorService.isTerminated()) {
        try {
            executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
        } catch (InterruptedException e) {
            log.error("Could not await termination", e);
        }
    }

    log.debug("Added {} of {} records to model {}, which now has size {} (before {})", counter, records.size(),
            m.getClass(), m.size(), modelSizeBefore);
    return counter.intValue();
}

From source file:org.opendaylight.infrautils.utils.concurrent.Executors.java

public static ListeningScheduledExecutorService newListeningScheduledThreadPool(int corePoolSize,
        String namePrefix, Logger logger) {
    return MoreExecutors.listeningDecorator(newScheduledThreadPool(corePoolSize, namePrefix, logger));
}

From source file:org.apache.streams.instagram.provider.InstagramAbstractProvider.java

@Override
public void startStream() {
    InstagramDataCollector dataCollector = getInstagramDataCollector();
    this.executorService = MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor());
    ListenableFuture future = this.executorService.submit(dataCollector);
    this.futures.add(future);
    executorService.shutdown();//from w w  w  . j a v a2  s.  c  o m
}

From source file:org.immutables.mongo.fixture.MongoContext.java

private MongoContext(final MongoClient client) {
    Preconditions.checkNotNull(client, "client");

    // allows to cleanup resources after each test
    final Closer closer = Closer.create();

    closer.register(new Closeable() {
        @Override//from   www .  j a v  a2  s  . co  m
        public void close() throws IOException {
            client.close();
        }
    });

    // drop database if exists (to have a clean test)
    if (Iterables.contains(client.listDatabaseNames(), DBNAME)) {
        client.getDatabase(DBNAME).drop();
    }

    this.database = client.getDatabase(DBNAME);

    closer.register(new Closeable() {
        @Override
        public void close() throws IOException {
            database.drop();
        }
    });

    final ListeningExecutorService executor = MoreExecutors
            .listeningDecorator(Executors.newSingleThreadExecutor());

    closer.register(new Closeable() {
        @Override
        public void close() throws IOException {
            MoreExecutors.shutdownAndAwaitTermination(executor, 100, TimeUnit.MILLISECONDS);
        }
    });

    this.setup = RepositorySetup.builder().gson(createGson()).executor(executor).database(database).build();

    this.closer = closer;
}

From source file:com.zaradai.kunzite.optimizer.control.DefaultOptimizerController.java

protected ListeningExecutorService createExecutorService() {
    return MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
}

From source file:io.v.syncslides.db.SyncbaseDB.java

@Override
public void init(Context context) throws InitException {
    if (mInitialized) {
        return;/*from  w  w w  .  j ava 2 s.c om*/
    }
    mContext = context;
    mHandler = new Handler(Looper.getMainLooper());
    mExecutorService = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());

    // If blessings aren't in place, the fragment that called this
    // initialization may continue to load and use DB, but nothing will
    // work so DB methods should return noop values.  It's assumed that
    // the calling fragment will send the user to the AccountManager,
    // accept blessings on return, then re-call this init.
    if (!V23.Singleton.get().isBlessed()) {
        Log.d(TAG, "no blessings.");
        return;
    }
    mVContext = V23.Singleton.get().getVContext();
    setupSyncbase();
}

From source file:org.flinkspector.core.runtime.Runner.java

public Runner(LocalFlinkMiniCluster executor) {
    this.cluster = executor;
    executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(10));
    currentPort = 5555;//from  w ww . j a v  a 2  s. co m
    runningListeners = new AtomicInteger(0);
    stopExecution = new TimerTask() {
        public void run() {
            stopExecution();
        }
    };

}

From source file:org.opendaylight.sxp.route.ClusterSanityWatchdogInstance.java

/**
 * @param broker                          service providing access to Datastore
 * @param clusterSingletonServiceProvider service used for registration
 * @param period                          period of watchdog feed
 * @param failLimit                       acceptable missed watchdog feeds
 *//* w  ww  . j  a va2s  . c  om*/
public ClusterSanityWatchdogInstance(final DataBroker broker,
        final ClusterSingletonServiceProvider clusterSingletonServiceProvider, final int period,
        final int failLimit) {
    LOG.info("Cluster sanity watchdog initiating ..");
    this.dataBroker = Objects.requireNonNull(broker);
    this.scheduledExecutorService = MoreExecutors.listeningDecorator(Executors.newScheduledThreadPool(1));
    taskFactory = new FollowerSyncStatusTaskFactory(period, failLimit);

    clusterServiceRegistration = Objects.requireNonNull(clusterSingletonServiceProvider)
            .registerClusterSingletonService(this);
    LOG.info("Cluster sanity watchdog initiated");
}

From source file:org.apache.brooklyn.core.mgmt.persist.FileBasedObjectStore.java

/**
 * @param basedir//  w  w  w .  j a va  2s . c  o m
 */
public FileBasedObjectStore(File basedir) {
    this.basedir = checkPersistenceDirPlausible(basedir);
    this.executor = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
    log.debug("File-based objectStore will use directory {}", basedir);
    // don't check accessible yet, we do that when we prepare
}