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:io.druid.indexing.overlord.SingleTaskBackgroundRunner.java

private static ListeningExecutorService buildExecutorService(int priority) {
    return MoreExecutors.listeningDecorator(Execs.singleThreaded("task-runner-%d-priority-" + priority,
            TaskThreadPriority.getThreadPriorityFromTaskPriority(priority)));
}

From source file:org.opendaylight.unimgr.mef.nrp.impl.topologytervice.TapiTopologyServiceImpl.java

public void init() {
    Objects.requireNonNull(broker);
    if (executor == null) {
        executor = MoreExecutors.listeningDecorator(
                new ThreadPoolExecutor(4, 16, 30, TimeUnit.MINUTES, new LinkedBlockingQueue<>()));
    }//from   w w  w.j ava  2 s .c o  m
    LOG.info("TapiTopologyService initialized");
}

From source file:org.apache.tez.dag.app.dag.RootInputInitializerManager.java

public RootInputInitializerManager(Vertex vertex, AppContext appContext, UserGroupInformation dagUgi,
        StateChangeNotifier stateTracker) {
    this.appContext = appContext;
    this.vertex = vertex;
    this.eventHandler = appContext.getEventHandler();
    this.rawExecutor = Executors.newCachedThreadPool(new ThreadFactoryBuilder().setDaemon(true)
            .setNameFormat("InputInitializer {" + this.vertex.getName() + "} #%d").build());
    this.executor = MoreExecutors.listeningDecorator(rawExecutor);
    this.dagUgi = dagUgi;
    this.entityStateTracker = stateTracker;
}

From source file:com.continuuity.loom.runtime.LoomServerMain.java

@Override
public void start() {
    LOG.info("Starting Loom...");
    // if no zk quorum is given, use the in memory zk server
    if (inMemoryZKServer != null) {
        inMemoryZKServer.startAndWait();
        zkClientService = getZKService(inMemoryZKServer.getConnectionStr());
    }/*from ww w  .  j a v  a 2 s.  c  o  m*/
    zkClientService.startAndWait();

    solverExecutorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(solverNumThreads,
            new ThreadFactoryBuilder().setNameFormat("solver-scheduler-%d").setDaemon(true).build()));

    callbackExecutorService = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool(
            new ThreadFactoryBuilder().setNameFormat("callback-%d").setDaemon(true).build()));

    try {
        // this is here because loom modules does things that need to connect to zookeeper...
        // TODO: move everything that needs zk started out of the module
        injector = Guice.createInjector(new ConfigurationModule(conf), new ZookeeperModule(zkClientService),
                new StoreModule(conf), new QueueModule(zkClientService),
                new SchedulerModule(conf, callbackExecutorService, solverExecutorService), new HttpModule(),
                new ManagementModule(), new ProvisionerModule(), new CodecModules().getModule());

        idService = injector.getInstance(IdService.class);
        idService.startAndWait();
        tenantStore = injector.getInstance(TenantStore.class);
        tenantStore.startAndWait();
        clusterStoreService = injector.getInstance(ClusterStoreService.class);
        clusterStoreService.startAndWait();
        entityStoreService = injector.getInstance(EntityStoreService.class);
        entityStoreService.startAndWait();
        provisionerStore = injector.getInstance(ProvisionerStore.class);
        provisionerStore.startAndWait();
        resourceService = injector.getInstance(ResourceService.class);
        resourceService.startAndWait();

        // Register MBean
        LoomStats loomStats = injector.getInstance(LoomStats.class);
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        ObjectName name = new ObjectName("com.continuuity.loom:type=LoomStats");
        mbs.registerMBean(loomStats, name);
    } catch (Exception e) {
        LOG.error("Exception starting up.", e);
        System.exit(-1);
    }
    loomService = injector.getInstance(LoomService.class);
    loomService.startAndWait();
    LOG.info("Loom service started on {}", loomService.getBindAddress());

    scheduler = injector.getInstance(Scheduler.class);
    scheduler.startAndWait();
    LOG.info("Scheduler started successfully.");
}

From source file:org.apache.hadoop.hive.llap.tezplugins.TaskCommunicator.java

public TaskCommunicator(int numThreads, Configuration conf) {
    super(TaskCommunicator.class.getSimpleName());
    this.hostProxies = new ConcurrentHashMap<>();
    this.socketFactory = NetUtils.getDefaultSocketFactory(conf);

    long connectionTimeout = conf.getLong(LlapConfiguration.LLAP_TASK_COMMUNICATOR_CONNECTION_TIMEOUT_MILLIS,
            LlapConfiguration.LLAP_TASK_COMMUNICATOR_CONNECTION_TIMEOUT_MILLIS_DEFAULT);
    long retrySleep = conf.getLong(
            LlapConfiguration.LLAP_TASK_COMMUNICATOR_CONNECTION_SLEEP_BETWEEN_RETRIES_MILLIS,
            LlapConfiguration.LLAP_TASK_COMMUNICATOR_CONNECTION_SLEEP_BETWEEN_RETRIES_MILLIS_DEFAULT);
    this.retryPolicy = RetryPolicies.retryUpToMaximumTimeWithFixedSleep(connectionTimeout, retrySleep,
            TimeUnit.MILLISECONDS);

    this.requestManager = new RequestManager(numThreads);
    ExecutorService localExecutor = Executors.newFixedThreadPool(1,
            new ThreadFactoryBuilder().setNameFormat("RequestManagerExecutor").build());
    this.requestManagerExecutor = MoreExecutors.listeningDecorator(localExecutor);

    LOG.info("Setting up taskCommunicator with" + "numThreads=" + numThreads + "retryTime(millis)="
            + connectionTimeout + "retrySleep(millis)=" + retrySleep);
}

From source file:org.excalibur.core.util.concurrent.Futures2.java

public static <V> List<V> invokeAll(List<Callable<V>> tasks) {
    return invokeAllAndShutdownWhenFinish(tasks,
            MoreExecutors.listeningDecorator(Executors.newCachedThreadPool()));
}

From source file:org.apache.streams.youtube.provider.YoutubeProvider.java

@Override
public void prepare(Object configurationObject) {
    try {/* w w  w.j av  a  2  s .  c o m*/
        this.youtube = createYouTubeClient();
    } catch (IOException | GeneralSecurityException ex) {
        LOGGER.error("Failed to created oauth for YouTube : {}", ex);
        throw new RuntimeException(ex);
    }

    this.executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(DEFAULT_THREAD_POOL_SIZE));
    this.datumQueue = new LinkedBlockingQueue<>(1000);
    this.isComplete = new AtomicBoolean(false);
    this.previousPullWasEmpty = false;
}

From source file:com.github.lukaszbudnik.dqueue.QueueClientImpl.java

QueueClientImpl(int cassandraPort, String[] cassandraAddress, String cassandraKeyspace,
        String cassandraTablePrefix, boolean cassandraCreateTables, CuratorFramework zookeeperClient,
        int threadPoolSize, MetricRegistry metricRegistry, HealthCheckRegistry healthCheckRegistry)
        throws Exception {
    this.cassandraPort = cassandraPort;
    this.cassandraAddress = cassandraAddress;
    this.cassandraKeyspace = cassandraKeyspace;
    this.cassandraTablePrefix = cassandraTablePrefix;
    this.cassandraCreateTables = cassandraCreateTables;
    this.zookeeperClient = zookeeperClient;
    this.metricRegistry = metricRegistry;
    this.healthCheckRegistry = healthCheckRegistry;

    Optional.ofNullable(healthCheckRegistry).ifPresent(hcr -> {
        hcr.register("zookeeper", new HealthCheck() {
            @Override/*from  w  ww.j  a  v  a 2s. c  o m*/
            protected Result check() throws Exception {
                if (zookeeperClient.getZookeeperClient().isConnected()) {
                    return Result.healthy();
                } else {
                    return Result.unhealthy("Zookeeper client not connected");
                }
            }
        });
        hcr.register("cassandra", new HealthCheck() {
            @Override
            protected Result check() throws Exception {
                int counter = 0;
                Session.State state = session.getState();
                for (Host host : state.getConnectedHosts()) {
                    counter += state.getOpenConnections(host);
                }
                if (counter > 0) {
                    return Result.healthy();
                } else {
                    return Result.unhealthy("Cassandra client not connected");
                }
            }
        });
    });

    cluster = Cluster.builder().withPort(cassandraPort).addContactPoints(cassandraAddress).build();
    session = cluster.connect();

    cacheCreatedTables = CacheBuilder.newBuilder().maximumSize(1000).build();

    threadFactory = new ThreadFactoryBuilder().setNameFormat("dqueue-thread-%d").build();

    executorService = MoreExecutors
            .listeningDecorator(Executors.newFixedThreadPool(threadPoolSize, threadFactory));
}

From source file:com.github.nethad.clustermeister.provisioning.torque.TorqueNodeManager.java

public TorqueNodeManager(Configuration configuration) {
    this.configuration = configuration;
    try {// w w w  .j  a  v  a2  s.  co m
        TorqueConfiguration torqueConfiguration = buildTorqueConfiguration();
        Injector injector = Guice.createInjector(new SSHModule());
        SSHClient sshClient = injector.getInstance(SSHClient.class);
        sshClient.setCredentials(torqueConfiguration.getSshCredentials());
        nodeDeployer = new TorqueJPPFNodeDeployer(buildTorqueConfiguration(), sshClient);
        executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(THREAD_POOL_SIZE));
    } catch (ConfigurationValueMissingException ex) {
        logger.error("Configuration value is missing.", ex);
    } catch (SSHClientException ex) {
        logger.error("Could not start ssh client. Something is wrong with your private key or its path.", ex);
    }
}

From source file:com.facebook.watchman.WatchmanConnection.java

public WatchmanConnection(Supplier<Map<String, Object>> inputStream, OutputStream outputStream,
        Optional<Collection<String>> unilateralLabels, Optional<Callback> unilateralCallback,
        Optional<WatchmanCommandListener> commandListener, Optional<Socket> optionalSocket) {
    this.inputMessageSupplier = inputStream;
    this.outputStream = outputStream;
    this.unilateralLabels = unilateralLabels;
    this.unilateralCallback = unilateralCallback;
    this.socket = optionalSocket;
    this.processing = new AtomicBoolean(true);
    this.outgoingMessageExecutor = MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor(
            new ThreadFactoryBuilder().setNameFormat("[watchman] Outgoing Message Executor").build()));
    this.commandQueue = Queues.newLinkedBlockingDeque();
    this.bserSerializer = new BserSerializer();
    this.commandListener = commandListener;
    this.incomingMessageExecutor = Executors.newSingleThreadExecutor(
            new ThreadFactoryBuilder().setNameFormat("[watchman] Incoming Message Executor").build());
}