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 File: TimeoutsHealthIndicator.java    From super-cloudops with Apache License 2.0 6 votes vote down vote up
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 #2
Source File: RemovePollRace.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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 #3
Source File: JDBCLogHandler.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
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 #4
Source File: WrongOrderTransporter.java    From moleculer-java with MIT License 6 votes vote down vote up
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 #5
Source File: JDBCLogHandler.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
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 #6
Source File: BatchMQProducer.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
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 #7
Source File: RemovePollRace.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
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 #8
Source File: ConcurrentLinkedDequeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #9
Source File: RemovePollRace.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
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 File: RemovePollRace.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
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 File: RemovePollRace.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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 #12
Source File: RemovePollRace.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
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 File: ConcurrentLinkedDequeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #14
Source File: RemovePollRace.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
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 File: RemovePollRace.java    From native-obfuscator with GNU General Public License v3.0 6 votes vote down vote up
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 #16
Source File: ConcurrentLinkedDequeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Deque contains all elements of collection used to initialize
 */
public void testConstructor6() {
    Integer[] ints = new Integer[SIZE];
    for (int i = 0; i < SIZE; ++i)
        ints[i] = new Integer(i);
    ConcurrentLinkedDeque q = new ConcurrentLinkedDeque(Arrays.asList(ints));
    for (int i = 0; i < SIZE; ++i)
        assertEquals(ints[i], q.poll());
}
 
Example #17
Source File: ConcurrentLinkedDequeTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * contains(x) reports true when elements added but not yet removed
 */
public void testContains() {
    ConcurrentLinkedDeque q = populatedDeque(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertTrue(q.contains(new Integer(i)));
        q.poll();
        assertFalse(q.contains(new Integer(i)));
    }
}
 
Example #18
Source File: ConcurrentLinkedDequeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * offer(x) succeeds
 */
public void testOffer() {
    ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
    assertTrue(q.offer(zero));
    assertTrue(q.offer(one));
    assertSame(zero, q.peekFirst());
    assertSame(one, q.peekLast());
}
 
Example #19
Source File: ConcurrentLinkedDequeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * offerLast(x) succeeds
 */
public void testOfferLast() {
    ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
    assertTrue(q.offerLast(zero));
    assertTrue(q.offerLast(one));
    assertSame(zero, q.peekFirst());
    assertSame(one, q.peekLast());
}
 
Example #20
Source File: SetQueue.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
private synchronized boolean runEmptyTasks() {
    if (this.emptyTasks.isEmpty()) {
        return false;
    }
    final ConcurrentLinkedDeque<Runnable> tmp = new ConcurrentLinkedDeque<>(this.emptyTasks);
    this.emptyTasks.clear();
    for (final Runnable runnable : tmp) {
        runnable.run();
    }
    return true;
}
 
Example #21
Source File: ConcurrentLinkedDequeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * toString() contains toStrings of elements
 */
public void testToString() {
    ConcurrentLinkedDeque q = populatedDeque(SIZE);
    String s = q.toString();
    for (int i = 0; i < SIZE; ++i) {
        assertTrue(s.contains(String.valueOf(i)));
    }
}
 
Example #22
Source File: DelayedHashMap.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
private DelayedHashMap(int expire, int segment, TransienceMonitor monitor) {
    if (segment < 2) {
        throw new IllegalArgumentException("segment must be >= 2");
    }
    this.segments = new ConcurrentLinkedDeque<ConcurrentHashMap<K, V>>();
    for (int index = 0; index < segment; index++) {
        this.segments.addLast(new ConcurrentHashMap<K, V>());
    }
    this.monitor = monitor;
    this.waitTime = expire * 1000 / segment;
}
 
Example #23
Source File: ConcurrentLinkedDequeTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Iterator ordering is FIFO
 */
public void testIteratorOrdering() {
    final ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
    q.add(one);
    q.add(two);
    q.add(three);

    int k = 0;
    for (Iterator it = q.iterator(); it.hasNext();) {
        assertEquals(++k, it.next());
    }

    assertEquals(3, k);
}
 
Example #24
Source File: ConcurrentLinkedDequeTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * getFirst() returns first element, or throws NSEE if empty
 */
public void testFirstElement() {
    ConcurrentLinkedDeque q = populatedDeque(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.getFirst());
        assertEquals(i, q.pollFirst());
    }
    try {
        q.getFirst();
        shouldThrow();
    } catch (NoSuchElementException success) {}
}
 
Example #25
Source File: DedupCache.java    From eagle with Apache License 2.0 5 votes vote down vote up
public Map<EventUniq, ConcurrentLinkedDeque<DedupValue>> getEvents() {
    if (lastUpdated < 0
        || System.currentTimeMillis() - lastUpdated > CACHE_MAX_EXPIRE_TIME_IN_DAYS * DateUtils.MILLIS_PER_DAY
        || events.size() <= 0) {
        lastUpdated = System.currentTimeMillis();
    }
    return events;
}
 
Example #26
Source File: ExchangeMergeStaleServerNodesTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param nodeId Node ID to replay.
 */
private void replay(UUID nodeId) {
    Collection<Runnable> old = delayed.replace(nodeId, new ConcurrentLinkedDeque<>());

    if (old != null) {
        for (Runnable task : old)
            task.run();
    }
}
 
Example #27
Source File: ConcurrentLinkedDequeTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #28
Source File: ConcurrentLinkedDequeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * pop() removes first element, or throws NSEE if empty
 */
public void testPop() {
    ConcurrentLinkedDeque q = populatedDeque(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.pop());
    }
    try {
        q.pop();
        shouldThrow();
    } catch (NoSuchElementException success) {}
}
 
Example #29
Source File: ConcurrentLinkedDequeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * containsAll(c) is true when c contains a subset of elements
 */
public void testContainsAll() {
    ConcurrentLinkedDeque q = populatedDeque(SIZE);
    ConcurrentLinkedDeque p = new ConcurrentLinkedDeque();
    for (int i = 0; i < SIZE; ++i) {
        assertTrue(q.containsAll(p));
        assertFalse(p.containsAll(q));
        p.add(new Integer(i));
    }
    assertTrue(p.containsAll(q));
}
 
Example #30
Source File: ConcurrentLinkedDequeTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * addFirst(null) throws NPE
 */
public void testAddFirstNull() {
    ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
    try {
        q.addFirst(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}