Example usage for java.util.concurrent DelayQueue poll

List of usage examples for java.util.concurrent DelayQueue poll

Introduction

In this page you can find the example usage for java.util.concurrent DelayQueue poll.

Prototype

public E poll() 

Source Link

Document

Retrieves and removes the head of this queue, or returns null if this queue has no elements with an expired delay.

Usage

From source file:org.apache.hawq.pxf.service.UGICache.java

/**
 * 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//from   w ww  . j a  va2  s  .  c  o m
 */
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();
            if (LOG.isDebugEnabled()) {
                LOG.debug(expiredUGI.getSession().toString() + " Skipping close of " + fsMsg);
            }
            // Place it back in the queue if still in use and was not closed
            expiredUGI.resetTime();
            expirationQueue.offer(expiredUGI);
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug("Delay Queue Size for segment " + expiredUGI.getSession().getSegmentId() + " = "
                    + expirationQueue.size());
        }
    }
}