本文整理汇总了Java中com.google.common.collect.Queues.newConcurrentLinkedQueue方法的典型用法代码示例。如果您正苦于以下问题:Java Queues.newConcurrentLinkedQueue方法的具体用法?Java Queues.newConcurrentLinkedQueue怎么用?Java Queues.newConcurrentLinkedQueue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.collect.Queues
的用法示例。
在下文中一共展示了Queues.newConcurrentLinkedQueue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Chunk
import com.google.common.collect.Queues; //导入方法依赖的package包/类
public Chunk(World worldIn, int x, int z)
{
this.storageArrays = new ExtendedBlockStorage[16];
this.blockBiomeArray = new byte[256];
this.precipitationHeightMap = new int[256];
this.updateSkylightColumns = new boolean[256];
this.chunkTileEntityMap = Maps.<BlockPos, TileEntity>newHashMap();
this.queuedLightChecks = 4096;
this.tileEntityPosQueue = Queues.<BlockPos>newConcurrentLinkedQueue();
this.entityLists = (ClassInheritanceMultiMap[])(new ClassInheritanceMultiMap[16]);
this.worldObj = worldIn;
this.xPosition = x;
this.zPosition = z;
this.heightMap = new int[256];
for (int i = 0; i < this.entityLists.length; ++i)
{
this.entityLists[i] = new ClassInheritanceMultiMap(Entity.class);
}
Arrays.fill((int[])this.precipitationHeightMap, (int) - 999);
Arrays.fill(this.blockBiomeArray, (byte) - 1);
}
示例2: 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();
}
示例3: ManagedLedgerImpl
import com.google.common.collect.Queues; //导入方法依赖的package包/类
public ManagedLedgerImpl(ManagedLedgerFactoryImpl factory, BookKeeper bookKeeper, MetaStore store,
ManagedLedgerConfig config, ScheduledExecutorService scheduledExecutor, OrderedSafeExecutor orderedExecutor,
final String name) {
this.factory = factory;
this.bookKeeper = bookKeeper;
this.config = config;
this.store = store;
this.name = name;
this.scheduledExecutor = scheduledExecutor;
this.executor = orderedExecutor;
TOTAL_SIZE_UPDATER.set(this, 0);
NUMBER_OF_ENTRIES_UPDATER.set(this, 0);
ENTRIES_ADDED_COUNTER_UPDATER.set(this, 0);
STATE_UPDATER.set(this, State.None);
this.ledgersStat = null;
this.mbean = new ManagedLedgerMBeanImpl(this);
this.entryCache = factory.getEntryCacheManager().getEntryCache(this);
this.waitingCursors = Queues.newConcurrentLinkedQueue();
this.uninitializedCursors = Maps.newHashMap();
this.updateCursorRateLimit = RateLimiter.create(1);
// Get the next rollover time. Add a random value upto 5% to avoid rollover multiple ledgers at the same time
this.maximumRolloverTimeMs = (long) (config.getMaximumRolloverTimeMs() * (1 + random.nextDouble() * 5 / 100.0));
}
示例4: addFunctions
import com.google.common.collect.Queues; //导入方法依赖的package包/类
/**
* Adds all function names and signatures to passed jar,
* adds all function names, their signatures and holders to {@link #functions}.
*
* @param jar jar where function to be added
* @param newFunctions collection of function holders, each contains function name, signature and holder.
*/
private void addFunctions(Map<String, Queue<String>> jar, List<FunctionHolder> newFunctions) {
for (FunctionHolder function : newFunctions) {
final String functionName = function.getName();
Queue<String> jarFunctions = jar.get(functionName);
if (jarFunctions == null) {
jarFunctions = Queues.newConcurrentLinkedQueue();;
jar.put(functionName, jarFunctions);
}
final String functionSignature = function.getSignature();
jarFunctions.add(functionSignature);
Map<String, DrillFuncHolder> signatures = functions.get(functionName);
if (signatures == null) {
signatures = Maps.newConcurrentMap();
functions.put(functionName, signatures);
}
signatures.put(functionSignature, function.getHolder());
}
}
示例5: testDeserializeFromSequenceFile
import com.google.common.collect.Queues; //导入方法依赖的package包/类
@Test(dependsOnMethods = "testSerializeToSequenceFile")
public void testDeserializeFromSequenceFile() throws IOException {
Queue<WorkUnitState> workUnitStates = Queues.newConcurrentLinkedQueue();
Closer closer = Closer.create();
try {
ParallelRunner parallelRunner = closer.register(new ParallelRunner(2, this.fs));
parallelRunner.deserializeFromSequenceFile(Text.class, WorkUnitState.class, new Path(this.outputPath, "seq1"),
workUnitStates);
parallelRunner.deserializeFromSequenceFile(Text.class, WorkUnitState.class, new Path(this.outputPath, "seq2"),
workUnitStates);
} catch (Throwable t) {
throw closer.rethrow(t);
} finally {
closer.close();
}
Assert.assertEquals(workUnitStates.size(), 2);
for (WorkUnitState workUnitState : workUnitStates) {
TestWatermark watermark = new Gson().fromJson(workUnitState.getActualHighWatermark(), TestWatermark.class);
Assert.assertTrue(watermark.getLongWatermark() == 10L || watermark.getLongWatermark() == 100L);
}
}
示例6: testDeserializeFromSequenceFile
import com.google.common.collect.Queues; //导入方法依赖的package包/类
@Test(dependsOnMethods = "testSerializeToSequenceFile")
public void testDeserializeFromSequenceFile() throws IOException {
Queue<WorkUnitState> workUnitStates = Queues.newConcurrentLinkedQueue();
Path seqPath1 = new Path(this.outputPath, "seq1");
Path seqPath2 = new Path(this.outputPath, "seq2");
try (ParallelRunner parallelRunner = new ParallelRunner(2, this.fs)) {
parallelRunner.deserializeFromSequenceFile(Text.class, WorkUnitState.class, seqPath1, workUnitStates, true);
parallelRunner.deserializeFromSequenceFile(Text.class, WorkUnitState.class, seqPath2, workUnitStates, true);
}
Assert.assertFalse(this.fs.exists(seqPath1));
Assert.assertFalse(this.fs.exists(seqPath2));
Assert.assertEquals(workUnitStates.size(), 2);
for (WorkUnitState workUnitState : workUnitStates) {
TestWatermark watermark = new Gson().fromJson(workUnitState.getActualHighWatermark(), TestWatermark.class);
Assert.assertTrue(watermark.getLongWatermark() == 10L || watermark.getLongWatermark() == 100L);
}
}
示例7: Chunk
import com.google.common.collect.Queues; //导入方法依赖的package包/类
public Chunk(World world, int i, int j) {
this.sections = new ChunkSection[16];
this.g = new byte[256];
this.h = new int[256];
this.i = new boolean[256];
this.tileEntities = Maps.newHashMap();
this.x = 4096;
this.y = Queues.newConcurrentLinkedQueue();
this.entitySlices = (List[]) (new List[16]); // Spigot
this.world = world;
this.locX = i;
this.locZ = j;
this.heightMap = new int[256];
for (int k = 0; k < this.entitySlices.length; ++k) {
this.entitySlices[k] = new org.bukkit.craftbukkit.util.UnsafeList(); // Spigot
}
Arrays.fill(this.h, -999);
Arrays.fill(this.g, (byte) -1);
// CraftBukkit start
this.bukkitChunk = new org.bukkit.craftbukkit.CraftChunk(this);
}
示例8: BattleRunner
import com.google.common.collect.Queues; //导入方法依赖的package包/类
public BattleRunner(Set<String> robocodeEnginePaths, String jvmArgs,
int numRounds, int battleFieldWidth, int battleFieldHeight) {
_commandMapping = new ConcurrentHashMap<Process, String>();
_allProcs = new LinkedList<Process>();
_numRounds = numRounds;
_battleFieldWidth = battleFieldWidth;
_battleFieldHeight = battleFieldHeight;
_jvmArgs = jvmArgs;
_threadPoolSize = robocodeEnginePaths.size();
_threadPool = Executors.newFixedThreadPool(_threadPoolSize);
_callbackPool = Executors.newFixedThreadPool(1);
_processQueue = Queues.newConcurrentLinkedQueue();
for (String enginePath : robocodeEnginePaths) {
initEngine(enginePath, jvmArgs);
}
}
示例9: waitForCompletion
import com.google.common.collect.Queues; //导入方法依赖的package包/类
public void waitForCompletion() throws MultipleBuildOperationFailures {
waitingForCompletion.set(true);
CountDownLatch finished = new CountDownLatch(operations.size());
Queue<Throwable> failures = Queues.newConcurrentLinkedQueue();
for (QueuedOperation operation : operations) {
if (operation.future.isCancelled()) {
// If it's canceled, we'll never get a callback, so we just remove it from
// operations we're waiting for.
finished.countDown();
} else {
Futures.addCallback(operation.future, new CompletionCallback(finished, failures));
}
}
try {
finished.await();
} catch (InterruptedException e) {
throw UncheckedException.throwAsUncheckedException(e);
}
// all operations are complete, check for errors
if (!failures.isEmpty()) {
throw new MultipleBuildOperationFailures(getFailureMessage(failures), failures, logLocation);
}
}
示例10: 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();
}
示例11: inCompletionOrder
import com.google.common.collect.Queues; //导入方法依赖的package包/类
/**
* Returns a list of delegate futures that correspond to the futures received in the order that
* they complete. Delegate futures return the same value or throw the same exception as the
* corresponding input future returns/throws.
*
* <p>Cancelling a delegate future has no effect on any input future, since the delegate future
* does not correspond to a specific input future until the appropriate number of input futures
* have completed. At that point, it is too late to cancel the input future. The input future's
* result, which cannot be stored into the cancelled delegate future, is ignored.
*
* @since 17.0
*/
@Beta
@GwtIncompatible // TODO
public static <T> ImmutableList<ListenableFuture<T>> inCompletionOrder(
Iterable<? extends ListenableFuture<? extends T>> futures) {
// A CLQ may be overkill here. We could save some pointers/memory by synchronizing on an
// ArrayDeque
final ConcurrentLinkedQueue<SettableFuture<T>> delegates = Queues.newConcurrentLinkedQueue();
ImmutableList.Builder<ListenableFuture<T>> listBuilder = ImmutableList.builder();
// Using SerializingExecutor here will ensure that each CompletionOrderListener executes
// atomically and therefore that each returned future is guaranteed to be in completion order.
// N.B. there are some cases where the use of this executor could have possibly surprising
// effects when input futures finish at approximately the same time _and_ the output futures
// have directExecutor listeners. In this situation, the listeners may end up running on a
// different thread than if they were attached to the corresponding input future. We believe
// this to be a negligible cost since:
// 1. Using the directExecutor implies that your callback is safe to run on any thread.
// 2. This would likely only be noticeable if you were doing something expensive or blocking on
// a directExecutor listener on one of the output futures which is an antipattern anyway.
SerializingExecutor executor = new SerializingExecutor(directExecutor());
for (final ListenableFuture<? extends T> future : futures) {
SettableFuture<T> delegate = SettableFuture.create();
// Must make sure to add the delegate to the queue first in case the future is already done
delegates.add(delegate);
future.addListener(
new Runnable() {
@Override
public void run() {
delegates.remove().setFuture(future);
}
},
executor);
listBuilder.add(delegate);
}
return listBuilder.build();
}
示例12: Session
import com.google.common.collect.Queues; //导入方法依赖的package包/类
public Session(Channel channel, InetSocketAddress address) {
this.packetQueue = Queues.newConcurrentLinkedQueue();
this.datagramSequenceNumber = new AtomicInteger();
this.messageNumber = new AtomicInteger();
this.state = State.NOT_CONNECTED;
this.address = address;
this.channel = channel;
this.receipts = new ConcurrentHashMap<>();
PocketServer.getInstance().getLogger().debug("Created session for {}", address);
}
示例13: inCompletionOrder
import com.google.common.collect.Queues; //导入方法依赖的package包/类
/**
* Returns a list of delegate futures that correspond to the futures received in the order that
* they complete. Delegate futures return the same value or throw the same exception as the
* corresponding input future returns/throws.
*
* <p>Cancelling a delegate future has no effect on any input future, since the delegate future
* does not correspond to a specific input future until the appropriate number of input futures
* have completed. At that point, it is too late to cancel the input future. The input future's
* result, which cannot be stored into the cancelled delegate future, is ignored.
*
* @since 17.0
*/
@Beta
@GwtIncompatible // TODO
public static <T> ImmutableList<ListenableFuture<T>> inCompletionOrder(Iterable<? extends ListenableFuture<? extends T>> futures) {
// A CLQ may be overkill here. We could save some pointers/memory by synchronizing on an
// ArrayDeque
final ConcurrentLinkedQueue<SettableFuture<T>> delegates = Queues.newConcurrentLinkedQueue();
ImmutableList.Builder<ListenableFuture<T>> listBuilder = ImmutableList.builder();
// Using SerializingExecutor here will ensure that each CompletionOrderListener executes
// atomically and therefore that each returned future is guaranteed to be in completion order.
// N.B. there are some cases where the use of this executor could have possibly surprising
// effects when input futures finish at approximately the same time _and_ the output futures
// have directExecutor listeners. In this situation, the listeners may end up running on a
// different thread than if they were attached to the corresponding input future. We believe
// this to be a negligible cost since:
// 1. Using the directExecutor implies that your callback is safe to run on any thread.
// 2. This would likely only be noticeable if you were doing something expensive or blocking on
// a directExecutor listener on one of the output futures which is an antipattern anyway.
SerializingExecutor executor = new SerializingExecutor(directExecutor());
for (final ListenableFuture<? extends T> future : futures) {
SettableFuture<T> delegate = SettableFuture.create();
// Must make sure to add the delegate to the queue first in case the future is already done
delegates.add(delegate);
future.addListener(
new Runnable() {
@Override
public void run() {
delegates.remove().setFuture(future);
}
},
executor);
listBuilder.add(delegate);
}
return listBuilder.build();
}
示例14: AbstractCommandRouter
import com.google.common.collect.Queues; //导入方法依赖的package包/类
AbstractCommandRouter(CommandBus commandBus,
Message commandMessage,
CommandContext commandContext) {
this.commandBus = checkNotNull(commandBus);
checkNotNull(commandMessage);
checkNotNull(commandContext);
this.source = asCommand(commandMessage, commandContext);
this.queue = Queues.newConcurrentLinkedQueue();
}
示例15: collectOutputTaskStates
import com.google.common.collect.Queues; //导入方法依赖的package包/类
/**
* Collect the output {@link TaskState}s of the job as a list.
*/
private List<TaskState> collectOutputTaskStates(Path taskStatePath) throws IOException {
if (!this.fs.exists(taskStatePath)) {
LOG.warn(String.format("Task state output path %s does not exist", taskStatePath));
return ImmutableList.of();
}
FileStatus[] fileStatuses = this.fs.listStatus(taskStatePath, new PathFilter() {
@Override
public boolean accept(Path path) {
return path.getName().endsWith(TASK_STATE_STORE_TABLE_SUFFIX);
}
});
if (fileStatuses == null || fileStatuses.length == 0) {
LOG.warn("No task state files found in " + taskStatePath);
return ImmutableList.of();
}
Queue<TaskState> taskStateQueue = Queues.newConcurrentLinkedQueue();
Closer closer = Closer.create();
try {
ParallelRunner parallelRunner = closer.register(new ParallelRunner(this.parallelRunnerThreads, this.fs));
for (FileStatus status : fileStatuses) {
parallelRunner.deserializeFromSequenceFile(Text.class, TaskState.class, status.getPath(), taskStateQueue);
}
} catch (Throwable t) {
throw closer.rethrow(t);
} finally {
closer.close();
}
LOG.info(String.format("Collected task state of %d completed tasks", taskStateQueue.size()));
return ImmutableList.copyOf(taskStateQueue);
}