本文整理汇总了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);
}
示例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);
}
示例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"));
}
示例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();
}
示例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);
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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);
}
示例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);
}
示例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());
}
示例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);
}
示例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);
}
}
}
});
}
示例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();
}