java.util.concurrent.ConcurrentLinkedDeque Java Examples
The following examples show how to use
java.util.concurrent.ConcurrentLinkedDeque.
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 Project: moleculer-java Author: moleculer-java File: WrongOrderTransporter.java License: MIT License | 6 votes |
public void run() { synchronized (channels) { for (Map.Entry<String, ConcurrentLinkedDeque<Tree>> entry : channels.entrySet()) { String channel = entry.getKey(); if (!channel.startsWith(nodeID + ':')) { continue; } int i = channel.indexOf(':'); channel = channel.substring(i + 1); ConcurrentLinkedDeque<Tree> queue = entry.getValue(); while (!queue.isEmpty()) { Tree message = queue.removeLast(); try { received(channel, serializer.write(message)); } catch (Exception cause) { logger.error("Unable to serialize message!", cause); } } } } }
Example #2
Source Project: quarkus-http Author: quarkusio File: JDBCLogHandler.java License: Apache License 2.0 | 6 votes |
public JDBCLogHandler(final HttpHandler next, final String formatString, DataSource dataSource) { this.next = next; this.formatString = formatString; this.dataSource = dataSource; tableName = "access"; remoteHostField = "remoteHost"; userField = "userName"; timestampField = "timestamp"; virtualHostField = "virtualHost"; methodField = "method"; queryField = "query"; statusField = "status"; bytesField = "bytes"; refererField = "referer"; userAgentField = "userAgent"; this.pendingMessages = new ConcurrentLinkedDeque<>(); }
Example #3
Source Project: DDMQ Author: didi File: BatchMQProducer.java License: Apache License 2.0 | 6 votes |
public void send(CarreraRequest request, MessageQueueSelector messageQueueSelector) throws RemotingException, MQClientException, InterruptedException, MQBrokerException { TopicPublishInfo topicInfo = clusterProducer.getRocketMQProducerByIndex(0).getDefaultMQProducerImpl().getTopicPublishInfoTable().get(request.getTopic()); if (topicInfo == null || !topicInfo.ok()) { //new topic sendSingleMessage(request); return; } MessageQueue mq = messageQueueSelector.select(topicInfo.getMessageQueueList(), null, request); request.setMessageQueue(mq); requestQMap.computeIfAbsent(mq.getBrokerName(), _name -> { Deque<CarreraRequest> q = new ConcurrentLinkedDeque<>(); addRequestQueue(q, _name, config.getMaxEncodeWorkerForEachBroker()); return q; }).add(request); }
Example #4
Source Project: jdk8u-dev-jdk Author: frohoff File: RemovePollRace.java License: GNU General Public License v2.0 | 6 votes |
Collection<Queue<Boolean>> concurrentQueues() { List<Queue<Boolean>> queues = new ArrayList<Queue<Boolean>>(); queues.add(new ConcurrentLinkedDeque<Boolean>()); queues.add(new ConcurrentLinkedQueue<Boolean>()); queues.add(new ArrayBlockingQueue<Boolean>(count, false)); queues.add(new ArrayBlockingQueue<Boolean>(count, true)); queues.add(new LinkedBlockingQueue<Boolean>()); queues.add(new LinkedBlockingDeque<Boolean>()); queues.add(new LinkedTransferQueue<Boolean>()); // Following additional implementations are available from: // http://gee.cs.oswego.edu/dl/concurrency-interest/index.html // queues.add(new SynchronizedLinkedListQueue<Boolean>()); // Avoid "first fast, second slow" benchmark effect. Collections.shuffle(queues); return queues; }
Example #5
Source Project: native-obfuscator Author: radioegor146 File: RemovePollRace.java License: GNU General Public License v3.0 | 6 votes |
Collection<Queue<Boolean>> concurrentQueues() { List<Queue<Boolean>> queues = new ArrayList<Queue<Boolean>>(); queues.add(new ConcurrentLinkedDeque<Boolean>()); queues.add(new ConcurrentLinkedQueue<Boolean>()); queues.add(new ArrayBlockingQueue<Boolean>(count, false)); queues.add(new ArrayBlockingQueue<Boolean>(count, true)); queues.add(new LinkedBlockingQueue<Boolean>()); queues.add(new LinkedBlockingDeque<Boolean>()); queues.add(new LinkedTransferQueue<Boolean>()); // Following additional implementations are available from: // http://gee.cs.oswego.edu/dl/concurrency-interest/index.html // queues.add(new SynchronizedLinkedListQueue<Boolean>()); // Avoid "first fast, second slow" benchmark effect. Collections.shuffle(queues); return queues; }
Example #6
Source Project: jdk8u60 Author: chenghanpeng File: RemovePollRace.java License: GNU General Public License v2.0 | 6 votes |
Collection<Queue<Boolean>> concurrentQueues() { List<Queue<Boolean>> queues = new ArrayList<Queue<Boolean>>(); queues.add(new ConcurrentLinkedDeque<Boolean>()); queues.add(new ConcurrentLinkedQueue<Boolean>()); queues.add(new ArrayBlockingQueue<Boolean>(count, false)); queues.add(new ArrayBlockingQueue<Boolean>(count, true)); queues.add(new LinkedBlockingQueue<Boolean>()); queues.add(new LinkedBlockingDeque<Boolean>()); queues.add(new LinkedTransferQueue<Boolean>()); // Following additional implementations are available from: // http://gee.cs.oswego.edu/dl/concurrency-interest/index.html // queues.add(new SynchronizedLinkedListQueue<Boolean>()); // Avoid "first fast, second slow" benchmark effect. Collections.shuffle(queues); return queues; }
Example #7
Source Project: openjdk-jdk9 Author: AdoptOpenJDK File: ConcurrentLinkedDequeTest.java License: GNU General Public License v2.0 | 6 votes |
/** * iterator.remove() removes current element */ public void testIteratorRemove() { final ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); final Random rng = new Random(); for (int iters = 0; iters < 100; ++iters) { int max = rng.nextInt(5) + 2; int split = rng.nextInt(max - 1) + 1; for (int j = 1; j <= max; ++j) q.add(new Integer(j)); Iterator it = q.iterator(); for (int j = 1; j <= split; ++j) assertEquals(it.next(), new Integer(j)); it.remove(); assertEquals(it.next(), new Integer(split + 1)); for (int j = 1; j <= split; ++j) q.remove(new Integer(j)); it = q.iterator(); for (int j = split + 1; j <= max; ++j) { assertEquals(it.next(), new Integer(j)); it.remove(); } assertFalse(it.hasNext()); assertTrue(q.isEmpty()); } }
Example #8
Source Project: super-cloudops Author: wl4g File: TimeoutsHealthIndicator.java License: Apache License 2.0 | 6 votes |
public void addTimes(String metricName, long time) { if (logger.isDebugEnabled()) { logger.debug("MetricName={}, time={}", metricName, time); } int latestCount = conf.getSamples(); Deque<Long> deque = this.records.get(metricName); if (deque == null) { if (logger.isInfoEnabled()) { logger.info("Initial timeoutsHealthIndicator, metricName={}, capacity: {}", metricName, latestCount); } deque = new ConcurrentLinkedDeque<>(); } // Overflow check. if (deque.size() >= (latestCount - 1)) { deque.poll(); // Remove first. } deque.offer(time); this.records.put(metricName, deque); }
Example #9
Source Project: openjdk-jdk8u Author: AdoptOpenJDK File: RemovePollRace.java License: GNU General Public License v2.0 | 6 votes |
Collection<Queue<Boolean>> concurrentQueues() { List<Queue<Boolean>> queues = new ArrayList<Queue<Boolean>>(); queues.add(new ConcurrentLinkedDeque<Boolean>()); queues.add(new ConcurrentLinkedQueue<Boolean>()); queues.add(new ArrayBlockingQueue<Boolean>(count, false)); queues.add(new ArrayBlockingQueue<Boolean>(count, true)); queues.add(new LinkedBlockingQueue<Boolean>()); queues.add(new LinkedBlockingDeque<Boolean>()); queues.add(new LinkedTransferQueue<Boolean>()); // Following additional implementations are available from: // http://gee.cs.oswego.edu/dl/concurrency-interest/index.html // queues.add(new SynchronizedLinkedListQueue<Boolean>()); // Avoid "first fast, second slow" benchmark effect. Collections.shuffle(queues); return queues; }
Example #10
Source Project: jdk8u_jdk Author: JetBrains File: RemovePollRace.java License: GNU General Public License v2.0 | 6 votes |
Collection<Queue<Boolean>> concurrentQueues() { List<Queue<Boolean>> queues = new ArrayList<Queue<Boolean>>(); queues.add(new ConcurrentLinkedDeque<Boolean>()); queues.add(new ConcurrentLinkedQueue<Boolean>()); queues.add(new ArrayBlockingQueue<Boolean>(count, false)); queues.add(new ArrayBlockingQueue<Boolean>(count, true)); queues.add(new LinkedBlockingQueue<Boolean>()); queues.add(new LinkedBlockingDeque<Boolean>()); queues.add(new LinkedTransferQueue<Boolean>()); // Following additional implementations are available from: // http://gee.cs.oswego.edu/dl/concurrency-interest/index.html // queues.add(new SynchronizedLinkedListQueue<Boolean>()); // Avoid "first fast, second slow" benchmark effect. Collections.shuffle(queues); return queues; }
Example #11
Source Project: openjdk-jdk9 Author: AdoptOpenJDK File: ConcurrentLinkedDequeTest.java License: GNU General Public License v2.0 | 6 votes |
/** * descendingIterator.remove() removes current element */ public void testDescendingIteratorRemove() { final ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); final Random rng = new Random(); for (int iters = 0; iters < 100; ++iters) { int max = rng.nextInt(5) + 2; int split = rng.nextInt(max - 1) + 1; for (int j = max; j >= 1; --j) q.add(new Integer(j)); Iterator it = q.descendingIterator(); for (int j = 1; j <= split; ++j) assertEquals(it.next(), new Integer(j)); it.remove(); assertEquals(it.next(), new Integer(split + 1)); for (int j = 1; j <= split; ++j) q.remove(new Integer(j)); it = q.descendingIterator(); for (int j = split + 1; j <= max; ++j) { assertEquals(it.next(), new Integer(j)); it.remove(); } assertFalse(it.hasNext()); assertTrue(q.isEmpty()); } }
Example #12
Source Project: hottub Author: dsrg-uoft File: RemovePollRace.java License: GNU General Public License v2.0 | 6 votes |
Collection<Queue<Boolean>> concurrentQueues() { List<Queue<Boolean>> queues = new ArrayList<Queue<Boolean>>(); queues.add(new ConcurrentLinkedDeque<Boolean>()); queues.add(new ConcurrentLinkedQueue<Boolean>()); queues.add(new ArrayBlockingQueue<Boolean>(count, false)); queues.add(new ArrayBlockingQueue<Boolean>(count, true)); queues.add(new LinkedBlockingQueue<Boolean>()); queues.add(new LinkedBlockingDeque<Boolean>()); queues.add(new LinkedTransferQueue<Boolean>()); // Following additional implementations are available from: // http://gee.cs.oswego.edu/dl/concurrency-interest/index.html // queues.add(new SynchronizedLinkedListQueue<Boolean>()); // Avoid "first fast, second slow" benchmark effect. Collections.shuffle(queues); return queues; }
Example #13
Source Project: lams Author: lamsfoundation File: JDBCLogHandler.java License: GNU General Public License v2.0 | 6 votes |
public JDBCLogHandler(final HttpHandler next, final String formatString, DataSource dataSource) { this.next = next; this.formatString = formatString; this.dataSource = dataSource; tableName = "access"; remoteHostField = "remoteHost"; userField = "userName"; timestampField = "timestamp"; virtualHostField = "virtualHost"; methodField = "method"; queryField = "query"; statusField = "status"; bytesField = "bytes"; refererField = "referer"; userAgentField = "userAgent"; this.pendingMessages = new ConcurrentLinkedDeque<>(); }
Example #14
Source Project: openjdk-8 Author: bpupadhyaya File: RemovePollRace.java License: GNU General Public License v2.0 | 6 votes |
Collection<Queue<Boolean>> concurrentQueues() { List<Queue<Boolean>> queues = new ArrayList<Queue<Boolean>>(); queues.add(new ConcurrentLinkedDeque<Boolean>()); queues.add(new ConcurrentLinkedQueue<Boolean>()); queues.add(new ArrayBlockingQueue<Boolean>(count, false)); queues.add(new ArrayBlockingQueue<Boolean>(count, true)); queues.add(new LinkedBlockingQueue<Boolean>()); queues.add(new LinkedBlockingDeque<Boolean>()); queues.add(new LinkedTransferQueue<Boolean>()); // Following additional implementations are available from: // http://gee.cs.oswego.edu/dl/concurrency-interest/index.html // queues.add(new SynchronizedLinkedListQueue<Boolean>()); // Avoid "first fast, second slow" benchmark effect. Collections.shuffle(queues); return queues; }
Example #15
Source Project: openjdk-jdk9 Author: AdoptOpenJDK File: RemovePollRace.java License: GNU General Public License v2.0 | 6 votes |
Collection<Queue<Boolean>> concurrentQueues() { List<Queue<Boolean>> queues = new ArrayList<>(); queues.add(new ConcurrentLinkedDeque<Boolean>()); queues.add(new ConcurrentLinkedQueue<Boolean>()); queues.add(new ArrayBlockingQueue<Boolean>(count, false)); queues.add(new ArrayBlockingQueue<Boolean>(count, true)); queues.add(new LinkedBlockingQueue<Boolean>()); queues.add(new LinkedBlockingDeque<Boolean>()); queues.add(new LinkedTransferQueue<Boolean>()); // Following additional implementations are available from: // http://gee.cs.oswego.edu/dl/concurrency-interest/index.html // queues.add(new SynchronizedLinkedListQueue<Boolean>()); // Avoid "first fast, second slow" benchmark effect. Collections.shuffle(queues); return queues; }
Example #16
Source Project: j2objc Author: google File: ConcurrentLinkedDequeTest.java License: Apache License 2.0 | 5 votes |
/** * element() returns first element, or throws NSEE if empty */ public void testElement() { ConcurrentLinkedDeque q = populatedDeque(SIZE); for (int i = 0; i < SIZE; ++i) { assertEquals(i, q.element()); assertEquals(i, q.poll()); } try { q.element(); shouldThrow(); } catch (NoSuchElementException success) {} }
Example #17
Source Project: j2objc Author: google File: ConcurrentLinkedDequeTest.java License: Apache License 2.0 | 5 votes |
/** * offerFirst(x) succeeds */ public void testOfferFirst() { ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); assertTrue(q.offerFirst(zero)); assertTrue(q.offerFirst(one)); assertSame(one, q.peekFirst()); assertSame(zero, q.peekLast()); }
Example #18
Source Project: enode Author: anruence File: AggregateRoot.java License: MIT License | 5 votes |
private void appendUncommittedEvent(IDomainEvent<TAggregateRootId> domainEvent) { if (uncommittedEvents == null) { uncommittedEvents = new ConcurrentLinkedDeque<>(); } if (uncommittedEvents.stream().anyMatch(x -> x.getClass().equals(domainEvent.getClass()))) { throw new UnsupportedOperationException(String.format("Cannot apply duplicated domain event type: %s, current aggregateRoot type: %s, id: %s", domainEvent.getClass(), this.getClass().getName(), id)); } uncommittedEvents.add(domainEvent); }
Example #19
Source Project: openjdk-jdk9 Author: AdoptOpenJDK File: ConcurrentLinkedDequeTest.java License: GNU General Public License v2.0 | 5 votes |
/** * poll() succeeds unless empty */ public void testPoll() { ConcurrentLinkedDeque q = populatedDeque(SIZE); for (int i = 0; i < SIZE; ++i) { assertEquals(i, q.poll()); } assertNull(q.poll()); }
Example #20
Source Project: openjdk-jdk9 Author: AdoptOpenJDK File: ConcurrentLinkedDequeTest.java License: GNU General Public License v2.0 | 5 votes |
/** * isEmpty is true before add, false after */ public void testEmpty() { ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); assertTrue(q.isEmpty()); q.add(one); assertFalse(q.isEmpty()); q.add(two); q.remove(); q.remove(); assertTrue(q.isEmpty()); }
Example #21
Source Project: j2objc Author: google File: ConcurrentLinkedDequeTest.java License: Apache License 2.0 | 5 votes |
/** * peekLast() returns next element, or null if empty */ public void testPeekLast() { ConcurrentLinkedDeque q = populatedDeque(SIZE); for (int i = SIZE - 1; i >= 0; --i) { assertEquals(i, q.peekLast()); assertEquals(i, q.pollLast()); assertTrue(q.peekLast() == null || !q.peekLast().equals(i)); } assertNull(q.peekLast()); }
Example #22
Source Project: openjdk-jdk9 Author: AdoptOpenJDK File: ConcurrentLinkedDequeTest.java License: GNU General Public License v2.0 | 5 votes |
/** * Initializing from Collection of null elements throws NPE */ public void testConstructor4() { try { new ConcurrentLinkedDeque(Arrays.asList(new Integer[SIZE])); shouldThrow(); } catch (NullPointerException success) {} }
Example #23
Source Project: j2objc Author: google File: ConcurrentLinkedDequeTest.java License: Apache License 2.0 | 5 votes |
/** * offerLast(null) throws NPE */ public void testOfferLastNull() { ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); try { q.offerLast(null); shouldThrow(); } catch (NullPointerException success) {} }
Example #24
Source Project: j2objc Author: google File: ConcurrentLinkedDequeTest.java License: Apache License 2.0 | 5 votes |
/** * poll() succeeds unless empty */ public void testPoll() { ConcurrentLinkedDeque q = populatedDeque(SIZE); for (int i = 0; i < SIZE; ++i) { assertEquals(i, q.poll()); } assertNull(q.poll()); }
Example #25
Source Project: j2objc Author: google File: ConcurrentLinkedDequeTest.java License: Apache License 2.0 | 5 votes |
/** * peekFirst() returns next element, or null if empty */ public void testPeekFirst() { ConcurrentLinkedDeque q = populatedDeque(SIZE); for (int i = 0; i < SIZE; ++i) { assertEquals(i, q.peekFirst()); assertEquals(i, q.pollFirst()); assertTrue(q.peekFirst() == null || !q.peekFirst().equals(i)); } assertNull(q.peekFirst()); }
Example #26
Source Project: aion Author: aionnetwork File: NodeMgrTest.java License: MIT License | 5 votes |
@Test public void testConcurrentAccess() throws InterruptedException { Deque<INode> inbound = new ConcurrentLinkedDeque<>(); Deque<INode> outbound = new ConcurrentLinkedDeque<>(); List<Runnable> threads = new ArrayList<>(); // due to the maximum number of threads used, active nodes will not be rejected here for (int i = 0; i < MAX_ACTIVE_NODES; i++) { threads.add(generateTempNode()); threads.add(moveTempNodeToOutbound(outbound)); threads.add(moveTempNodeToInbound(inbound)); threads.add(movePeerToActive(inbound, outbound)); } assertConcurrent("Testing concurrent use of NodeMgr with additions to temp, inbound, outbound and active.", threads, TIME_OUT); // print the resulting set of active peers System.out.println(nMgr.dumpNodeInfo("self", true)); assertTrue(nMgr.activeNodesSize() <= MAX_ACTIVE_NODES); // the following assert can fail, but under normal circumstances the odds are extremely low // if it fails consistently there is very likely a bug in the node management assertTrue(nMgr.activeNodesSize() > 0); // also remove active nodes for (int i = 0; i < MAX_ACTIVE_NODES; i++) { threads.add(dropActive()); } assertConcurrent("Testing concurrent use of NodeMgr use with added deletions.", threads, TIME_OUT); // print the resulting set of active peers System.out.println(nMgr.dumpNodeInfo("self", true)); assertTrue(nMgr.activeNodesSize() <= MAX_ACTIVE_NODES); // the following assert can fail, but under normal circumstances the odds are extremely low // if it fails consistently there is very likely a bug in the node management assertTrue(nMgr.activeNodesSize() > 0); }
Example #27
Source Project: FastAsyncWorldedit Author: boy0001 File: MappedFaweQueue.java License: GNU General Public License v3.0 | 5 votes |
@Override public void addEditSession(EditSession session) { ConcurrentLinkedDeque<EditSession> tmp = sessions; if (tmp == null) tmp = new ConcurrentLinkedDeque<>(); tmp.add(session); this.sessions = tmp; }
Example #28
Source Project: j2objc Author: google File: ConcurrentLinkedDequeTest.java License: Apache License 2.0 | 5 votes |
/** * pollLast() succeeds unless empty */ public void testPollLast() { ConcurrentLinkedDeque q = populatedDeque(SIZE); for (int i = SIZE - 1; i >= 0; --i) { assertEquals(i, q.pollLast()); } assertNull(q.pollLast()); }
Example #29
Source Project: openjdk-jdk9 Author: AdoptOpenJDK File: ConcurrentLinkedDequeTest.java License: GNU General Public License v2.0 | 5 votes |
/** * add(null) throws NPE */ public void testAddNull() { ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(); try { q.add(null); shouldThrow(); } catch (NullPointerException success) {} }
Example #30
Source Project: clust4j Author: tgsmith61591 File: MeanShift.java License: Apache License 2.0 | 5 votes |
static ConcurrentSkipListSet<MeanShiftSeed> doAll( int maxIter, double[][] X, RadiusNeighbors nbrs, ConcurrentLinkedDeque<SummaryLite> summaries) { return getThreadPool().invoke( new ParallelSeedExecutor( maxIter, X, nbrs, summaries)); }