commit 1d7663bdbcdfe6f59b4ba76bde7043363ac10c04 Author: Todd Lipcon Date: Fri Apr 16 11:47:34 2010 -0700 HBASE-2458. Add synchronized keywords to SoftValueSortedMap diff --git src/java/org/apache/hadoop/hbase/util/SoftValueSortedMap.java src/java/org/apache/hadoop/hbase/util/SoftValueSortedMap.java index 5bf586e..7c4c49c 100644 --- src/java/org/apache/hadoop/hbase/util/SoftValueSortedMap.java +++ src/java/org/apache/hadoop/hbase/util/SoftValueSortedMap.java @@ -65,7 +65,7 @@ public class SoftValueSortedMap implements SortedMap { * Internally these call checkReferences on each access. * @return How many references cleared. */ - public int checkReferences() { + private int checkReferences() { int i = 0; for (Object obj = null; (obj = this.rq.poll()) != null;) { i++; @@ -74,7 +74,7 @@ public class SoftValueSortedMap implements SortedMap { return i; } - public V put(K key, V value) { + public synchronized V put(K key, V value) { checkReferences(); SoftValue oldValue = this.internalMap.put(key, new SoftValue(key, value, this.rq)); @@ -82,11 +82,11 @@ public class SoftValueSortedMap implements SortedMap { } @SuppressWarnings("unchecked") - public void putAll(Map map) { + public synchronized void putAll(Map map) { throw new RuntimeException("Not implemented"); } - public V get(Object key) { + public synchronized V get(Object key) { checkReferences(); SoftValue value = this.internalMap.get(key); if (value == null) { @@ -99,74 +99,74 @@ public class SoftValueSortedMap implements SortedMap { return value.get(); } - public V remove(Object key) { + public synchronized V remove(Object key) { checkReferences(); SoftValue value = this.internalMap.remove(key); return value == null ? null : value.get(); } - public boolean containsKey(Object key) { + public synchronized boolean containsKey(Object key) { checkReferences(); return this.internalMap.containsKey(key); } - public boolean containsValue(Object value) { + public synchronized boolean containsValue(Object value) { /* checkReferences(); return internalMap.containsValue(value);*/ throw new UnsupportedOperationException("Don't support containsValue!"); } - public K firstKey() { + public synchronized K firstKey() { checkReferences(); return internalMap.firstKey(); } - public K lastKey() { + public synchronized K lastKey() { checkReferences(); return internalMap.lastKey(); } - public SoftValueSortedMap headMap(K key) { + public synchronized SoftValueSortedMap headMap(K key) { checkReferences(); return new SoftValueSortedMap(this.internalMap.headMap(key)); } - public SoftValueSortedMap tailMap(K key) { + public synchronized SoftValueSortedMap tailMap(K key) { checkReferences(); return new SoftValueSortedMap(this.internalMap.tailMap(key)); } - public SoftValueSortedMap subMap(K fromKey, K toKey) { + public synchronized SoftValueSortedMap subMap(K fromKey, K toKey) { checkReferences(); return new SoftValueSortedMap(this.internalMap.subMap(fromKey, toKey)); } - public boolean isEmpty() { + public synchronized boolean isEmpty() { checkReferences(); return this.internalMap.isEmpty(); } - public int size() { + public synchronized int size() { checkReferences(); return this.internalMap.size(); } - public void clear() { + public synchronized void clear() { checkReferences(); this.internalMap.clear(); } - public Set keySet() { + public synchronized Set keySet() { checkReferences(); return this.internalMap.keySet(); } @SuppressWarnings("unchecked") - public Comparator comparator() { + public synchronized Comparator comparator() { return this.internalMap.comparator(); } - public Set> entrySet() { + public synchronized Set> entrySet() { checkReferences(); Set>> entries = this.internalMap.entrySet(); Set> real_entries = new TreeSet>(); @@ -176,7 +176,7 @@ public class SoftValueSortedMap implements SortedMap { return real_entries; } - public Collection values() { + public synchronized Collection values() { checkReferences(); Collection> softValues = this.internalMap.values(); ArrayList hardValues = new ArrayList(); @@ -185,4 +185,4 @@ public class SoftValueSortedMap implements SortedMap { } return hardValues; } -} \ No newline at end of file +}