下面列出了java.util.concurrent.DelayQueue#poll ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Iterate through all the entries in the queue and close expired {@link UserGroupInformation},
* otherwise it resets the timer for every non-expired entry.
*
* @param expirationQueue
*/
private void cleanup(DelayQueue<Entry> expirationQueue) {
Entry expiredUGI;
while ((expiredUGI = expirationQueue.poll()) != null) {
if (expiredUGI.isNotInUse()) {
closeUGI(expiredUGI);
} else {
// The UGI object is still being used by another thread
String fsMsg = "FileSystem for proxy user = " + expiredUGI.getSession().getUser();
LOG.debug("{} Skipping close of {}", expiredUGI.getSession().toString(), fsMsg);
// Place it back in the queue if still in use and was not closed
expiredUGI.resetTime();
expirationQueue.offer(expiredUGI);
}
LOG.debug("Delay Queue Size for segment {} = {}", expiredUGI.getSession().getSegmentId(), expirationQueue.size());
}
}
/**
* element returns next element, or throws NSEE if empty
*/
public void testElement() {
DelayQueue q = populatedQueue(SIZE);
for (int i = 0; i < SIZE; ++i) {
assertEquals(new PDelay(i), q.element());
q.poll();
}
try {
q.element();
shouldThrow();
} catch (NoSuchElementException success) {}
}
/**
* contains(x) reports true when elements added but not yet removed
*/
public void testContains() {
DelayQueue q = populatedQueue(SIZE);
for (int i = 0; i < SIZE; ++i) {
assertTrue(q.contains(new PDelay(i)));
q.poll();
assertFalse(q.contains(new PDelay(i)));
}
}
/**
* element returns next element, or throws NSEE if empty
*/
public void testElement() {
DelayQueue q = populatedQueue(SIZE);
for (int i = 0; i < SIZE; ++i) {
assertEquals(new PDelay(i), q.element());
q.poll();
}
try {
q.element();
shouldThrow();
} catch (NoSuchElementException success) {}
}
/**
* contains(x) reports true when elements added but not yet removed
*/
public void testContains() {
DelayQueue q = populatedQueue(SIZE);
for (int i = 0; i < SIZE; ++i) {
assertTrue(q.contains(new PDelay(i)));
q.poll();
assertFalse(q.contains(new PDelay(i)));
}
}