|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.blur.CachedMap
org.apache.blur.zookeeper.ZkCachedMap
public class ZkCachedMap
This is an simple implementation of a set-once map of string-to-string that
is backed by ZooKeeper. Meaning that once the value is set a single time it
cannot be set to a different value. The clear cache method is called when the
internal cache is to be cleared and re-read from ZooKeeper.
Usage:
ZkCachedMap map = new ZkCachedMap(zooKeeper, path);
String key = "key";
String newValue = "value";
String value = map.get(key);
if (value == null) {
if (map.putIfMissing(key, newValue)) {
System.out.println("Yay! My value was taken.");
value = newValue;
} else {
System.out.println("Boo! Someone beat me to it.");
value = map.get(key);
}
}
System.out.println("key [" + key + "] value [" + value + "]");
Constructor Summary | |
---|---|
ZkCachedMap(org.apache.zookeeper.ZooKeeper zooKeeper,
String basePath)
|
Method Summary | |
---|---|
void |
clearCache()
Clears the in memory cache of the map, this forces a re-read from the source. |
Map<String,String> |
fetchAllFromSource()
Fetches all the keys and values for the map from the source. |
String |
get(String key)
Checks the in memory map first, then fetches from ZooKeeper. |
boolean |
putIfMissing(String key,
String value)
Checks the in memory map first, if it exists then return true. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ZkCachedMap(org.apache.zookeeper.ZooKeeper zooKeeper, String basePath)
Method Detail |
---|
public void clearCache()
CachedMap
clearCache
in class CachedMap
public String get(String key) throws IOException
get
in class CachedMap
key
- the key.
IOException
- if there is an io error.public boolean putIfMissing(String key, String value) throws IOException
putIfMissing
in class CachedMap
key
- the key.value
- the value.
IOException
- if there is an io error.public Map<String,String> fetchAllFromSource() throws IOException
CachedMap
fetchAllFromSource
in class CachedMap
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |