java.util.concurrent.DelayQueue#remove ( )源码实例Demo

下面列出了java.util.concurrent.DelayQueue#remove ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: pxf   文件: UGICache.java
/**
 * Decrement reference count for the given session's UGI. Resets the time at which the UGI will
 * expire to UGI_CACHE_EXPIRY milliseconds in the future.
 *
 * @param session                  the session for which we want to release the UGI.
 * @param cleanImmediatelyIfNoRefs if true, destroys the UGI for the given session (only if it
 *                                 is now unreferenced).
 */
@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
public void release(SessionId session, boolean cleanImmediatelyIfNoRefs) {

    Entry entry = cache.get(session);

    if (entry == null) {
        throw new IllegalStateException("Cannot release UGI for this session; it is not cached: " + session);
    }

    DelayQueue<Entry> expirationQueue = getExpirationQueue(session.getSegmentId());

    synchronized (expirationQueue) {
        entry.decrementRefCount();
        expirationQueue.remove(entry);
        if (cleanImmediatelyIfNoRefs && entry.isNotInUse()) {
            closeUGI(entry);
        } else {
            // Reset expiration time and put it back in the queue
            // only when we don't close the UGI
            entry.resetTime();
            expirationQueue.offer(entry);
        }
    }
}
 
源代码2 项目: java   文件: DefaultDelayingQueue.java
private void insert(
    DelayQueue<WaitForEntry<T>> q, Map<T, WaitForEntry<T>> knownEntries, WaitForEntry entry) {
  WaitForEntry existing = knownEntries.get((T) entry.data);
  if (existing != null) {
    if (Duration.between(existing.readyAtMillis, entry.readyAtMillis).isNegative()) {
      q.remove(existing);
      existing.readyAtMillis = entry.readyAtMillis;
      q.add(existing);
    }

    return;
  }

  q.offer(entry);
  knownEntries.put((T) entry.data, entry);
}
 
源代码3 项目: openjdk-jdk9   文件: DelayQueueTest.java
/**
 * retainAll(c) retains only those elements of c and reports true if changed
 */
public void testRetainAll() {
    DelayQueue q = populatedQueue(SIZE);
    DelayQueue p = populatedQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        boolean changed = q.retainAll(p);
        if (i == 0)
            assertFalse(changed);
        else
            assertTrue(changed);

        assertTrue(q.containsAll(p));
        assertEquals(SIZE - i, q.size());
        p.remove();
    }
}
 
源代码4 项目: j2objc   文件: DelayQueueTest.java
/**
 * retainAll(c) retains only those elements of c and reports true if changed
 */
public void testRetainAll() {
    DelayQueue q = populatedQueue(SIZE);
    DelayQueue p = populatedQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        boolean changed = q.retainAll(p);
        if (i == 0)
            assertFalse(changed);
        else
            assertTrue(changed);

        assertTrue(q.containsAll(p));
        assertEquals(SIZE - i, q.size());
        p.remove();
    }
}
 
源代码5 项目: openjdk-jdk9   文件: DelayQueueTest.java
/**
 * isEmpty is true before add, false after
 */
public void testEmpty() {
    DelayQueue q = new DelayQueue();
    assertTrue(q.isEmpty());
    assertEquals(Integer.MAX_VALUE, q.remainingCapacity());
    q.add(new PDelay(1));
    assertFalse(q.isEmpty());
    q.add(new PDelay(2));
    q.remove();
    q.remove();
    assertTrue(q.isEmpty());
}
 
源代码6 项目: openjdk-jdk9   文件: DelayQueueTest.java
/**
 * remove removes next element, or throws NSEE if empty
 */
public void testRemove() {
    DelayQueue q = populatedQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(new PDelay(i), q.remove());
    }
    try {
        q.remove();
        shouldThrow();
    } catch (NoSuchElementException success) {}
}
 
源代码7 项目: openjdk-jdk9   文件: DelayQueueTest.java
/**
 * removeAll(c) removes only those elements of c and reports true if changed
 */
public void testRemoveAll() {
    for (int i = 1; i < SIZE; ++i) {
        DelayQueue q = populatedQueue(SIZE);
        DelayQueue p = populatedQueue(i);
        assertTrue(q.removeAll(p));
        assertEquals(SIZE - i, q.size());
        for (int j = 0; j < i; ++j) {
            PDelay x = (PDelay)(p.remove());
            assertFalse(q.contains(x));
        }
    }
}
 
源代码8 项目: j2objc   文件: DelayQueueTest.java
/**
 * isEmpty is true before add, false after
 */
public void testEmpty() {
    DelayQueue q = new DelayQueue();
    assertTrue(q.isEmpty());
    assertEquals(Integer.MAX_VALUE, q.remainingCapacity());
    q.add(new PDelay(1));
    assertFalse(q.isEmpty());
    q.add(new PDelay(2));
    q.remove();
    q.remove();
    assertTrue(q.isEmpty());
}
 
源代码9 项目: j2objc   文件: DelayQueueTest.java
/**
 * remove removes next element, or throws NSEE if empty
 */
public void testRemove() {
    DelayQueue q = populatedQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(new PDelay(i), q.remove());
    }
    try {
        q.remove();
        shouldThrow();
    } catch (NoSuchElementException success) {}
}
 
源代码10 项目: j2objc   文件: DelayQueueTest.java
/**
 * removeAll(c) removes only those elements of c and reports true if changed
 */
public void testRemoveAll() {
    for (int i = 1; i < SIZE; ++i) {
        DelayQueue q = populatedQueue(SIZE);
        DelayQueue p = populatedQueue(i);
        assertTrue(q.removeAll(p));
        assertEquals(SIZE - i, q.size());
        for (int j = 0; j < i; ++j) {
            PDelay x = (PDelay)(p.remove());
            assertFalse(q.contains(x));
        }
    }
}
 
源代码11 项目: exhibitor   文件: ActivityQueue.java
/**
 * Replace the given activity in the given queue. If not in the queue, adds it to the queue. The activity
 * runs after the specified delay (the delay of the previous entry, if any, is ignored)
 *
 * @param group the queue - all activities within a queue are executed serially
 * @param activity the activity
 * @param delay the delay
 * @param unit the delay unit
 */
public synchronized void     replace(QueueGroups group, Activity activity, long delay, TimeUnit unit)
{
    ActivityHolder  holder = new ActivityHolder(activity, TimeUnit.MILLISECONDS.convert(delay, unit));
    DelayQueue<ActivityHolder> queue = queues.get(group);
    queue.remove(holder);
    queue.offer(holder);
}