Example usage for java.util.concurrent LinkedBlockingQueue LinkedBlockingQueue

List of usage examples for java.util.concurrent LinkedBlockingQueue LinkedBlockingQueue

Introduction

In this page you can find the example usage for java.util.concurrent LinkedBlockingQueue LinkedBlockingQueue.

Prototype

public LinkedBlockingQueue(Collection<? extends E> c) 

Source Link

Document

Creates a LinkedBlockingQueue with a capacity of Integer#MAX_VALUE , initially containing the elements of the given collection, added in traversal order of the collection's iterator.

Usage

From source file:com.mnt.base.stream.comm.PacketProcessorManager.java

protected PacketProcessorManager(int threadSize) {

    if (enablePacketCacheQueue) {
        int packetCacheQueueSize = BaseConfiguration.getIntProperty("packet_cache_queue_size", 10000);
        //streamPacketQueue = new LinkedBlockingQueue<StreamPacket>(packetCacheQueueSize);

        streamPacketQueueMap = new ConcurrentHashMap<Integer, BlockingQueue<StreamPacket>>();
        this.maxQueueMapSize = threadSize;

        this.pushAi = new AtomicLong(0);
        this.pollAi = new AtomicLong(0);

        for (int i = 0; i < this.maxQueueMapSize; i++) {
            streamPacketQueueMap.put(i, new LinkedBlockingQueue<StreamPacket>(packetCacheQueueSize));
        }/* ww w  .j av  a 2s .  co m*/

        threadSize = threadSize > 0 ? threadSize : 1; // at least one thread
        initProcessorThreads(threadSize);
    }

    initProcessorMap();
}

From source file:org.duracloud.mill.manifest.builder.ManifestBuilder.java

/**
 * /*w w  w .j a v  a 2 s  .co  m*/
 * @param account
 * @param contentStores
 * @param spaceList
 * @param manifestItemRepo
 * @param clean
 * @param dryRun
 * @param threads 
 */
public void init(String account, Collection<ContentStore> contentStores, List<String> spaceList, boolean clean,
        boolean dryRun, int threads) {
    this.account = account;
    this.contentStores = contentStores;
    this.spaceList = spaceList;
    this.clean = clean;
    this.dryRun = dryRun;

    if (this.executor != null) {
        this.executor.shutdownNow();
    }

    this.successes = 0;
    this.errors = 0;
    this.totalProcessed = 0;

    this.executor = new ThreadPoolExecutor(threads, threads, 0l, TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<Runnable>(500));

}

From source file:com.sm.replica.server.grizzly.ReplicaServerFilter.java

protected void init() {
    if (Runtime.getRuntime().availableProcessors() > maxThreads)
        this.maxThreads = Runtime.getRuntime().availableProcessors();
    if (maxQueue < maxThreads * 1000)
        maxQueue = maxThreads * 1000;/*from   w w w. j a  v  a2  s.  co m*/
    BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(maxQueue);
    threadPools = new ThreadPoolExecutor(maxThreads, maxThreads, 30, TimeUnit.SECONDS, queue,
            new ThreadPoolFactory("Replica"));
}

From source file:edu.umass.cs.gnsserver.activecode.ActiveCodeHandler.java

/**
 * Initializes an ActiveCodeHandler/*from w  ww . ja  v a 2  s  .  c o  m*/
 *
 * @param app
 * @param numProcesses
 * @param blacklistSeconds
 */
public ActiveCodeHandler(GNSApplicationInterface<?> app, int numProcesses, long blacklistSeconds) {
    clientPool = new ClientPool(app);
    // Get the ThreadFactory implementation to use
    ThreadFactory threadFactory = new ActiveCodeThreadFactory(clientPool);
    // Create the ThreadPoolExecutor
    executorPool = new ActiveCodeExecutor(numProcesses, numProcesses, 0, TimeUnit.SECONDS,
            new LinkedBlockingQueue<>(100),
            // new SynchronousQueue<Runnable>(),
            threadFactory, new ThreadPoolExecutor.DiscardPolicy());
    // Start the processes
    executorPool.prestartAllCoreThreads();
    // Blacklist init
    blacklist = new HashMap<>();
    this.blacklistSeconds = blacklistSeconds;
}

From source file:com.petpet.c3po.gatherer.LocalFileGatherer.java

/**
 * Creates a new gatherer./*w ww .  jav  a  2s .  c  o  m*/
 */
public LocalFileGatherer() {
    this.queue = new LinkedBlockingQueue<MetadataStream>(10000);
    this.ready = false;
}

From source file:com.olacabs.fabric.compute.sources.kafka.impl.Balancer.java

public void start() throws Exception {
    Map<Integer, HostPort> leaders = KafkaMetadataClient.findLeadersForPartitions(brokers, topic);
    if (leaders.isEmpty()) {
        throw new Exception("Could not find any leaders for any of the partitions in topic: " + topic);
    }//  w  ww .  j a  v  a  2s. c o m
    LOGGER.info("Number of leaders: {}", leaders.size());
    events = new LinkedBlockingQueue<>(leaders.size());
    KafkaConsumerBuilder consumerBuilder = KafkaConsumerBuilder.builder().brokers(brokers)
            .instanceId(HostUtils.hostname()).build();
    OffsetSource offsetSource = ZookeeperOffsetSource.builder().curatorFramework(curatorFramework)
            .objectMapper(objectMapper).topologyName(topologyName).topicName(topic).build();
    leaders.entrySet().forEach(entry -> {
        readers.put(entry.getKey(), KafkaMessageReader.builder().bufferSize(bufferSize)
                .consumerBuilder(consumerBuilder).events(events).offsetSource(offsetSource)
                .partition(entry.getKey()).startOffsetPickStrategy(startOffsetPickStrategy).topic(topic)
                .transactionManager(TransactionManager.builder().topic(topic).topologyName(topologyName)
                        .mapper(objectMapper).curator(curatorFramework).partition(entry.getKey()).build())
                .build());
        LOGGER.info("Created reader object for {}", topic);
    });
    readers.values().forEach(kafkaMessageReader -> {
        try {
            kafkaMessageReader.start();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    });
    KafkaReaderLeaderElector leaderElector = new KafkaReaderLeaderElector(topologyName, topic, readers,
            curatorFramework, objectMapper);
    leaderElector.start();
}

From source file:com.nlp.twitterstream.FilteredTwitterStream.java

/**
 * Authenticate via OAuth1 //from   w  w  w. j  av  a 2 s. co  m
 * @param consumerKey
 * @param consumerSecret
 * @param token
 * @param secret
 * @throws InterruptedException
 */
public void oauth(String consumerKey, String consumerSecret, String token, String secret)
        throws InterruptedException {

    queue = new LinkedBlockingQueue<String>(10000);

    // Create endpoints with track terms
    StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint();
    endpoint.trackTerms(Lists.newArrayList(TwitterStreamNLPConstants.trackTermsFilter));
    endpoint.languages(Lists.newArrayList(TwitterStreamNLPConstants.languagesFilter));

    Authentication auth = new OAuth1(consumerKey, consumerSecret, token, secret);

    // Create a new BasicClient. By default gzip is enabled.
    client = new ClientBuilder().hosts(Constants.STREAM_HOST).endpoint(endpoint).authentication(auth)
            .processor(new StringDelimitedProcessor(queue)).build();

    // Establish a connection
    client.connect();

    if (!isConnectionActive()) {
        handleReconnection();
    }
}

From source file:com.indeed.imhotep.web.config.SpringConfiguration.java

@Bean(destroyMethod = "shutdown")
public ExecutorService executorService() {
    return new ThreadPoolExecutor(3, 10, 30, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(100),
            new NamedThreadFactory("IQL-Worker"));
}

From source file:io.openmessaging.rocketmq.consumer.LocalMessageCache.java

LocalMessageCache(final DefaultMQPullConsumer rocketmqPullConsumer, final ClientConfig clientConfig) {
    consumeRequestCache = new LinkedBlockingQueue<>(clientConfig.getRmqPullMessageCacheCapacity());
    this.consumedRequest = new ConcurrentHashMap<>();
    this.pullOffsetTable = new ConcurrentHashMap<>();
    this.rocketmqPullConsumer = rocketmqPullConsumer;
    this.clientConfig = clientConfig;
    this.cleanExpireMsgExecutors = Executors
            .newSingleThreadScheduledExecutor(new ThreadFactoryImpl("OMS_CleanExpireMsgScheduledThread_"));
}

From source file:com.legstar.host.server.Engine.java

/**
 * Create the Engine for a maximum number of requests waiting to
 * be serviced./* w ww . ja v  a2s.  c  o  m*/
 * 
 * @param maxRequests maximum number of requests waiting to be
 *            serviced. Past this number, the engine will start rejecting
 *            the new requests.
 * @param workManager an implementation of a thread pool
 * @param poolManager a host connections pool manager
 * @param workFactory provides methods to create work items
 * @param takeTimeout maximum time (milliseconds) to wait for a pooled
 *            connection to become
 *            available
 */
public Engine(final int maxRequests, final WorkManager workManager, final ConnectionPoolManager poolManager,
        final WorkFactory workFactory, final int takeTimeout) {
    _requests = new LinkedBlockingQueue<LegStarRequest>(maxRequests);
    _isShuttingDown = false;
    _workManager = workManager;
    _poolManager = poolManager;
    _workFactory = workFactory;
    _takeTimeout = takeTimeout;
    _log.debug("Created engine instance:" + this);
}