fix concurrent modification exceptions in local cache

This commit is contained in:
fjy 2014-04-08 16:23:24 -07:00
parent 7c90a0fb96
commit dd8e9e2930
1 changed files with 11 additions and 5 deletions

View File

@ -77,7 +77,10 @@ public class MapCache implements Cache
@Override
public byte[] get(NamedKey key)
{
final byte[] retVal = baseMap.get(computeKey(getNamespaceId(key.namespace), key.key));
final byte[] retVal;
synchronized (clearLock) {
retVal = baseMap.get(computeKey(getNamespaceId(key.namespace), key.key));
}
if (retVal == null) {
missCount.incrementAndGet();
} else {
@ -90,7 +93,7 @@ public class MapCache implements Cache
public void put(NamedKey key, byte[] value)
{
synchronized (clearLock) {
baseMap.put(computeKey(getNamespaceId(key.namespace), key.key), value);
baseMap.put(computeKey(getNamespaceId(key.namespace), key.key), value);
}
}
@ -98,7 +101,7 @@ public class MapCache implements Cache
public Map<NamedKey, byte[]> getBulk(Iterable<NamedKey> keys)
{
Map<NamedKey, byte[]> retVal = Maps.newHashMap();
for(NamedKey key : keys) {
for (NamedKey key : keys) {
retVal.put(key, get(key));
}
return retVal;
@ -110,7 +113,9 @@ public class MapCache implements Cache
byte[] idBytes;
synchronized (namespaceId) {
idBytes = getNamespaceId(namespace);
if(idBytes == null) return;
if (idBytes == null) {
return;
}
namespaceId.remove(namespace);
}
@ -150,7 +155,8 @@ public class MapCache implements Cache
return retVal;
}
public boolean isLocal() {
public boolean isLocal()
{
return true;
}
}