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.streams.twitter.provider.TwitterTimelineProvider.java

@Override
public void prepare(Object configurationObject) {

    if (configurationObject instanceof TwitterTimelineProviderConfiguration) {
        this.config = (TwitterTimelineProviderConfiguration) configurationObject;
    }//from w  ww.j  a v a 2  s  .c o  m

    try {
        lock.writeLock().lock();
        providerQueue = constructQueue();
    } finally {
        lock.writeLock().unlock();
    }

    Objects.requireNonNull(providerQueue);
    Objects.requireNonNull(config.getOauth().getConsumerKey());
    Objects.requireNonNull(config.getOauth().getConsumerSecret());
    Objects.requireNonNull(config.getOauth().getAccessToken());
    Objects.requireNonNull(config.getOauth().getAccessTokenSecret());
    Objects.requireNonNull(config.getInfo());

    consolidateToIDs();

    if (ids.size() > 1) {
        executor = MoreExecutors.listeningDecorator(
                TwitterUserInformationProvider.newFixedThreadPoolWithQueueSize(5, ids.size()));
    } else {
        executor = MoreExecutors.listeningDecorator(newSingleThreadExecutor());
    }
}

From source file:io.mycat.server.MycatServer.java

public void startup() throws IOException {

    SystemConfig system = config.getSystem();
    int processorCount = system.getProcessors();

    // server startup
    LOGGER.info("===============================================");
    LOGGER.info(NAME + " is ready to startup ...");
    String inf = "Startup processors ...,total processors:" + system.getProcessors() + ",aio thread pool size:"
            + system.getProcessorExecutor() + "    \r\n each process allocated socket buffer pool "
            + " bytes ,buffer chunk size:" + system.getProcessorBufferChunk()
            + "  buffer pool's capacity(buferPool/bufferChunk) is:"
            + system.getProcessorBufferPool() / system.getProcessorBufferChunk();
    LOGGER.info(inf);/*w w  w .  j a  va  2  s  .  c o  m*/
    LOGGER.info("sysconfig params:" + system.toString());

    int threadPoolSize = system.getProcessorExecutor();
    int processBuferPool = system.getProcessorBufferPool();
    int processBufferChunk = system.getProcessorBufferChunk();
    int socketBufferLocalPercent = system.getProcessorBufferLocalPercent();

    // server startup
    LOGGER.info("===============================================");
    LOGGER.info(NAME + " is ready to startup ,network config:" + system);

    // message byte buffer pool
    BufferPool bufferPool = new BufferPool(processBuferPool, processBufferChunk,
            system.getFrontSocketSoRcvbuf(), socketBufferLocalPercent / processorCount);
    // Business Executor ?
    NameableExecutor businessExecutor = ExecutorUtil.create("BusinessExecutor", threadPoolSize);
    // Executor?
    timerExecutor = ExecutorUtil.createSheduledExecute("Timer", system.getTimerExecutor());
    listeningExecutorService = MoreExecutors.listeningDecorator(businessExecutor);

    // create netsystem to store our network related objects
    NetSystem netSystem = new NetSystem(bufferPool, businessExecutor, timerExecutor);
    netSystem.setNetConfig(system);
    // Reactor pool
    NIOReactorPool reactorPool = new NIOReactorPool(BufferPool.LOCAL_BUF_THREAD_PREX + "NIOREACTOR",
            processorCount);
    NIOConnector connector = new NIOConnector(BufferPool.LOCAL_BUF_THREAD_PREX + "NIOConnector", reactorPool);
    connector.start();
    netSystem.setConnector(connector);

    MySQLFrontConnectionFactory frontFactory = new MySQLFrontConnectionFactory(
            new MySQLFrontConnectionHandler());
    NIOAcceptor server = new NIOAcceptor(BufferPool.LOCAL_BUF_THREAD_PREX + NAME + "Server", system.getBindIp(),
            system.getServerPort(), frontFactory, reactorPool);
    server.start();
    // server started
    LOGGER.info(server.getName() + " is started and listening on " + server.getPort());
    LOGGER.info("===============================================");
    // init datahost
    Map<String, PhysicalDBPool> dataHosts = config.getDataHosts();
    LOGGER.info("Initialize dataHost ...");
    for (PhysicalDBPool node : dataHosts.values()) {
        String index = dnIndexProperties.getProperty(node.getHostName(), "0");
        if (!"0".equals(index)) {
            LOGGER.info("init datahost: " + node.getHostName() + "  to use datasource index:" + index);
        }
        node.init(Integer.valueOf(index));
        node.startHeartbeat();
    }
    long dataNodeIldeCheckPeriod = system.getDataNodeIdleCheckPeriod();
    timer.schedule(updateTime(), 0L, TIME_UPDATE_PERIOD);
    timer.schedule(processorCheck(), 0L, system.getProcessorCheckPeriod());
    timer.schedule(dataNodeConHeartBeatCheck(dataNodeIldeCheckPeriod), 0L, dataNodeIldeCheckPeriod);
    timer.schedule(dataNodeHeartbeat(), 0L, system.getDataNodeHeartbeatPeriod());
    timer.schedule(catletClassClear(), 30000);

}

From source file:org.hawkular.metrics.core.impl.MetricsServiceImpl.java

public void startUp(Session session, String keyspace, boolean resetDb, boolean createSchema,
        MetricRegistry metricRegistry) {
    SchemaManager schemaManager = new SchemaManager(session);
    if (resetDb) {
        schemaManager.dropKeyspace(keyspace);
    }//from  w w w .j a v a 2 s.  c om
    if (createSchema) {
        // This creates/updates the keyspace + tables if needed
        schemaManager.createSchema(keyspace);
    }
    session.execute("USE " + keyspace);
    logger.info("Using a key space of '{}'", keyspace);
    metricsTasks = MoreExecutors
            .listeningDecorator(Executors.newFixedThreadPool(4, new MetricsThreadFactory()));
    loadDataRetentions();

    this.metricRegistry = metricRegistry;

    dataPointInserters = ImmutableMap
            .<MetricType<?>, Func2<? extends Metric<?>, Integer, Observable<Integer>>>builder()
            .put(GAUGE, (metric, ttl) -> {
                @SuppressWarnings("unchecked")
                Metric<Double> gauge = (Metric<Double>) metric;
                return dataAccess.insertGaugeData(gauge, ttl);
            }).put(AVAILABILITY, (metric, ttl) -> {
                @SuppressWarnings("unchecked")
                Metric<AvailabilityType> avail = (Metric<AvailabilityType>) metric;
                return dataAccess.insertAvailabilityData(avail, ttl);
            }).put(COUNTER, (metric, ttl) -> {
                @SuppressWarnings("unchecked")
                Metric<Long> counter = (Metric<Long>) metric;
                return dataAccess.insertCounterData(counter, ttl);
            }).put(COUNTER_RATE, (metric, ttl) -> {
                @SuppressWarnings("unchecked")
                Metric<Double> gauge = (Metric<Double>) metric;
                return dataAccess.insertGaugeData(gauge, ttl);
            }).build();

    dataPointFinders = ImmutableMap
            .<MetricType<?>, Func3<? extends MetricId<?>, Long, Long, Observable<ResultSet>>>builder()
            .put(GAUGE, dataAccess::findData).put(AVAILABILITY, dataAccess::findAvailabilityData)
            .put(COUNTER, dataAccess::findCounterData).build();

    dataPointMappers = ImmutableMap.<MetricType<?>, Func1<Row, ? extends DataPoint<?>>>builder()
            .put(GAUGE, Functions::getGaugeDataPoint).put(AVAILABILITY, Functions::getAvailabilityDataPoint)
            .put(COUNTER, Functions::getCounterDataPoint).build();

    initMetrics();
}

From source file:org.eclipse.osee.executor.admin.internal.ExecutorAdminImpl.java

private ListeningScheduledExecutorService createScheduledExecutor(String id, int poolSize) {
    ThreadFactory threadFactory = new ThreadFactoryBuilder()//
            .setNameFormat(id + "- [%s]")//
            .setPriority(Thread.NORM_PRIORITY)//
            .build();// w w w  .  ja  v  a2 s. c o  m
    ScheduledExecutorService executor = null;
    if (poolSize > 0) {
        executor = Executors.newScheduledThreadPool(poolSize, threadFactory);
    } else {
        executor = Executors.newSingleThreadScheduledExecutor(threadFactory);
    }
    ListeningScheduledExecutorService listeningExecutor = MoreExecutors.listeningDecorator(executor);
    cache.put(id, listeningExecutor);
    return listeningExecutor;
}

From source file:org.apache.streams.facebook.provider.FacebookUserstreamProvider.java

@Override
public void prepare(Object o) {

    executor = MoreExecutors.listeningDecorator(newFixedThreadPoolWithQueueSize(5, 20));

    Preconditions.checkNotNull(providerQueue);
    Preconditions.checkNotNull(this.klass);
    Preconditions.checkNotNull(configuration.getOauth().getAppId());
    Preconditions.checkNotNull(configuration.getOauth().getAppSecret());
    Preconditions.checkNotNull(configuration.getOauth().getUserAccessToken());

    client = getFacebookClient();/* w w  w .j ava2 s.c o  m*/

    if (configuration.getInfo() != null && configuration.getInfo().size() > 0) {

        List<String> ids = new ArrayList<String>();
        List<String[]> idsBatches = new ArrayList<String[]>();

        for (String s : configuration.getInfo()) {
            if (s != null) {
                ids.add(s);

                if (ids.size() >= 100) {
                    // add the batch
                    idsBatches.add(ids.toArray(new String[ids.size()]));
                    // reset the Ids
                    ids = new ArrayList<String>();
                }

            }
        }
    }
}

From source file:org.opendaylight.controller.sal.connect.netconf.NetconfDevice.java

public NetconfDevice(final SchemaResourcesDTO schemaResourcesDTO, final RemoteDeviceId id,
        final RemoteDeviceHandler<NetconfSessionPreferences> salFacade,
        final ExecutorService globalProcessingExecutor, final boolean reconnectOnSchemasChange) {
    this.id = id;
    this.reconnectOnSchemasChange = reconnectOnSchemasChange;
    this.schemaRegistry = schemaResourcesDTO.getSchemaRegistry();
    this.schemaContextFactory = schemaResourcesDTO.getSchemaContextFactory();
    this.salFacade = salFacade;
    this.stateSchemasResolver = schemaResourcesDTO.getStateSchemasResolver();
    this.processingExecutor = MoreExecutors.listeningDecorator(globalProcessingExecutor);
    this.notificationHandler = new NotificationHandler(salFacade, id);
}

From source file:org.apache.tez.runtime.library.common.shuffle.orderedgrouped.Shuffle.java

public Shuffle(InputContext inputContext, Configuration conf, int numInputs, long initialMemoryAvailable)
        throws IOException {
    this.inputContext = inputContext;
    this.conf = conf;

    this.srcNameTrimmed = TezUtilsInternal.cleanVertexName(inputContext.getSourceVertexName());

    if (ConfigUtils.isIntermediateInputCompressed(conf)) {
        Class<? extends CompressionCodec> codecClass = ConfigUtils.getIntermediateInputCompressorClass(conf,
                DefaultCodec.class);
        codec = ReflectionUtils.newInstance(codecClass, conf);
        // Work around needed for HADOOP-12191. Avoids the native initialization synchronization race
        codec.getDecompressorType();/*from ww  w. j  a v  a 2s .co m*/
    } else {
        codec = null;
    }
    this.ifileReadAhead = conf.getBoolean(TezRuntimeConfiguration.TEZ_RUNTIME_IFILE_READAHEAD,
            TezRuntimeConfiguration.TEZ_RUNTIME_IFILE_READAHEAD_DEFAULT);
    if (this.ifileReadAhead) {
        this.ifileReadAheadLength = conf.getInt(TezRuntimeConfiguration.TEZ_RUNTIME_IFILE_READAHEAD_BYTES,
                TezRuntimeConfiguration.TEZ_RUNTIME_IFILE_READAHEAD_BYTES_DEFAULT);
    } else {
        this.ifileReadAheadLength = 0;
    }

    Combiner combiner = TezRuntimeUtils.instantiateCombiner(conf, inputContext);

    FileSystem localFS = FileSystem.getLocal(this.conf);
    LocalDirAllocator localDirAllocator = new LocalDirAllocator(TezRuntimeFrameworkConfigs.LOCAL_DIRS);

    // TODO TEZ Get rid of Map / Reduce references.
    TezCounter spilledRecordsCounter = inputContext.getCounters().findCounter(TaskCounter.SPILLED_RECORDS);
    TezCounter reduceCombineInputCounter = inputContext.getCounters()
            .findCounter(TaskCounter.COMBINE_INPUT_RECORDS);
    TezCounter mergedMapOutputsCounter = inputContext.getCounters().findCounter(TaskCounter.MERGED_MAP_OUTPUTS);

    LOG.info(srcNameTrimmed + ": " + "Shuffle assigned with " + numInputs + " inputs" + ", codec: "
            + (codec == null ? "None" : codec.getClass().getName()) + ", ifileReadAhead: " + ifileReadAhead);

    startTime = System.currentTimeMillis();
    merger = new MergeManager(this.conf, localFS, localDirAllocator, inputContext, combiner,
            spilledRecordsCounter, reduceCombineInputCounter, mergedMapOutputsCounter, this,
            initialMemoryAvailable, codec, ifileReadAhead, ifileReadAheadLength);

    scheduler = new ShuffleScheduler(this.inputContext, this.conf, numInputs, this, merger, merger, startTime,
            codec, ifileReadAhead, ifileReadAheadLength, srcNameTrimmed);

    this.mergePhaseTime = inputContext.getCounters().findCounter(TaskCounter.MERGE_PHASE_TIME);
    this.shufflePhaseTime = inputContext.getCounters().findCounter(TaskCounter.SHUFFLE_PHASE_TIME);

    eventHandler = new ShuffleInputEventHandlerOrderedGrouped(inputContext, scheduler,
            ShuffleUtils.isTezShuffleHandler(conf));

    ExecutorService rawExecutor = Executors.newFixedThreadPool(1, new ThreadFactoryBuilder().setDaemon(true)
            .setNameFormat("ShuffleAndMergeRunner {" + srcNameTrimmed + "}").build());

    executor = MoreExecutors.listeningDecorator(rawExecutor);
    runShuffleCallable = new RunShuffleCallable();
}

From source file:org.hawkular.metrics.core.service.MetricsServiceImpl.java

public void startUp(Session session, String keyspace, boolean resetDb, boolean createSchema,
        MetricRegistry metricRegistry) {
    session.execute("USE " + keyspace);
    log.infoKeyspaceUsed(keyspace);//from w w  w .  ja  v a2  s .c  o m
    metricsTasks = MoreExecutors
            .listeningDecorator(Executors.newFixedThreadPool(4, new MetricsThreadFactory()));
    loadDataRetentions();

    this.metricRegistry = metricRegistry;

    dataPointInserters = ImmutableMap
            .<MetricType<?>, Func2<? extends Metric<?>, Integer, Observable<Integer>>>builder()
            .put(GAUGE, (metric, ttl) -> {
                @SuppressWarnings("unchecked")
                Metric<Double> gauge = (Metric<Double>) metric;
                return dataAccess.insertGaugeData(gauge, ttl);
            }).put(AVAILABILITY, (metric, ttl) -> {
                @SuppressWarnings("unchecked")
                Metric<AvailabilityType> avail = (Metric<AvailabilityType>) metric;
                return dataAccess.insertAvailabilityData(avail, ttl);
            }).put(COUNTER, (metric, ttl) -> {
                @SuppressWarnings("unchecked")
                Metric<Long> counter = (Metric<Long>) metric;
                return dataAccess.insertCounterData(counter, ttl);
            }).put(COUNTER_RATE, (metric, ttl) -> {
                @SuppressWarnings("unchecked")
                Metric<Double> gauge = (Metric<Double>) metric;
                return dataAccess.insertGaugeData(gauge, ttl);
            }).put(STRING, (metric, ttl) -> {
                @SuppressWarnings("unchecked")
                Metric<String> string = (Metric<String>) metric;
                return dataAccess.insertStringData(string, ttl, maxStringSize);
            }).build();

    dataPointFinders = ImmutableMap
            .<MetricType<?>, Func5<? extends MetricId<?>, Long, Long, Integer, Order, Observable<Row>>>builder()
            .put(GAUGE, (metricId, start, end, limit, order) -> {
                @SuppressWarnings("unchecked")
                MetricId<Double> gaugeId = (MetricId<Double>) metricId;
                return dataAccess.findGaugeData(gaugeId, start, end, limit, order);
            }).put(AVAILABILITY, (metricId, start, end, limit, order) -> {
                @SuppressWarnings("unchecked")
                MetricId<AvailabilityType> availabilityId = (MetricId<AvailabilityType>) metricId;
                return dataAccess.findAvailabilityData(availabilityId, start, end, limit, order);
            }).put(COUNTER, (metricId, start, end, limit, order) -> {
                @SuppressWarnings("unchecked")
                MetricId<Long> counterId = (MetricId<Long>) metricId;
                return dataAccess.findCounterData(counterId, start, end, limit, order);
            }).put(STRING, (metricId, start, end, limit, order) -> {
                @SuppressWarnings("unchecked")
                MetricId<String> stringId = (MetricId<String>) metricId;
                return dataAccess.findStringData(stringId, start, end, limit, order);
            }).build();

    dataPointMappers = ImmutableMap.<MetricType<?>, Func1<Row, ? extends DataPoint<?>>>builder()
            .put(GAUGE, Functions::getGaugeDataPoint).put(AVAILABILITY, Functions::getAvailabilityDataPoint)
            .put(COUNTER, Functions::getCounterDataPoint).put(STRING, Functions::getStringDataPoint).build();

    initStringSize(session);
    initMetrics();
}

From source file:org.opendaylight.daexim.impl.DataExportImportAppProvider.java

/**
 * Method called when the blueprint container is created.
 *///  w  w  w  .  j  a va 2s . c  o m
public void init() {
    topII = InstanceIdentifier.create(Daexim.class);
    globalStatusII = InstanceIdentifier.create(Daexim.class).child(DaeximStatus.class);
    ipcII = InstanceIdentifier.create(Daexim.class).child(DaeximControl.class);
    nodeStatusII = InstanceIdentifier.create(Daexim.class).child(DaeximStatus.class).child(NodeStatus.class,
            new NodeStatusKey(nodeNameProvider.getNodeName()));
    ipcDTC = new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, ipcII);
    dataBroker.registerDataTreeChangeListener(ipcDTC,
            (ClusteredDataTreeChangeListener<DaeximControl>) changes -> {
                try {
                    ipcHandler(changes);
                } catch (TransactionCommitFailedException e) {
                    LOG.error("Failure while processing IPC request", e);
                }
            });
    checkDatastructures();
    scheduledExecutorService = MoreExecutors.listeningDecorator(Executors.newScheduledThreadPool(10,
            new ThreadFactoryBuilder().setNameFormat("daexim-scheduler-%d").build()));
    LOG.info("Daexim Session Initiated, running on node '{}'", nodeNameProvider.getNodeName());
}

From source file:org.apache.tez.runtime.library.broadcast.input.BroadcastShuffleManager.java

public BroadcastShuffleManager(TezInputContext inputContext, Configuration conf, int numInputs)
        throws IOException {
    this.inputContext = inputContext;
    this.conf = conf;
    this.numInputs = numInputs;

    if (ConfigUtils.isIntermediateInputCompressed(conf)) {
        Class<? extends CompressionCodec> codecClass = ConfigUtils.getIntermediateInputCompressorClass(conf,
                DefaultCodec.class);
        codec = ReflectionUtils.newInstance(codecClass, conf);
    } else {/*from w  w w. j  a  v a 2s .c om*/
        codec = null;
    }

    this.ifileReadAhead = conf.getBoolean(TezJobConfig.TEZ_RUNTIME_IFILE_READAHEAD,
            TezJobConfig.TEZ_RUNTIME_IFILE_READAHEAD_DEFAULT);
    if (this.ifileReadAhead) {
        this.ifileReadAheadLength = conf.getInt(TezJobConfig.TEZ_RUNTIME_IFILE_READAHEAD_BYTES,
                TezJobConfig.TEZ_RUNTIME_IFILE_READAHEAD_BYTES_DEFAULT);
    } else {
        this.ifileReadAheadLength = 0;
    }
    this.ifileBufferSize = conf.getInt("io.file.buffer.size",
            TezJobConfig.TEZ_RUNTIME_IFILE_BUFFER_SIZE_DEFAULT);

    this.inputManager = new BroadcastInputManager(inputContext.getUniqueIdentifier(), conf);
    this.inputEventHandler = new BroadcastShuffleInputEventHandler(inputContext, this, this.inputManager, codec,
            ifileReadAhead, ifileReadAheadLength);

    completedInputSet = Collections.newSetFromMap(new ConcurrentHashMap<InputIdentifier, Boolean>(numInputs));
    completedInputs = new LinkedBlockingQueue<FetchedInput>(numInputs);
    knownSrcHosts = new ConcurrentHashMap<String, InputHost>();
    pendingHosts = new LinkedBlockingQueue<InputHost>();
    obsoletedInputs = Collections.newSetFromMap(new ConcurrentHashMap<InputAttemptIdentifier, Boolean>());

    int maxConfiguredFetchers = conf.getInt(TezJobConfig.TEZ_RUNTIME_SHUFFLE_PARALLEL_COPIES,
            TezJobConfig.DEFAULT_TEZ_RUNTIME_SHUFFLE_PARALLEL_COPIES);

    this.numFetchers = Math.min(maxConfiguredFetchers, numInputs);

    this.fetcherRawExecutor = Executors.newFixedThreadPool(numFetchers, new ThreadFactoryBuilder()
            .setDaemon(true).setNameFormat("Fetcher [" + inputContext.getUniqueIdentifier() + "] #%d").build());
    this.fetcherExecutor = MoreExecutors.listeningDecorator(fetcherRawExecutor);

    this.schedulerRawExecutor = Executors.newFixedThreadPool(1, new ThreadFactoryBuilder().setDaemon(true)
            .setNameFormat("ShuffleRunner [" + inputContext.getUniqueIdentifier() + "]").build());
    this.schedulerExecutor = MoreExecutors.listeningDecorator(schedulerRawExecutor);

    this.startTime = System.currentTimeMillis();
    this.lastProgressTime = startTime;

    this.shuffleSecret = ShuffleUtils.getJobTokenSecretFromTokenBytes(
            inputContext.getServiceConsumerMetaData(ShuffleHandler.MAPREDUCE_SHUFFLE_SERVICEID));

    this.connectionTimeout = conf.getInt(TezJobConfig.TEZ_RUNTIME_SHUFFLE_CONNECT_TIMEOUT,
            TezJobConfig.DEFAULT_TEZ_RUNTIME_SHUFFLE_STALLED_COPY_TIMEOUT);
    this.readTimeout = conf.getInt(TezJobConfig.TEZ_RUNTIME_SHUFFLE_READ_TIMEOUT,
            TezJobConfig.DEFAULT_TEZ_RUNTIME_SHUFFLE_READ_TIMEOUT);

    LOG.info("BroadcastShuffleManager -> numInputs: " + numInputs + " compressionCodec: "
            + (codec == null ? "NoCompressionCodec" : codec.getClass().getName()) + ", numFetchers: "
            + numFetchers);
}