You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2018/03/03 16:13:53 UTC
groovy git commit: Minor refactoring: remove template code of
`ConcurrentCommonCache`
Repository: groovy
Updated Branches:
refs/heads/master d9205b76a -> bf1dc7b1b
Minor refactoring: remove template code of `ConcurrentCommonCache`
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/bf1dc7b1
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/bf1dc7b1
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/bf1dc7b1
Branch: refs/heads/master
Commit: bf1dc7b1b5c36743314c3cbc50c6a819d02e88d3
Parents: d9205b7
Author: danielsun1106 <re...@hotmail.com>
Authored: Sun Mar 4 00:11:42 2018 +0800
Committer: danielsun1106 <re...@hotmail.com>
Committed: Sun Mar 4 00:11:42 2018 +0800
----------------------------------------------------------------------
.../runtime/memoize/ConcurrentCommonCache.java | 74 +++++---------------
1 file changed, 16 insertions(+), 58 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/bf1dc7b1/src/main/java/org/codehaus/groovy/runtime/memoize/ConcurrentCommonCache.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/memoize/ConcurrentCommonCache.java b/src/main/java/org/codehaus/groovy/runtime/memoize/ConcurrentCommonCache.java
index 80f6bdd..27ee102 100644
--- a/src/main/java/org/codehaus/groovy/runtime/memoize/ConcurrentCommonCache.java
+++ b/src/main/java/org/codehaus/groovy/runtime/memoize/ConcurrentCommonCache.java
@@ -93,26 +93,16 @@ public class ConcurrentCommonCache<K, V> implements EvictableCache<K, V>, ValueC
* {@inheritDoc}
*/
@Override
- public V get(K key) {
- readLock.lock();
- try {
- return commonCache.get(key);
- } finally {
- readLock.unlock();
- }
+ public V get(final K key) {
+ return doWithReadLock(c -> c.get(key));
}
/**
* {@inheritDoc}
*/
@Override
- public V put(K key, V value) {
- writeLock.lock();
- try {
- return commonCache.put(key, value);
- } finally {
- writeLock.unlock();
- }
+ public V put(final K key, final V value) {
+ return doWithWriteLock(c -> c.put(key, value));
}
/**
@@ -160,12 +150,7 @@ public class ConcurrentCommonCache<K, V> implements EvictableCache<K, V>, ValueC
*/
@Override
public Collection<V> values() {
- readLock.lock();
- try {
- return commonCache.values();
- } finally {
- readLock.unlock();
- }
+ return doWithReadLock(c -> c.values());
}
/**
@@ -173,25 +158,15 @@ public class ConcurrentCommonCache<K, V> implements EvictableCache<K, V>, ValueC
*/
@Override
public Set<K> keys() {
- readLock.lock();
- try {
- return commonCache.keys();
- } finally {
- readLock.unlock();
- }
+ return doWithReadLock(c -> c.keys());
}
/**
* {@inheritDoc}
*/
@Override
- public boolean containsKey(K key) {
- readLock.lock();
- try {
- return commonCache.containsKey(key);
- } finally {
- readLock.unlock();
- }
+ public boolean containsKey(final K key) {
+ return doWithReadLock(c -> c.containsKey(key));
}
/**
@@ -199,25 +174,15 @@ public class ConcurrentCommonCache<K, V> implements EvictableCache<K, V>, ValueC
*/
@Override
public int size() {
- readLock.lock();
- try {
- return commonCache.size();
- } finally {
- readLock.unlock();
- }
+ return doWithReadLock(c -> c.size());
}
/**
* {@inheritDoc}
*/
@Override
- public V remove(K key) {
- writeLock.lock();
- try {
- return commonCache.remove(key);
- } finally {
- writeLock.unlock();
- }
+ public V remove(final K key) {
+ return doWithWriteLock(c -> c.remove(key));
}
/**
@@ -225,12 +190,7 @@ public class ConcurrentCommonCache<K, V> implements EvictableCache<K, V>, ValueC
*/
@Override
public Map<K, V> clear() {
- writeLock.lock();
- try {
- return commonCache.clear();
- } finally {
- writeLock.unlock();
- }
+ return doWithWriteLock(c -> c.clear());
}
/**
@@ -238,12 +198,10 @@ public class ConcurrentCommonCache<K, V> implements EvictableCache<K, V>, ValueC
*/
@Override
public void cleanUpNullReferences() {
- writeLock.lock();
- try {
- commonCache.cleanUpNullReferences();
- } finally {
- writeLock.unlock();
- }
+ doWithWriteLock(c -> {
+ c.cleanUpNullReferences();
+ return null;
+ });
}
/**