com.twitter.common.zookeeper
Class ZooKeeperMap<V>

java.lang.Object
  extended by com.google.common.collect.ForwardingObject
      extended by com.google.common.collect.ForwardingMap<String,V>
          extended by com.twitter.common.zookeeper.ZooKeeperMap<V>
Type Parameters:
V - the type of values this map stores
All Implemented Interfaces:
Map<String,V>

public class ZooKeeperMap<V>
extends ForwardingMap<String,V>

A ZooKeeper backed Map. Initialized with a node path, this map represents child nodes under that path as keys, with the data in those nodes as values. This map is readonly from clients of this class, and only can be modified via direct zookeeper operations. Note that instances of this class maintain a zookeeper watch for each zookeeper node under the parent, as well as on the parent itself. Instances of this class should be created via the create(com.twitter.common.zookeeper.ZooKeeperClient, java.lang.String, com.google.common.base.Function) factory method. As of ZooKeeper Version 3.1, the maxiumum allowable size of a data node is 1 MB A single client should be able to hold up to maintain several thousand watches, but this depends on rate of data change as well. Talk to your zookeeper cluster administrator if you expect number of map entries times number of live clients to exceed a thousand, as a zookeeper cluster is limited by total number of server-side watches enabled. For an example of a set of tools to maintain one of these maps, please see src/scripts/HenAccess.py in the hen repository.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.google.common.collect.ForwardingMap
ForwardingMap.StandardEntrySet, ForwardingMap.StandardKeySet, ForwardingMap.StandardValues
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
static Function<byte[],byte[]> BYTE_ARRAY_VALUES
          Default deserializer for the constructor if you want to simply store the zookeeper byte[] data in this map.
 
Method Summary
 void clear()
          This map is readonly, this method throws a UnsupportedOperationException
static
<V> ZooKeeperMap<V>
create(ZooKeeperClient zkClient, String nodePath, Function<byte[],V> deserializer)
          Returns an initialized ZooKeeperMap.
protected  Map<String,V> delegate()
           
 V put(String key, V value)
          This map is readonly, this method throws a UnsupportedOperationException
 void putAll(Map<? extends String,? extends V> m)
          This map is readonly, this method throws a UnsupportedOperationException
 V remove(Object key)
          This map is readonly, this method throws a UnsupportedOperationException
 
Methods inherited from class com.google.common.collect.ForwardingMap
containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, size, standardClear, standardContainsKey, standardContainsValue, standardEquals, standardHashCode, standardIsEmpty, standardPutAll, standardRemove, standardToString, values
 
Methods inherited from class com.google.common.collect.ForwardingObject
toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

BYTE_ARRAY_VALUES

public static final Function<byte[],byte[]> BYTE_ARRAY_VALUES
Default deserializer for the constructor if you want to simply store the zookeeper byte[] data in this map.

Method Detail

create

public static <V> ZooKeeperMap<V> create(ZooKeeperClient zkClient,
                                         String nodePath,
                                         Function<byte[],V> deserializer)
                              throws InterruptedException,
                                     org.apache.zookeeper.KeeperException,
                                     ZooKeeperClient.ZooKeeperConnectionException
Returns an initialized ZooKeeperMap. The given path must exist at the time of creation or a KeeperException will be thrown.

Parameters:
zkClient - a zookeeper client
nodePath - path to a node whose data will be watched
deserializer - a function that converts byte[] data from a zk node to this map's value type V
Throws:
InterruptedException - if the underlying zookeeper server transaction is interrupted
KeeperException.NoNodeException - if the given nodePath doesn't exist
org.apache.zookeeper.KeeperException - if the server signals an error
ZooKeeperClient.ZooKeeperConnectionException - if there was a problem connecting to the zookeeper cluster

delegate

protected Map<String,V> delegate()
Overrides:
delegate in class ForwardingMap<String,V>

clear

public void clear()
This map is readonly, this method throws a UnsupportedOperationException

Specified by:
clear in interface Map<String,V>
Overrides:
clear in class ForwardingMap<String,V>

put

public V put(String key,
             V value)
This map is readonly, this method throws a UnsupportedOperationException

Specified by:
put in interface Map<String,V>
Overrides:
put in class ForwardingMap<String,V>

putAll

public void putAll(Map<? extends String,? extends V> m)
This map is readonly, this method throws a UnsupportedOperationException

Specified by:
putAll in interface Map<String,V>
Overrides:
putAll in class ForwardingMap<String,V>

remove

public V remove(Object key)
This map is readonly, this method throws a UnsupportedOperationException

Specified by:
remove in interface Map<String,V>
Overrides:
remove in class ForwardingMap<String,V>