@SuppressWarnings("unchecked") @Override @Nullable public <T> T get(Object key, Callable<T> valueLoader) { Element element = lookup(key); if (element != null) { return (T) element.getObjectValue(); } else { this.cache.acquireWriteLockOnKey(key); try { element = lookup(key); // one more attempt with the write lock if (element != null) { return (T) element.getObjectValue(); } else { return loadValue(key, valueLoader); } } finally { this.cache.releaseWriteLockOnKey(key); } } }
@SuppressWarnings("unchecked") @Override @Nullable public <T> T get(Object key, Callable<T> valueLoader) { Element element = lookup(key); if (element != null) { return (T) element.getObjectValue(); } else { this.cache.acquireWriteLockOnKey(key); try { element = lookup(key); // one more attempt with the write lock if (element != null) { return (T) element.getObjectValue(); } else { return loadValue(key, valueLoader); } } finally { this.cache.releaseWriteLockOnKey(key); } } }
@Override @SuppressWarnings("unchecked") public <T> T get(Object key, Callable<T> valueLoader) { Element element = lookup(key); if (element != null) { return (T) element.getObjectValue(); } else { this.cache.acquireWriteLockOnKey(key); try { element = lookup(key); // One more attempt with the write lock if (element != null) { return (T) element.getObjectValue(); } else { return loadValue(key, valueLoader); } } finally { this.cache.releaseWriteLockOnKey(key); } } }
/** * {@inheritDoc} */ public void acquireWriteLockOnKey(Object key) { underlyingCache.acquireWriteLockOnKey(key); }
/** * {@inheritDoc} */ public void acquireWriteLockOnKey(Object arg0) { // THIS IS GENERATED CODE -- DO NOT HAND MODIFY! Thread t = Thread.currentThread(); ClassLoader prev = t.getContextClassLoader(); t.setContextClassLoader(this.classLoader); try { this.cache.acquireWriteLockOnKey(arg0); } finally { t.setContextClassLoader(prev); } }
/** * {@inheritDoc} */ public void acquireWriteLockOnKey(Object key) { underlyingCache.acquireWriteLockOnKey(key); }
/** * {@inheritDoc} */ public void acquireWriteLockOnKey(Object key) { underlyingCache.acquireWriteLockOnKey(key); }
/** * {@inheritDoc} */ public void acquireWriteLockOnKey(Object key) { underlyingCache.acquireWriteLockOnKey(key); }
@Override public void writeLock(Object key) { __ehcache.acquireWriteLockOnKey(key); }
/** * {@inheritDoc} */ public void acquireWriteLockOnKey(Object arg0) { // THIS IS GENERATED CODE -- DO NOT HAND MODIFY! Thread t = Thread.currentThread(); ClassLoader prev = t.getContextClassLoader(); t.setContextClassLoader(this.classLoader); try { this.cache.acquireWriteLockOnKey(arg0); } finally { t.setContextClassLoader(prev); } }
/** * {@inheritDoc} */ public void acquireWriteLockOnKey(Object arg0) { // THIS IS GENERATED CODE -- DO NOT HAND MODIFY! Thread t = Thread.currentThread(); ClassLoader prev = t.getContextClassLoader(); t.setContextClassLoader(this.classLoader); try { this.cache.acquireWriteLockOnKey(arg0); } finally { t.setContextClassLoader(prev); } }
/** * {@inheritDoc} */ public void acquireWriteLockOnKey(Object arg0) { // THIS IS GENERATED CODE -- DO NOT HAND MODIFY! Thread t = Thread.currentThread(); ClassLoader prev = t.getContextClassLoader(); t.setContextClassLoader(this.classLoader); try { this.cache.acquireWriteLockOnKey(arg0); } finally { t.setContextClassLoader(prev); } }
@Override public V getAndRemove(final K key) { checkNotClosed(); if(key == null) throw new NullPointerException(); ehcache.acquireWriteLockOnKey(key); try { Element previousElement; previousElement = ehcache.get(key); removeAndWriteIfNeeded(key); return previousElement == null ? null : (V) previousElement.getObjectValue(); } finally { ehcache.releaseWriteLockOnKey(key); } }
@Override public V getAndRemove(final K key) { checkNotClosed(); if(key == null) throw new NullPointerException(); ehcache.acquireWriteLockOnKey(key); try { Element previousElement; previousElement = ehcache.get(key); removeAndWriteIfNeeded(key); return previousElement == null ? null : (V) previousElement.getObjectValue(); } finally { ehcache.releaseWriteLockOnKey(key); } }
@SuppressWarnings("unchecked") @Override public <T> T get(Object key, Callable<T> valueLoader) { Element element = lookup(key); if (element != null) { return (T) element.getObjectValue(); } else { this.cache.acquireWriteLockOnKey(key); try { element = lookup(key); // one more attempt with the write lock if (element != null) { return (T) element.getObjectValue(); } else { return loadValue(key, valueLoader); } } finally { this.cache.releaseWriteLockOnKey(key); } } }
@Override public void remove() { if(current == null) { throw new IllegalStateException(); } jCache.ehcache.acquireWriteLockOnKey(current.getKey()); try { final Element element = jCache.ehcache.getQuiet(current.getKey()); if(element != null && element.getObjectValue().equals(current.getValue())) { jCache.removeAndWriteIfNeeded(current.getKey()); } } finally { jCache.ehcache.releaseWriteLockOnKey(current.getKey()); } }
@Override public void remove() { if(current == null) { throw new IllegalStateException(); } jCache.ehcache.acquireWriteLockOnKey(current.getKey()); try { final Element element = jCache.ehcache.getQuiet(current.getKey()); if(element != null && element.getObjectValue().equals(current.getValue())) { jCache.removeAndWriteIfNeeded(current.getKey()); } } finally { jCache.ehcache.releaseWriteLockOnKey(current.getKey()); } }
@Override public boolean putIfAbsent(final K key, final V value) { checkNotClosed(); if(key == null) throw new NullPointerException(); if(value == null) throw new NullPointerException(); ehcache.acquireWriteLockOnKey(key); try { if (!ehcache.isKeyInCache(key)) { final Element element = new Element(key, value); final Duration expiryForCreation; expiryForCreation = cfg.getExpiryPolicy().getExpiryForCreation(); if(setTimeTo(cfg.overrideDefaultExpiry(), expiryForCreation, element)) { putAndWriteIfNeeded(element); } return true; } } finally { ehcache.releaseWriteLockOnKey(key); } return false; }
void putWithoutWriter(final K key, final V value) { checkNotClosed(); if(key == null) throw new NullPointerException(); if(value == null) throw new NullPointerException(); ehcache.acquireWriteLockOnKey(key); try { final Duration expiry; final boolean inCache = ehcache.isKeyInCache(key); if(inCache) { expiry = cfg.getExpiryPolicy().getExpiryForUpdate(); } else { expiry = cfg.getExpiryPolicy().getExpiryForCreation(); } final Element element = new Element(key, value); if(setTimeTo(cfg.overrideDefaultExpiry(), expiry, element)) { ehcache.put(element); } else if(inCache) { ehcache.remove(key); } } finally { ehcache.releaseWriteLockOnKey(key); } }
private boolean removeAndWriteIfNeeded(final K key) { if (cfg.isWriteThrough()) { ehcache.acquireWriteLockOnKey(key); final Element previous = ehcache.getQuiet(key); try { return ehcache.removeWithWriter(key); } catch (RuntimeException e) { if(previous != null) { ehcache.putQuiet(previous); } throw new CacheWriterException(e); } } else { if (ehcache.isKeyInCache(key)) { return ehcache.remove(key); } return false; } }