当前位置: 首页>>代码示例>>Java>>正文


Java Queues.newArrayBlockingQueue方法代码示例

本文整理汇总了Java中com.google.common.collect.Queues.newArrayBlockingQueue方法的典型用法代码示例。如果您正苦于以下问题:Java Queues.newArrayBlockingQueue方法的具体用法?Java Queues.newArrayBlockingQueue怎么用?Java Queues.newArrayBlockingQueue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.collect.Queues的用法示例。


在下文中一共展示了Queues.newArrayBlockingQueue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: FileReaderService

import com.google.common.collect.Queues; //导入方法依赖的package包/类
public FileReaderService(PathSet pathSet,
                         Charset charset,
                         FileInput.InitialReadPosition initialReadPosition,
                         FileInput input,
                         MessageBuilder messageBuilder,
                         ContentSplitter contentSplitter,
                         Buffer buffer,
                         int readerBufferSize,
                         long readerInterval,
                         FileObserver fileObserver) {
    this.pathSet = pathSet;
    this.initialReadPosition = initialReadPosition;
    this.input = input;
    this.messageBuilder = messageBuilder;
    this.contentSplitter = contentSplitter;
    this.buffer = buffer;
    this.charset = charset;
    this.readerBufferSize = readerBufferSize;
    this.readerInterval = readerInterval;
    this.fileObserver = fileObserver;
    chunkQueue = Queues.newArrayBlockingQueue(2);
}
 
开发者ID:DevOpsStudio,项目名称:Re-Collector,代码行数:23,代码来源:FileReaderService.java

示例2: NutchServer

import com.google.common.collect.Queues; //导入方法依赖的package包/类
private NutchServer() {
  configManager = new ConfManagerImpl();
  BlockingQueue<Runnable> runnables = Queues.newArrayBlockingQueue(JOB_CAPACITY);
  NutchServerPoolExecutor executor = new NutchServerPoolExecutor(10, JOB_CAPACITY, 1, TimeUnit.HOURS, runnables);
  jobManager = new JobManagerImpl(new JobFactory(), configManager, executor);
  fetchNodeDb = FetchNodeDb.getInstance();

  sf = new JAXRSServerFactoryBean();
  BindingFactoryManager manager = sf.getBus().getExtension(BindingFactoryManager.class);
  JAXRSBindingFactory factory = new JAXRSBindingFactory();
  factory.setBus(sf.getBus());
  manager.registerBindingFactory(JAXRSBindingFactory.JAXRS_BINDING_ID, factory);
  sf.setResourceClasses(getClasses());
  sf.setResourceProviders(getResourceProviders());
  sf.setProvider(new JacksonJaxbJsonProvider());

}
 
开发者ID:jorcox,项目名称:GeoCrawler,代码行数:18,代码来源:NutchServer.java

示例3: ConsumerBase

import com.google.common.collect.Queues; //导入方法依赖的package包/类
protected ConsumerBase(PulsarClientImpl client, String topic, String subscription, ConsumerConfiguration conf,
        int receiverQueueSize, ExecutorService listenerExecutor, CompletableFuture<Consumer> subscribeFuture) {
    super(client, topic, new Backoff(100, TimeUnit.MILLISECONDS, 60, TimeUnit.SECONDS, 0 , TimeUnit.MILLISECONDS));
    this.maxReceiverQueueSize = receiverQueueSize;
    this.subscription = subscription;
    this.conf = conf;
    this.consumerName = conf.getConsumerName() == null ? ConsumerName.generateRandomName() : conf.getConsumerName();
    this.subscribeFuture = subscribeFuture;
    this.listener = conf.getMessageListener();
    if (receiverQueueSize <= 1) {
        this.incomingMessages = Queues.newArrayBlockingQueue(1);
    } else {
        this.incomingMessages = new GrowableArrayBlockingQueue<>();
    }

    this.listenerExecutor = listenerExecutor;
    this.pendingReceives = Queues.newConcurrentLinkedQueue();
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:19,代码来源:ConsumerBase.java

示例4: log_errors

import com.google.common.collect.Queues; //导入方法依赖的package包/类
@Test
public void log_errors() {
    final CommandEnvelope commandEnvelope = givenCommandEnvelope();

    // Since we're in the tests mode `Environment` returns `SubstituteLogger` instance.
    final SubstituteLogger log = (SubstituteLogger) handler.log();

    // Restrict the queue size only to the number of calls we want to make.
    final Queue<SubstituteLoggingEvent> queue = Queues.newArrayBlockingQueue(1);
    log.setDelegate(new EventRecodingLogger(log, queue));

    SubstituteLoggingEvent loggingEvent;

    final RuntimeException exception = new RuntimeException("log_errors");
    handler.onError(commandEnvelope, exception);

    loggingEvent = queue.poll();

    assertEquals(Level.ERROR, loggingEvent.getLevel());
    assertEquals(commandEnvelope, handler.getLastErrorEnvelope());
    assertEquals(exception, handler.getLastException());
}
 
开发者ID:SpineEventEngine,项目名称:core-java,代码行数:23,代码来源:CommandHandlerShould.java

示例5: SelectDispatcher

import com.google.common.collect.Queues; //导入方法依赖的package包/类
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,
            new MetricRegistry(),
            new DefaultSampleProcessorService(1),
            new ContextConfigurations());

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

}
 
开发者ID:OpenNMS,项目名称:newts,代码行数:24,代码来源:SelectDispatcher.java

示例6: readPositionEnd

import com.google.common.collect.Queues; //导入方法依赖的package包/类
@Test
public void readPositionEnd() throws IOException, InterruptedException {
    final Utils.LogFile logFile = new Utils.LogFile(100 * 1024, 400, 100);
    logFile.close();
    final ArrayBlockingQueue<FileChunk> chunkQueue = Queues.newArrayBlockingQueue(1);
    final AsynchronousFileChannel channel = AsynchronousFileChannel.open(logFile.getPath(), StandardOpenOption.READ);
    final CountingAsyncFileChannel spy = new CountingAsyncFileChannel(channel);

    final ChunkReader chunkReader = new ChunkReader(mock(FileInput.class), logFile.getPath(), spy, chunkQueue, 10 * 1024,
            FileInput.InitialReadPosition.END, null);

    final ScheduledExecutorService chunkReaderExecutor = Executors.newSingleThreadScheduledExecutor(
            new ThreadFactoryBuilder()
                    .setDaemon(false)
                    .setNameFormat("file-chunk-reader-%d")
                    .setUncaughtExceptionHandler(this)
                    .build()
    );

    final Thread consumer = new Thread() {
        @Override
        public void run() {
            try {
                final FileChunk chunk = chunkQueue.poll(2, TimeUnit.SECONDS);
                assertNull("Reading from the end of the file must not produce a chunk for a non-changing file.", chunk);
            } catch (InterruptedException ignore) {
            }
        }
    };
    consumer.start();
    chunkReaderExecutor.scheduleAtFixedRate(chunkReader, 0, 250, TimeUnit.MILLISECONDS);
    consumer.join();

    // we can process one chunk at a time, so one read is queued, the second is buffered
    assertEquals("The e should be empty", 1, chunkQueue.remainingCapacity());
}
 
开发者ID:DevOpsStudio,项目名称:Re-Collector,代码行数:37,代码来源:ChunkReaderTest.java

示例7: testCreateQueue

import com.google.common.collect.Queues; //导入方法依赖的package包/类
/**
 * 创建队列
 */
@Test
public void testCreateQueue() {
    List<String> strList = Lists.newArrayListWithExpectedSize(128);

    // 创建ArrayBlockingQueue
    ArrayBlockingQueue<String> blockingQueue = Queues.newArrayBlockingQueue(128);

    // 创建LinkedBlockingQueue
    LinkedBlockingQueue<String> linkedBlockingQueue1 = Queues.newLinkedBlockingQueue();
    LinkedBlockingQueue<String> linkedBlockingQueue2 = Queues.newLinkedBlockingQueue(128);
    LinkedBlockingQueue<String> linkedBlockingQueue3 = Queues.newLinkedBlockingQueue(strList);

    // 创建LinkedBlockingDeque
    LinkedBlockingDeque<String> blockingDeque1 = Queues.newLinkedBlockingDeque();
    LinkedBlockingDeque<String> blockingDeque2 = Queues.newLinkedBlockingDeque(128);
    LinkedBlockingDeque<String> blockingDeque3 = Queues.newLinkedBlockingDeque(strList);

    // 创建ArrayDeque
    ArrayDeque<String> arrayDeque1 = Queues.newArrayDeque();
    ArrayDeque<String> arrayDeque2 = Queues.newArrayDeque(strList);

    // 创建ConcurrentLinkedQueue
    ConcurrentLinkedQueue<String> concurrentLinkedQueue1 = Queues.newConcurrentLinkedQueue();
    ConcurrentLinkedQueue<String> concurrentLinkedQueue2 = Queues.newConcurrentLinkedQueue(strList);

    // 创建PriorityBlockingQueue
    PriorityBlockingQueue<String> priorityBlockingQueue1 = Queues.newPriorityBlockingQueue();
    PriorityBlockingQueue<String> priorityBlockingQueue2 = Queues.newPriorityBlockingQueue(strList);

    // 创建PriorityQueue
    PriorityQueue<Comparable> priorityQueue1 = Queues.newPriorityQueue();
    PriorityQueue<Comparable> priorityQueue2 = Queues.newPriorityQueue(strList);

    // 创建SynchronousQueue
    SynchronousQueue<String> synchronousQueue = Queues.newSynchronousQueue();
}
 
开发者ID:cbooy,项目名称:cakes,代码行数:40,代码来源:QueuesDemo.java

示例8: ChunkRenderDispatcher

import com.google.common.collect.Queues; //导入方法依赖的package包/类
public ChunkRenderDispatcher(int countRenderBuilders)
{
    int i = Math.max(1, (int)((double)Runtime.getRuntime().maxMemory() * 0.3D) / 10485760);
    int j = Math.max(1, MathHelper.clamp_int(Runtime.getRuntime().availableProcessors(), 1, i / 5));
    if(countRenderBuilders < 0) countRenderBuilders = MathHelper.clamp_int(j * 10, 1, i);
    this.countRenderBuilders = countRenderBuilders;

    if (j > 1)
    {
        for (int k = 0; k < j; ++k)
        {
            ChunkRenderWorker chunkrenderworker = new ChunkRenderWorker(this);
            Thread thread = THREAD_FACTORY.newThread(chunkrenderworker);
            thread.start();
            this.listThreadedWorkers.add(chunkrenderworker);
            this.listWorkerThreads.add(thread);
        }
    }

    this.queueFreeRenderBuilders = Queues.<RegionRenderCacheBuilder>newArrayBlockingQueue(this.countRenderBuilders);

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

    this.renderWorker = new ChunkRenderWorker(this, new RegionRenderCacheBuilder());
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:29,代码来源:ChunkRenderDispatcher.java

示例9: assertAtLevel

import com.google.common.collect.Queues; //导入方法依赖的package包/类
private void assertAtLevel(Level level) {
    final LoggingObserver<Object> observer = getObserver(level);

    assertNotNull(observer);

    // Since we're in the tests mode `Environment` returns `SubstituteLogger` instance.
    final SubstituteLogger log = (SubstituteLogger) observer.log();

    // Restrict the queue size only to the number of calls we want to make.
    final Queue<SubstituteLoggingEvent> queue = Queues.newArrayBlockingQueue(3);
    log.setDelegate(new EventRecodingLogger(log, queue));

    SubstituteLoggingEvent loggingEvent;

    final String value = newUuid();
    observer.onNext(value);
    loggingEvent = queue.poll();
    assertNotNull(loggingEvent);
    assertLogLevel(loggingEvent, level);
    assertContains(loggingEvent, value);
    assertContains(loggingEvent, "onNext");

    final Timestamp currentTime = Time.getCurrentTime();
    final String timeStr = Timestamps.toString(currentTime);
    observer.onNext(currentTime);
    loggingEvent = queue.poll();
    assertNotNull(loggingEvent);
    assertLogLevel(loggingEvent, level);
    assertContains(loggingEvent, timeStr);

    observer.onCompleted();
    loggingEvent = queue.poll();
    assertNotNull(loggingEvent);
    assertLogLevel(loggingEvent, level);
    assertContains(loggingEvent, "onCompleted");
}
 
开发者ID:SpineEventEngine,项目名称:core-java,代码行数:37,代码来源:LoggingObserverShould.java

示例10: EmbeddedJetty

import com.google.common.collect.Queues; //导入方法依赖的package包/类
public EmbeddedJetty(boolean isDebugMode) {

		ArrayBlockingQueue<Runnable> queue = Queues.newArrayBlockingQueue(this.capability);
		pool = new QueuedThreadPool(this.maxThreads, this.minThreads, this.idleTimeout, queue);
		{
			pool.setName("jetty");
			pool.setDetailedDump(isDebugMode);
			pool.setStopTimeout(this.stopTimeout);
		}

		this.server = new Server(pool);
		this.server.setStopAtShutdown(true);

		// set default error page to empty
		if (false == isDebugMode) {
			this.server.addBean(emtpyErrorPage);
			emtpyErrorPage.setServer(this.server);

			this.server.setDumpAfterStart(false);
			this.server.setDumpBeforeStop(false);
		}

		this.httpConfig = new HttpConfiguration();
		{
			this.httpConfig.setSendServerVersion(false);
			this.httpConfig.setSendXPoweredBy(false);
			this.httpConfig.setSendDateHeader(true);
		}

		this.handlers = new HandlerCollection();
		this.server.setHandler(handlers);
	}
 
开发者ID:dohbot,项目名称:knives,代码行数:33,代码来源:EmbeddedJetty.java

示例11: setConfig

import com.google.common.collect.Queues; //导入方法依赖的package包/类
/**
 * 设置配置属性
 * 编译时接口
 * 各种配置属性的缺失,可以在该阶段快速发现
 *
 */
@Override
public void setConfig(StreamingConfig conf) throws StreamingException
{
    queue = Queues.newArrayBlockingQueue(DEFAULT_QUEUE_LENGTH);
    listenerPort = conf.getIntValue(StreamingConfig.OPERATOR_TCPSERVER_PORT);
    fixedLength = conf.getIntValue(StreamingConfig.OPERATOR_TCPSERVER_FIXEDLENGTH);
    this.config = conf;
}
 
开发者ID:HuaweiBigData,项目名称:StreamCQL,代码行数:15,代码来源:TCPWebInput.java

示例12: Service

import com.google.common.collect.Queues; //导入方法依赖的package包/类
public Service(String name, String logfile, Integer capacity, Boolean watchBufferEnabled) {
    this.setName(name);
    this.logfile = logfile;
    this.capacity = capacity;
    this.watchBufferEnabled = watchBufferEnabled;

    this.exitFlag = true;
    this.queue = Queues.newArrayBlockingQueue(capacity);
}
 
开发者ID:cshaxu,项目名称:nagini,代码行数:10,代码来源:Service.java

示例13: testCommandHistory

import com.google.common.collect.Queues; //导入方法依赖的package包/类
@Test
public void testCommandHistory() throws InterruptedException
{
    BlockingQueue<MockClient.InvokeDetails> results = Queues.newArrayBlockingQueue(1);
    MockClient client = new MockClient(results);
    client.command().history().invoke();

    MockClient.InvokeDetails details = results.poll(1, TimeUnit.SECONDS);
    Assert.assertNotNull(details);
    Assert.assertEquals(details.getAdditionalPaths(), new String[]{"commands"});
    Assert.assertEquals(details.getResponseType(), Commands.class);
    Assert.assertNull(details.getForPage());
}
 
开发者ID:qubole,项目名称:qds-sdk-java,代码行数:14,代码来源:TestRequestComposition.java

示例14: testCommandHistoryWithPaging

import com.google.common.collect.Queues; //导入方法依赖的package包/类
@Test
public void testCommandHistoryWithPaging() throws InterruptedException
{
    BlockingQueue<MockClient.InvokeDetails> results = Queues.newArrayBlockingQueue(1);
    MockClient client = new MockClient(results);
    client.command().history().forPage(10, 20).invoke();

    MockClient.InvokeDetails details = results.poll(1, TimeUnit.SECONDS);
    Assert.assertNotNull(details);
    Assert.assertEquals(details.getAdditionalPaths(), new String[]{"commands"});
    Assert.assertEquals(details.getResponseType(), Commands.class);
    Assert.assertEquals(details.getForPage(), new ForPage(10, 20));
}
 
开发者ID:qubole,项目名称:qds-sdk-java,代码行数:14,代码来源:TestRequestComposition.java

示例15: BoundedBlockingRecordQueue

import com.google.common.collect.Queues; //导入方法依赖的package包/类
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();
}
 
开发者ID:apache,项目名称:incubator-gobblin,代码行数:12,代码来源:BoundedBlockingRecordQueue.java


注:本文中的com.google.common.collect.Queues.newArrayBlockingQueue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。