List of usage examples for java.util.concurrent DelayQueue offer
public boolean offer(E e)
From source file:org.apache.hawq.pxf.service.UGICache.java
/** * If a UGI for the given session exists in the cache, returns it. Otherwise, creates a new * proxy UGI. In either case this method increments the reference count of the UGI. This method * also destroys expired, unreferenced UGIs for the same segmentId as the given session. * * @param session The user from the session is impersonated by the proxy UGI. * @return the proxy UGI for the given session. *//*from w w w . j av a2 s . c o m*/ public UserGroupInformation getUserGroupInformation(SessionId session) throws IOException { Integer segmentId = session.getSegmentId(); String user = session.getUser(); DelayQueue<Entry> delayQueue = getExpirationQueue(segmentId); synchronized (delayQueue) { // Use the opportunity to cleanup any expired entries cleanup(delayQueue); Entry entry = cache.get(session); if (entry == null) { if (LOG.isDebugEnabled()) { LOG.debug(session + " Creating proxy user = " + user); } entry = new Entry(ticker, ugiProvider.createProxyUGI(user), session); delayQueue.offer(entry); cache.put(session, entry); } entry.incrementRefCount(); return entry.getUGI(); } }
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). */// w w w . j a v a2 s . c o m 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); } } }
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 w w .jav a 2 s.com */ 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()); } } }