|
|
@ -142,11 +142,13 @@ public class MapView {
|
|
|
|
assert key.length() > 0;
|
|
|
|
assert key.length() > 0;
|
|
|
|
assert newMap != null;
|
|
|
|
assert newMap != null;
|
|
|
|
key = normalizeKey(key);
|
|
|
|
key = normalizeKey(key);
|
|
|
|
|
|
|
|
byte[] keyb = key.getBytes("UTF-8");
|
|
|
|
String s = map2string(newMap, "W" + DateFormatter.formatShortSecond() + " ");
|
|
|
|
String s = map2string(newMap, "W" + DateFormatter.formatShortSecond() + " ");
|
|
|
|
assert s != null;
|
|
|
|
assert s != null;
|
|
|
|
|
|
|
|
byte[] sb = s.getBytes("UTF-8");
|
|
|
|
synchronized (this) {
|
|
|
|
synchronized (this) {
|
|
|
|
// write entry
|
|
|
|
// write entry
|
|
|
|
if (blob != null) blob.put(key.getBytes("UTF-8"), s.getBytes("UTF-8"));
|
|
|
|
if (blob != null) blob.put(keyb, sb);
|
|
|
|
|
|
|
|
|
|
|
|
// write map to cache
|
|
|
|
// write map to cache
|
|
|
|
if (cache != null) cache.put(key, newMap);
|
|
|
|
if (cache != null) cache.put(key, newMap);
|
|
|
@ -162,13 +164,14 @@ public class MapView {
|
|
|
|
// update elementCount
|
|
|
|
// update elementCount
|
|
|
|
if (key == null) return;
|
|
|
|
if (key == null) return;
|
|
|
|
key = normalizeKey(key);
|
|
|
|
key = normalizeKey(key);
|
|
|
|
|
|
|
|
byte[] keyb = key.getBytes("UTF-8");
|
|
|
|
|
|
|
|
|
|
|
|
synchronized (this) {
|
|
|
|
synchronized (this) {
|
|
|
|
// remove from cache
|
|
|
|
// remove from cache
|
|
|
|
cache.remove(key);
|
|
|
|
cache.remove(key);
|
|
|
|
|
|
|
|
|
|
|
|
// remove from file
|
|
|
|
// remove from file
|
|
|
|
blob.remove(key.getBytes());
|
|
|
|
blob.remove(keyb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -182,9 +185,10 @@ public class MapView {
|
|
|
|
assert key != null;
|
|
|
|
assert key != null;
|
|
|
|
if (cache == null) return false; // case may appear during shutdown
|
|
|
|
if (cache == null) return false; // case may appear during shutdown
|
|
|
|
key = normalizeKey(key);
|
|
|
|
key = normalizeKey(key);
|
|
|
|
boolean h = false;
|
|
|
|
byte[] keyb = key.getBytes("UTF-8");
|
|
|
|
|
|
|
|
boolean h;
|
|
|
|
synchronized (this) {
|
|
|
|
synchronized (this) {
|
|
|
|
h = this.cache.containsKey(key) || this.blob.has(key.getBytes());
|
|
|
|
h = this.cache.containsKey(key) || this.blob.has(keyb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return h;
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -212,23 +216,34 @@ public class MapView {
|
|
|
|
assert key != null;
|
|
|
|
assert key != null;
|
|
|
|
if (cache == null) return null; // case may appear during shutdown
|
|
|
|
if (cache == null) return null; // case may appear during shutdown
|
|
|
|
key = normalizeKey(key);
|
|
|
|
key = normalizeKey(key);
|
|
|
|
|
|
|
|
byte[] keyb = key.getBytes("UTF-8");
|
|
|
|
|
|
|
|
|
|
|
|
synchronized (this) {
|
|
|
|
Map<String, String> map;
|
|
|
|
Map<String, String> map = cache.get(key);
|
|
|
|
if (storeCache) {
|
|
|
|
if (map != null) return map;
|
|
|
|
synchronized (this) {
|
|
|
|
|
|
|
|
map = cache.get(key);
|
|
|
|
// read object
|
|
|
|
if (map != null) return map;
|
|
|
|
final byte[] b = blob.get(key.getBytes());
|
|
|
|
|
|
|
|
if (b == null) return null;
|
|
|
|
|
|
|
|
map = bytes2map(b);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (storeCache) {
|
|
|
|
// read object
|
|
|
|
|
|
|
|
final byte[] b = blob.get(keyb);
|
|
|
|
|
|
|
|
if (b == null) return null;
|
|
|
|
|
|
|
|
map = bytes2map(b);
|
|
|
|
|
|
|
|
|
|
|
|
// write map to cache
|
|
|
|
// write map to cache
|
|
|
|
cache.put(key, map);
|
|
|
|
cache.put(key, map);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// return value
|
|
|
|
// return value
|
|
|
|
return map;
|
|
|
|
return map;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
byte[] b;
|
|
|
|
|
|
|
|
synchronized (this) {
|
|
|
|
|
|
|
|
map = cache.get(key);
|
|
|
|
|
|
|
|
if (map != null) return map;
|
|
|
|
|
|
|
|
b = blob.get(keyb);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (b == null) return null;
|
|
|
|
|
|
|
|
return bytes2map(b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|