List of usage examples for java.util.concurrent.locks Lock lock
lock
From source file:edu.internet2.middleware.shibboleth.common.relyingparty.provider.SAMLMDRelyingPartyConfigurationManager.java
/** * Gets the metadata provider used to lookup information about entities. * // www . j a v a 2s. c o m * @return metadata provider used to lookup information about entities */ public MetadataProvider getMetadataProvider() { Lock readLock = getReadWriteLock().readLock(); readLock.lock(); try { return metadataProvider; } finally { readLock.unlock(); } }
From source file:org.mule.transport.ConcurrentWorkTracker.java
public void removeWork(Runnable work) { Lock lock = registryLock.writeLock(); try {/*from w w w .j av a 2s. c om*/ if (logger.isDebugEnabled()) { logger.debug("Untracking work: " + work); } lock.lock(); works.remove(work); } finally { lock.unlock(); } }
From source file:SoftReferenceCache.java
/** * @see java.util.Map#get(java.lang.Object) *//* w w w .j av a 2s . c o m*/ public V get(Object key) { Lock lock = theLock.readLock(); lock.lock(); try { KeyedSoftReference<V> val = theCache.get(key); return val == null ? null : val.get(); } finally { lock.unlock(); } }
From source file:SoftReferenceCache.java
/** * @see java.util.Map#clear()/*ww w .j a v a 2 s . c o m*/ */ public void clear() { Lock lock = theLock.writeLock(); lock.lock(); try { theCache.clear(); } finally { lock.unlock(); } }
From source file:SoftReferenceCache.java
/** * @see java.util.Map#containsKey(java.lang.Object) *//*from ww w . j ava 2 s . c o m*/ public boolean containsKey(Object key) { Lock lock = theLock.readLock(); lock.lock(); try { KeyedSoftReference<V> val = theCache.get(key); return val == null || val.isEnqueued(); } finally { lock.unlock(); } }
From source file:SoftReferenceCache.java
/** * @see java.util.Map#remove(java.lang.Object) */// w w w. j av a 2s. com public V remove(Object key) { Lock lock = theLock.writeLock(); lock.lock(); try { removeQueued(); KeyedSoftReference<V> val = theCache.remove(key); return val == null ? null : val.get(); } finally { lock.unlock(); } }
From source file:SoftReferenceCache.java
/** * @see java.util.Map#put(java.lang.Object, java.lang.Object) *//*from ww w. j a v a 2 s.com*/ public V put(K key, V value) { Lock lock = theLock.writeLock(); lock.lock(); try { removeQueued(); KeyedSoftReference<V> val = theCache.get(key); theCache.put(key, new KeyedSoftReference<V>(key, value, theRefQueue)); return val == null ? null : val.get(); } finally { lock.unlock(); } }
From source file:SoftReferenceCache.java
/** * @see java.util.Map#putAll(java.util.Map) *//* ww w . j a v a2 s . c o m*/ public void putAll(Map<? extends K, ? extends V> m) { Lock lock = theLock.writeLock(); lock.lock(); try { removeQueued(); for (java.util.Map.Entry<? extends K, ? extends V> entry : m.entrySet()) { theCache.put(entry.getKey(), new KeyedSoftReference<V>(entry.getKey(), entry.getValue(), theRefQueue)); } } finally { lock.unlock(); } }
From source file:edu.internet2.middleware.shibboleth.idp.profile.IdPProfileHandlerManager.java
/** {@inheritDoc} */ public ProfileHandler getProfileHandler(ServletRequest request) { ProfileHandler handler;/*from ww w. j a va 2s . co m*/ String requestPath = ((HttpServletRequest) request).getPathInfo(); log.debug("{}: Looking up profile handler for request path: {}", getId(), requestPath); Lock readLock = getReadWriteLock().readLock(); readLock.lock(); try { handler = profileHandlers.get(requestPath); } finally { readLock.unlock(); } if (handler != null) { log.debug("{}: Located profile handler of the following type for the request path: {}", getId(), handler.getClass().getName()); } else { log.debug("{}: No profile handler registered for request path {}", getId(), requestPath); } return handler; }
From source file:com.ignorelist.kassandra.steam.scraper.FileCache.java
@Override public InputStream get(String key, Callable<? extends InputStream> valueLoader) throws ExecutionException { InputStream inputStream = getIfPresent(key); if (null != inputStream) { return inputStream; }// w ww. j a v a 2s . c o m final Lock writeLock = stripedLock.get(key).writeLock(); writeLock.lock(); try { inputStream = getIfPresentNonBlocking(key); if (null != inputStream) { return inputStream; } try { inputStream = valueLoader.call(); try { putNonBlocking(key, inputStream); return getIfPresentNonBlocking(key); } catch (IOException ex) { Logger.getLogger(FileCache.class.getName()).log(Level.SEVERE, "failed to write cache file", ex); throw new ExecutionException("failed to load " + key, ex); } } catch (Exception e) { Logger.getLogger(FileCache.class.getName()).log(Level.SEVERE, null, e); throw new ExecutionException(e); } } finally { writeLock.unlock(); } }