@Override public void remove() { if (current == null) { throw new IllegalStateException(); } cache.remove(current.getKey()); current = null; } }
final AtomicReference<T> invokeResult = new AtomicReference<>(); jsr107Cache.compute(key, (mappedKey, mappedValue) -> { MutableEntry mutableEntry = new MutableEntry(mappedKey, mappedValue); mutableEntryRef.set(mutableEntry);
@Override public Map<K, V> getAll(Set<? extends K> keys) { checkClosed(); try { return jsr107Cache.getAll(keys); } catch (CacheLoadingException e) { throw jsr107CacheLoaderException(e); } }
@Override public V getAndPut(final K key, final V value) { checkClosed(); if (key == null || value == null) { throw new NullPointerException(); } try { return jsr107Cache.getAndPut(key, value); } catch (CacheWritingException e) { throw jsr107CacheWriterException(e); } }
@Override public V getAndRemove(K key) { checkClosed(); if (key == null) { throw new NullPointerException(); } try { return jsr107Cache.getAndRemove(key); } catch (CacheWritingException e) { throw jsr107CacheWriterException(e); } }
@Override public void removeAll() { checkClosed(); try { jsr107Cache.removeAll(); } catch (CacheWritingException e) { throw jsr107CacheWriterException(e); } }
@Override public Iterator<Entry<K, V>> iterator() { checkClosed(); final Iterator<org.ehcache.Cache.Entry<K, V>> specIterator = jsr107Cache.specIterator(); return new Iterator<Entry<K, V>>() { @Override public boolean hasNext() { checkClosed(); return specIterator.hasNext(); } @Override public Entry<K, V> next() { checkClosed(); org.ehcache.Cache.Entry<K, V> next = specIterator.next(); return next == null ? null : new WrappedEhcacheEntry<>(next); } @Override public void remove() { checkClosed(); specIterator.remove(); } }; }
@Override public void loadAll(Set<? extends K> keys, boolean replaceExistingValues, CompletionListener completionListener) { checkClosed(); if (keys == null) { throw new NullPointerException(); } for (K key : keys) { if (key == null) { throw new NullPointerException(); } } completionListener = completionListener != null ? completionListener : NullCompletionListener.INSTANCE; if (cacheLoaderWriter == null) { completionListener.onCompletion(); return; } try { jsr107Cache.loadAll(keys, replaceExistingValues, this::loadAllFunction); } catch (Exception e) { final CacheLoaderException cle; cle = getCacheLoaderException(e); completionListener.onException(cle); return; } completionListener.onCompletion(); }
@Override public Cache.Entry<K, V> next() { try { Cache.Entry<K, Store.ValueHolder<V>> next = iterator.next(); final K nextKey = next.getKey(); Store.ValueHolder<V> nextValueHolder = next.getValue(); // call Cache.get() here to check for expiry *and* account for a get in the stats, without using the loader if (cache.getNoLoader(nextKey) == null) { current = null; return null; } current = next; final V nextValue = nextValueHolder.get(); return new Cache.Entry<K, V>() { @Override public K getKey() { return nextKey; } @Override public V getValue() { return nextValue; } }; } catch (StoreAccessException sae) { current = null; return null; } }
@Override public V getAndPut(final K key, final V value) { checkClosed(); if (key == null || value == null) { throw new NullPointerException(); } try { return jsr107Cache.getAndPut(key, value); } catch (CacheWritingException e) { throw jsr107CacheWriterException(e); } }
@Override public V getAndRemove(K key) { checkClosed(); if (key == null) { throw new NullPointerException(); } try { return jsr107Cache.getAndRemove(key); } catch (CacheWritingException e) { throw jsr107CacheWriterException(e); } }
@Override public void removeAll() { checkClosed(); try { jsr107Cache.removeAll(); } catch (CacheWritingException e) { throw jsr107CacheWriterException(e); } }
@Override public Iterator<Entry<K, V>> iterator() { checkClosed(); final Iterator<org.ehcache.Cache.Entry<K, V>> specIterator = jsr107Cache.specIterator(); return new Iterator<Entry<K, V>>() { @Override public boolean hasNext() { checkClosed(); return specIterator.hasNext(); } @Override public Entry<K, V> next() { checkClosed(); org.ehcache.Cache.Entry<K, V> next = specIterator.next(); return next == null ? null : new WrappedEhcacheEntry<>(next); } @Override public void remove() { checkClosed(); specIterator.remove(); } }; }
@Override public void loadAll(Set<? extends K> keys, boolean replaceExistingValues, CompletionListener completionListener) { checkClosed(); if (keys == null) { throw new NullPointerException(); } for (K key : keys) { if (key == null) { throw new NullPointerException(); } } completionListener = completionListener != null ? completionListener : NullCompletionListener.INSTANCE; if (cacheLoaderWriter == null) { completionListener.onCompletion(); return; } try { jsr107Cache.loadAll(keys, replaceExistingValues, this::loadAllFunction); } catch (Exception e) { final CacheLoaderException cle; cle = getCacheLoaderException(e); completionListener.onException(cle); return; } completionListener.onCompletion(); }
@Override public Cache.Entry<K, V> next() { try { Cache.Entry<K, Store.ValueHolder<V>> next = iterator.next(); final K nextKey = next.getKey(); Store.ValueHolder<V> nextValueHolder = next.getValue(); // call Cache.get() here to check for expiry *and* account for a get in the stats, without using the loader if (cache.getNoLoader(nextKey) == null) { current = null; return null; } current = next; final V nextValue = nextValueHolder.get(); return new Cache.Entry<K, V>() { @Override public K getKey() { return nextKey; } @Override public V getValue() { return nextValue; } }; } catch (StoreAccessException sae) { current = null; return null; } }
@Override public boolean remove(final K key) { checkClosed(); if (key == null) { throw new NullPointerException(); } try { return jsr107Cache.remove(key); } catch (CacheWritingException e) { throw jsr107CacheWriterException(e); } }
@Override public Map<K, V> getAll(Set<? extends K> keys) { checkClosed(); try { return jsr107Cache.getAll(keys); } catch (CacheLoadingException e) { throw jsr107CacheLoaderException(e); } }
final AtomicReference<T> invokeResult = new AtomicReference<>(); jsr107Cache.compute(key, (mappedKey, mappedValue) -> { MutableEntry mutableEntry = new MutableEntry(mappedKey, mappedValue); mutableEntryRef.set(mutableEntry);
@Override public void remove() { if (current == null) { throw new IllegalStateException(); } cache.remove(current.getKey()); current = null; } }
@Override public boolean remove(final K key) { checkClosed(); if (key == null) { throw new NullPointerException(); } try { return jsr107Cache.remove(key); } catch (CacheWritingException e) { throw jsr107CacheWriterException(e); } }