Example usage for java.util.concurrent DelayQueue remove

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

Introduction

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

Prototype

public boolean remove(Object o) 

Source Link

Document

Removes a single instance of the specified element from this queue, if it is present, whether or not it has expired.

Usage

From source file:org.apache.hawq.pxf.service.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).
 *//*from ww w  .  j  a  v  a  2  s. com*/
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);
        }
    }
}