Java Code Examples for com.google.common.collect.Queues#newArrayBlockingQueue()

The following examples show how to use com.google.common.collect.Queues#newArrayBlockingQueue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SelectDispatcher.java    From newts with Apache License 2.0 6 votes vote down vote up
SelectDispatcher(SelectConfig config) {
    super(config);

    m_config = config;

    CassandraSession session = new CassandraSessionImpl(
            config.getCassandraKeyspace(),
            config.getCassandraHost(),
            config.getCassandraPort(),
            config.getCassandraCompression(),
            config.getCassandraUsername(),
            config.getCassandraPassword(),
            config.getCassandraSsl());
    m_repository = new CassandraSampleRepository(
            session,
            Config.CASSANDRA_TTL,
            m_metricRegistry,
            new DefaultSampleProcessorService(1),
            new ContextConfigurations());

    m_queryQueue = Queues.newArrayBlockingQueue(config.getThreads() * 10);

}
 
Example 2
Source File: ChunkRenderDispatcherLitematica.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
public ChunkRenderDispatcherLitematica()
{
    int threadLimitMemory = Math.max(1, (int)((double)Runtime.getRuntime().maxMemory() * 0.15D) / 10485760);
    int threadLimitCPU = Math.max(1, MathHelper.clamp(Runtime.getRuntime().availableProcessors(), 1, threadLimitMemory / 5));
    this.countRenderBuilders = MathHelper.clamp(threadLimitCPU * 8, 1, threadLimitMemory);

    if (threadLimitCPU > 1)
    {
        Litematica.logger.info("Creating {} render threads", threadLimitCPU);

        for (int i = 0; i < threadLimitCPU; ++i)
        {
            ChunkRenderWorkerLitematica worker = new ChunkRenderWorkerLitematica(this);
            Thread thread = THREAD_FACTORY.newThread(worker);
            thread.start();
            this.listThreadedWorkers.add(worker);
            this.listWorkerThreads.add(thread);
        }
    }

    Litematica.logger.info("Using {} total BufferBuilder caches", this.countRenderBuilders + 1);

    this.queueFreeRenderBuilders = Queues.newArrayBlockingQueue(this.countRenderBuilders);

    for (int i = 0; i < this.countRenderBuilders; ++i)
    {
        this.queueFreeRenderBuilders.add(new BufferBuilderCache());
    }

    this.renderWorker = new ChunkRenderWorkerLitematica(this, new BufferBuilderCache());
}
 
Example 3
Source File: TessellatorCache.java    From ForgeHax with MIT License 5 votes vote down vote up
public TessellatorCache(int capacity, Supplier<E> supplier) {
  cache = Queues.newArrayBlockingQueue(capacity);
  
  // fill the cache
  for (int i = 0; i < capacity; i++) {
    cache.add(supplier.get());
  }
  
  // copy list of the original tessellators to prevent others from being added
  originals = ImmutableList.copyOf(cache);
}
 
Example 4
Source File: BoundedBlockingRecordQueue.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
private BoundedBlockingRecordQueue(Builder<T> builder) {
  Preconditions.checkArgument(builder.capacity > 0, "Invalid queue capacity");
  Preconditions.checkArgument(builder.timeout > 0, "Invalid timeout time");

  this.capacity = builder.capacity;
  this.timeout = builder.timeout;
  this.timeoutTimeUnit = builder.timeoutTimeUnit;
  this.blockingQueue = Queues.newArrayBlockingQueue(builder.capacity);

  this.queueStats = builder.ifCollectStats ? Optional.of(new QueueStats()) : Optional.<QueueStats> absent();
}
 
Example 5
Source File: StratumClient.java    From java-stratum with Apache License 2.0 4 votes vote down vote up
private ArrayBlockingQueue<StratumMessage> makeSubscriptionQueue() {
    return Queues.newArrayBlockingQueue(SUBSCRIPTION_QUEUE_CAPACITY);
}
 
Example 6
Source File: JobContextTest.java    From incubator-gobblin with Apache License 2.0 4 votes vote down vote up
public ControllableCallable(Either<T, Exception> toReturn, String name) {
  this.queue = Queues.newArrayBlockingQueue(1);
  this.queue.add(true);
  this.toReturn = toReturn;
  this.name = name;
}
 
Example 7
Source File: InsertDispatcher.java    From newts with Apache License 2.0 4 votes vote down vote up
InsertDispatcher(InsertConfig config) throws InterruptedException {
    super(config);

    m_config = config;

    CassandraSession session = new CassandraSessionImpl(
            config.getCassandraKeyspace(),
            config.getCassandraHost(),
            config.getCassandraPort(),
            config.getCassandraCompression(),
            config.getCassandraUsername(),
            config.getCassandraPassword(),
            config.getCassandraSsl());

    ContextConfigurations contexts = new ContextConfigurations();
    Set<SampleProcessor> processors = Sets.newHashSet();

    if (m_config.isSearchEnabled()) {
        ResourceIdSplitter resourceIdSplitter = new EscapableResourceIdSplitter();
        GuavaResourceMetadataCache cache = new GuavaResourceMetadataCache(m_config.getNumResources(), m_metricRegistry);
        CassandraIndexingOptions indexingOptions = new CassandraIndexingOptions.Builder()
                .withHierarchicalIndexing(m_config.isHierarchicalIndexingEnabled())
                .withMaxBatchSize(m_config.getBatchSize()).build();
        CassandraIndexer cassandraIndexer = new CassandraIndexer(session, Config.CASSANDRA_TTL,
                cache, m_metricRegistry, indexingOptions, resourceIdSplitter, contexts);
        CassandraIndexerSampleProcessor indexerSampleProcessor = new CassandraIndexerSampleProcessor(cassandraIndexer);
        processors.add(indexerSampleProcessor);
    }

    SampleProcessorService sampleProcessorService = new DefaultSampleProcessorService(m_config.getThreads(), processors);

    m_repository = new CassandraSampleRepository(
            session,
            Config.CASSANDRA_TTL,
            m_metricRegistry,
            sampleProcessorService,
            contexts);

    m_samplesQueue = Queues.newArrayBlockingQueue(config.getThreads() * 10);

}
 
Example 8
Source File: QueueRegistry.java    From termsuite-core with Apache License 2.0 3 votes vote down vote up
/**
 * Creates and registers a new {@link ArrayBlockingQueue} with given initial
 * capacity.
 *  
 * @param queueName
 * 			The name of the queue
 * @param capacity
 * 			The initial capacity of the queue
 * @return
 * 		the created and registered queue
 * 
 * @throws IllegalArgumentException if <code>queueName</code> is already registered.
 */
public BlockingQueue<CollectionDocument> registerQueue(String queueName, int capacity) {
	Preconditions.checkArgument(!registry.containsKey(queueName), "Queue %s already exists", queueName);
	ArrayBlockingQueue<CollectionDocument> q = Queues.newArrayBlockingQueue(capacity);
	registry.put(queueName, q);
	return q;
}
 
Example 9
Source File: ScannerSession.java    From datawave with Apache License 2.0 2 votes vote down vote up
public ScannerSession(String tableName, Set<Authorizations> auths, ResourceQueue delegator, int maxResults, Query settings, SessionOptions options,
                Collection<Range> ranges) {
    
    Preconditions.checkNotNull(options);
    Preconditions.checkNotNull(delegator);
    
    this.options = options;
    
    // build a stack of ranges
    this.ranges = new ConcurrentLinkedQueue<>();
    
    this.tableName = tableName;
    this.auths = auths;
    
    if (null != ranges && !ranges.isEmpty()) {
        List<Range> rangeList = Lists.newArrayList(ranges);
        Collections.sort(rangeList);
        
        this.ranges.addAll(ranges);
        lastRange = Iterables.getLast(rangeList);
        
    }
    
    resultQueue = Queues.newArrayBlockingQueue(maxResults);
    
    sessionDelegator = delegator;
    
    currentEntry = null;
    
    this.maxResults = maxResults;
    
    this.settings = settings;
    
    if (this.settings != null) {
        this.uncaughtExceptionHandler = this.settings.getUncaughtExceptionHandler();
    }
    
    // ensure we have an exception handler
    if (this.uncaughtExceptionHandler == null) {
        this.uncaughtExceptionHandler = new QueryUncaughtExceptionHandler();
    }
    
    delegatedResourceInitializer = RunningResource.class;
    
}