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


Java Queues.newLinkedBlockingQueue方法代码示例

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


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

示例1: EventReporter

import com.google.common.collect.Queues; //导入方法依赖的package包/类
public EventReporter(Builder builder) {
  super(builder.context, builder.name, builder.filter, builder.rateUnit, builder.durationUnit);

  this.closer = Closer.create();
  this.immediateReportExecutor = MoreExecutors.
      getExitingExecutorService((ThreadPoolExecutor) Executors.newFixedThreadPool(1,
          ExecutorsUtils.newThreadFactory(Optional.of(LOGGER), Optional.of("EventReporter-" + builder.name + "-%d"))),
          5, TimeUnit.MINUTES);

  this.metricContext = builder.context;
  this.notificationTargetKey = builder.context.addNotificationTarget(new Function<Notification, Void>() {
    @Nullable
    @Override
    public Void apply(Notification notification) {
      notificationCallback(notification);
      return null;
    }
  });
  this.reportingQueue = Queues.newLinkedBlockingQueue(QUEUE_CAPACITY);
}
 
开发者ID:Hanmourang,项目名称:Gobblin,代码行数:21,代码来源:EventReporter.java

示例2: EventReporter

import com.google.common.collect.Queues; //导入方法依赖的package包/类
public EventReporter(Builder builder) {
  super(builder.context, builder.name, builder.filter, builder.rateUnit, builder.durationUnit);

  this.closer = Closer.create();
  this.immediateReportExecutor = MoreExecutors.getExitingExecutorService(
      (ThreadPoolExecutor) Executors.newFixedThreadPool(1,
          ExecutorsUtils.newThreadFactory(Optional.of(LOGGER), Optional.of("EventReporter-" + builder.name + "-%d"))),
      5, TimeUnit.MINUTES);

  this.metricContext = builder.context;
  this.notificationTargetKey = builder.context.addNotificationTarget(new Function<Notification, Void>() {
    @Nullable
    @Override
    public Void apply(Notification notification) {
      notificationCallback(notification);
      return null;
    }
  });
  this.reportingQueue = Queues.newLinkedBlockingQueue(QUEUE_CAPACITY);
}
 
开发者ID:apache,项目名称:incubator-gobblin,代码行数:21,代码来源:EventReporter.java

示例3: MessageBuffer

import com.google.common.collect.Queues; //导入方法依赖的package包/类
@Inject
public MessageBuffer(MessageBufferConfiguration config, MetricRegistry metricRegistry) {
    this.metricRegistry = metricRegistry;
    this.queue = Queues.newLinkedBlockingQueue(config.getSize());

    this.inserted = metricRegistry.meter(name(getClass(), "inserted"));
    this.removed = metricRegistry.meter(name(getClass(), "removed"));
}
 
开发者ID:DevOpsStudio,项目名称:Re-Collector,代码行数:9,代码来源:MessageBuffer.java

示例4: 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

示例5: getDStream

import com.google.common.collect.Queues; //导入方法依赖的package包/类
@Override
public JavaDStream<Long> getDStream() throws Exception {
  List<Long> list = Lists.newArrayList();
  for (int i = 0; i < rowsPerBatch; i++) {
    list.add(counter++);
  }
  JavaRDD<Long> longs = Contexts.getJavaStreamingContext().sparkContext().parallelize(list);
  Queue<JavaRDD<Long>> queue = Queues.newLinkedBlockingQueue();
  queue.add(longs);
  LOG.info("Created stream queue with {} rows", list.size());
  return Contexts.getJavaStreamingContext().queueStream(queue, true);
}
 
开发者ID:cloudera-labs,项目名称:envelope,代码行数:13,代码来源:DummyStreamInput.java

示例6: testDuplicateCacheRemovalCase1

import com.google.common.collect.Queues; //导入方法依赖的package包/类
/**
 * Test that duplicate cache flushes are filtered by
 * DistributedCacheManagerDecorator.CacheMessageSendingTransactionSynchronization.exhaustQueue(...)
 * to just the unique set, and that individual cache entry flushes  are filtered if the containing caches are also
 * being flushed in their entirety.
 */
@Test
public void testDuplicateCacheRemovalCase1() {

    // duplicate caches, we expect these to be filtered to the unique set
    Queue<CacheTarget> targets = Queues.newLinkedBlockingQueue(); 
    targets.add(CacheTarget.entireCache(ROLE_RESPONSIBILITY_CACHE));
    targets.add(CacheTarget.entireCache(ROLE_RESPONSIBILITY_CACHE));
    targets.add(CacheTarget.entireCache(ROLE_TYPE_CACHE));
    targets.add(CacheTarget.entireCache(ROLE_TYPE_CACHE));
    targets.add(CacheTarget.entireCache(DELEGATE_TYPE_CACHE));
    targets.add(CacheTarget.entireCache(DELEGATE_TYPE_CACHE));
    targets.add(CacheTarget.entireCache(ROLE_MEMBER_TYPE));
    targets.add(CacheTarget.entireCache(ROLE_MEMBER_TYPE));
    targets.add(CacheTarget.entireCache(PERMISSION_TYPE));
    targets.add(CacheTarget.entireCache(PERMISSION_TYPE));

    // specific cache entries by key.  We expect these all to be filtered out because the entire caches
    // are being flushed based on the targets added above.
    targets.add(CacheTarget.singleEntry(ROLE_MEMBER_TYPE, "key1"));
    targets.add(CacheTarget.singleEntry(ROLE_MEMBER_TYPE, "key2"));
    targets.add(CacheTarget.singleEntry(ROLE_RESPONSIBILITY_CACHE, "key3"));
    targets.add(CacheTarget.singleEntry(ROLE_RESPONSIBILITY_CACHE, "key4"));

    // the expected result is the unique set of caches from targets
    ArrayList<CacheTarget> correctResults = Lists.newArrayList(
            CacheTarget.entireCache(ROLE_RESPONSIBILITY_CACHE),
            CacheTarget.entireCache(ROLE_MEMBER_TYPE),
            CacheTarget.entireCache(ROLE_TYPE_CACHE),
            CacheTarget.entireCache(DELEGATE_TYPE_CACHE),
            CacheTarget.entireCache(PERMISSION_TYPE));

    Collection<CacheTarget> results = new ArrayList<CacheTarget>(invokeExhaustQueue(targets));
    assertTrue(CollectionUtils.diff(correctResults, results).isEmpty());
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:41,代码来源:DistributedCacheManagerDecoratorTest.java

示例7: testDuplicateCacheRemovalCase2

import com.google.common.collect.Queues; //导入方法依赖的package包/类
/**
 * Test that duplicate cache flushes are filtered by
 * DistributedCacheManagerDecorator.CacheMessageSendingTransactionSynchronization.exhaustQueue(...)
 * to just the unique set, and that duplicate cache entry flushes are filtered to just the unique set as well.
 */
@Test
public void testDuplicateCacheRemovalCase2() {
    Queue<CacheTarget> targets = Queues.newLinkedBlockingQueue();

    // duplicate caches, we expect these to be filtered to the unique set
    targets.add(CacheTarget.entireCache(ROLE_TYPE_CACHE));
    targets.add(CacheTarget.entireCache(ROLE_TYPE_CACHE));
    targets.add(CacheTarget.entireCache(DELEGATE_TYPE_CACHE));
    targets.add(CacheTarget.entireCache(DELEGATE_TYPE_CACHE));
    targets.add(CacheTarget.entireCache(PERMISSION_TYPE));
    targets.add(CacheTarget.entireCache(PERMISSION_TYPE));

    // cache entries -- we expect no filtering, since (1) the caches these entries are in are not being
    // flushed in their entirety, and (2) the cache + key combinations are unique
    targets.add(CacheTarget.singleEntry(ROLE_MEMBER_TYPE, "key1"));
    targets.add(CacheTarget.singleEntry(ROLE_MEMBER_TYPE, "key2"));
    targets.add(CacheTarget.singleEntry(ROLE_RESPONSIBILITY_CACHE, "key3"));
    targets.add(CacheTarget.singleEntry(ROLE_RESPONSIBILITY_CACHE, "key4"));

    // the expected result is the unique set of caches, and each of the specified cache entries
    ArrayList<CacheTarget> correctResults = Lists.newArrayList(
            CacheTarget.entireCache(ROLE_TYPE_CACHE),
            CacheTarget.entireCache(DELEGATE_TYPE_CACHE),
            CacheTarget.entireCache(PERMISSION_TYPE),
            CacheTarget.singleEntry(ROLE_MEMBER_TYPE, "key1"),
            CacheTarget.singleEntry(ROLE_MEMBER_TYPE, "key2"),
            CacheTarget.singleEntry(ROLE_RESPONSIBILITY_CACHE, "key3"),
            CacheTarget.singleEntry(ROLE_RESPONSIBILITY_CACHE, "key4"));

    Collection<CacheTarget> results = new ArrayList<CacheTarget>(invokeExhaustQueue(targets));
    assertTrue(CollectionUtils.diff(correctResults, results).isEmpty());
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:38,代码来源:DistributedCacheManagerDecoratorTest.java

示例8: testDuplicateCacheRemovalCase3

import com.google.common.collect.Queues; //导入方法依赖的package包/类
/**
 * Test that duplicate cache flushes are filtered by
 * DistributedCacheManagerDecorator.CacheMessageSendingTransactionSynchronization.exhaustQueue(...)
 * to just the unique set, and that duplicate cache entry flushes are filtered to just the unique set as well.
 */
@Test
public void testDuplicateCacheRemovalCase3() {
    Queue<CacheTarget> targets = Queues.newLinkedBlockingQueue();

    // duplicate caches, we expect these to be filtered to the unique set
    targets.add(CacheTarget.entireCache(ROLE_TYPE_CACHE));
    targets.add(CacheTarget.entireCache(ROLE_TYPE_CACHE));
    targets.add(CacheTarget.entireCache(DELEGATE_TYPE_CACHE));
    targets.add(CacheTarget.entireCache(DELEGATE_TYPE_CACHE));
    targets.add(CacheTarget.entireCache(PERMISSION_TYPE));
    targets.add(CacheTarget.entireCache(PERMISSION_TYPE));

    // duplicate cache entries, we expect these to be filtered down to the unique set.
    targets.add(CacheTarget.singleEntry(ROLE_MEMBER_TYPE, "key1"));
    targets.add(CacheTarget.singleEntry(ROLE_MEMBER_TYPE, "key1"));
    targets.add(CacheTarget.singleEntry(ROLE_RESPONSIBILITY_CACHE, "key2"));
    targets.add(CacheTarget.singleEntry(ROLE_RESPONSIBILITY_CACHE, "key2"));

    // the expected result is the unique set of caches, and the unique set of specified cache entries
    ArrayList<CacheTarget> correctResults = Lists.newArrayList(
            CacheTarget.entireCache(ROLE_TYPE_CACHE), 
            CacheTarget.entireCache(DELEGATE_TYPE_CACHE),
            CacheTarget.entireCache(PERMISSION_TYPE), 
            CacheTarget.singleEntry(ROLE_MEMBER_TYPE, "key1"),
            CacheTarget.singleEntry(ROLE_RESPONSIBILITY_CACHE, "key2"));

    Collection<CacheTarget> results = new ArrayList<CacheTarget>(invokeExhaustQueue(targets));
    assertTrue(CollectionUtils.diff(correctResults, results).isEmpty());
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:35,代码来源:DistributedCacheManagerDecoratorTest.java

示例9: AsyncAppender

import com.google.common.collect.Queues; //导入方法依赖的package包/类
private AsyncAppender(Appender<ILoggingEvent> delegate) {
    this.delegate = delegate;
    this.queue = Queues.newLinkedBlockingQueue();
    this.batch = Lists.newArrayListWithCapacity(BATCH_SIZE);
    this.dispatcher = THREAD_FACTORY.newThread(this);
    setContext(delegate.getContext());
}
 
开发者ID:bither,项目名称:bither-desktop-java,代码行数:8,代码来源:AsyncAppender.java

示例10: serviceInit

import com.google.common.collect.Queues; //导入方法依赖的package包/类
@Override
public void serviceInit(Configuration conf) throws Exception {

  this.systemConf = TUtil.checkTypeAndGet(conf, TajoConf.class);
  this.rpcParams = RpcParameterFactory.get(this.systemConf);
  this.heartBeatRequestQueue = Queues.newLinkedBlockingQueue();
  this.serviceTracker = ServiceTrackerFactory.get(systemConf);
  this.workerContext.getNodeResourceManager().getDispatcher().register(NodeStatusEvent.EventType.class, this);
  this.heartBeatInterval = systemConf.getIntVar(TajoConf.ConfVars.WORKER_HEARTBEAT_IDLE_INTERVAL);
  this.updaterThread = new StatusUpdaterThread();
  this.updaterThread.setName("NodeStatusUpdater");
  super.serviceInit(conf);
}
 
开发者ID:apache,项目名称:tajo,代码行数:14,代码来源:NodeStatusUpdater.java

示例11: MockKafkaStream

import com.google.common.collect.Queues; //导入方法依赖的package包/类
public MockKafkaStream(int numStreams) {

    this.queues = Lists.newArrayList();
    this.mockStreams = Lists.newArrayList();
    this.offsets = Lists.newArrayList();

    for (int i = 0; i < numStreams; i++) {
      BlockingQueue<FetchedDataChunk> queue = Queues.newLinkedBlockingQueue();
      this.queues.add(queue);
      this.mockStreams.add(createMockStream(queue));
      this.offsets.add(new AtomicLong(0));
    }

    this.nextStream = new AtomicLong(-1);
  }
 
开发者ID:apache,项目名称:incubator-gobblin,代码行数:16,代码来源:MockKafkaStream.java

示例12: UnfiredCandidateActions

import com.google.common.collect.Queues; //导入方法依赖的package包/类
@Inject
UnfiredCandidateActions(BrowserConfiguration config, Provider<StateFlowGraph> sfg,
        MetricRegistry registry) {
	this.sfg = sfg;
	cache = Maps.newHashMap();
	statesWithCandidates = Queues.newLinkedBlockingQueue();
	// Every browser gets a lock.
	locks = Striped.lock(config.getNumberOfBrowsers());

	crawlerLostCount =
	        registry.register(MetricsModule.EVENTS_PREFIX + "crawler_lost", new Counter());
	unfiredActionsCount =
	        registry.register(MetricsModule.EVENTS_PREFIX + "unfired_actions", new Counter());
}
 
开发者ID:aminmf,项目名称:crawljax,代码行数:15,代码来源:UnfiredCandidateActions.java

示例13: BatchingAsyncFunction

import com.google.common.collect.Queues; //导入方法依赖的package包/类
private BatchingAsyncFunction(int batchSize, long timeout, TimeUnit timeoutUnit, Executor executor, Function<? super ImmutableList<I>, ? extends Iterable<? extends ListenableFuture<O>>> batchConsumer) {
  this.batchSize = batchSize;
  this.timeout = timeout;
  this.timeoutUnit = timeoutUnit;
  this.executor = executor;
  this.batchConsumer = batchConsumer;
  queue = Queues.newLinkedBlockingQueue(batchSize);
}
 
开发者ID:joshng,项目名称:papaya,代码行数:9,代码来源:BatchingAsyncFunction.java

示例14: initialise

import com.google.common.collect.Queues; //导入方法依赖的package包/类
@Override
public void initialise() {
    world = CoreRegistry.get(WorldProvider.class);
    air = BlockManager.getInstance().getAir();
    grass = BlockManager.getInstance().getBlock("engine:grass");
    dirt = BlockManager.getInstance().getBlock("engine:dirt");
    blockQueue = Queues.newLinkedBlockingQueue();
    running.set(true);

    executor = Executors.newFixedThreadPool(1);
    executor.execute(new Runnable() {
        @Override
        public void run() {
            Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
            while (running.get()) {
                try {
                    Vector3i blockPos = blockQueue.take();
                    if (world.isBlockActive(blockPos)) {
                        if (simulate(blockPos)) {
                            Thread.sleep(5000);
                        }
                    }
                } catch (InterruptedException e) {
                    logger.debug("Thread Interrupted", e);
                }
            }
        }
    });
}
 
开发者ID:zoneXcoding,项目名称:Mineworld,代码行数:30,代码来源:GrowthSimulator.java

示例15: ReplicaClient

import com.google.common.collect.Queues; //导入方法依赖的package包/类
public ReplicaClient(Client client) {
    this.client = client;
    this.inUse = new AtomicBoolean(false);
    requestBlockingQueue = Queues.newLinkedBlockingQueue();

    new Thread(new Runnable() {
        @Override
        public void run() {
            while(true) {
                Request<?> request = Uninterruptibles.takeUninterruptibly(requestBlockingQueue);
                request.process(ReplicaClient.this);
            }
        }
    }).start();
}
 
开发者ID:pbailis,项目名称:hat-vldb2014-code,代码行数:16,代码来源:QuorumReplicaRouter.java


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