public class

ZkCacheBaseDataAccessor

extends Object
implements HelixPropertyStore<T>
java.lang.Object
   ↳ org.apache.helix.manager.zk.ZkCacheBaseDataAccessor<T>
Known Direct Subclasses

Summary

Fields
protected WriteThroughCache<T> _wtCache
protected ZkCallbackCache<T> _zkCache
Public Constructors
ZkCacheBaseDataAccessor(ZkBaseDataAccessor<T> baseAccessor, List<String> wtCachePaths)
ZkCacheBaseDataAccessor(ZkBaseDataAccessor<T> baseAccessor, String chrootPath, List<String> wtCachePaths, List<String> zkCachePaths)
ZkCacheBaseDataAccessor(String zkAddress, ZkSerializer serializer, String chrootPath, List<String> wtCachePaths, List<String> zkCachePaths)
Public Methods
boolean create(String path, T data, int options)
This will always attempt to create the znode, if it exists it will return false.
boolean[] createChildren(List<String> paths, List<T> records, int options)
Use it when creating children under a parent node.
boolean[] exists(List<String> paths, int options)
checks if the all the paths exists
boolean exists(String path, int options)
checks if the path exists in zk
List<T> get(List<String> paths, List<Stat> stats, int options)
Get List of T corresponding to the paths using async api
T get(String path, Stat stat, int options)
Get the T corresponding to the path
List<String> getChildNames(String parentPath, int options)
Returns the child names given a parent path
List<T> getChildren(String parentPath, List<Stat> stats, int options)
Get the children under a parent path using async api
Stat getStat(String path, int options)
Get the stats of a single path
Stat[] getStats(List<String> paths, int options)
Get the stats of all the paths
boolean[] remove(List<String> paths, int options)
remove multiple paths using async api.
boolean remove(String path, int options)
This will remove the ZNode and all its descendants if any
void reset()
TODO refactor this.
boolean set(String path, T data, int options)
This will always attempt to set the data on existing node.
boolean set(String path, T data, int expectVersion, int options)
This will attempt to set the data on existing node only if version matches.
boolean[] setChildren(List<String> paths, List<T> records, int options)
can set multiple children under a parent node.
void start()
Perform resource allocation when property store starts Resource allocation includes: - start an internal thread for fire callbacks
void stop()
Perform clean up when property store stops Cleanup includes: - stop the internal thread for fire callbacks
void subscribe(String parentPath, HelixPropertyListener listener)
Register a listener to a parent path.
List<String> subscribeChildChanges(String path, IZkChildListener listener)
Subscribe child listener to path
void subscribeDataChanges(String path, IZkDataListener listener)
Subscribe data listener to path
void unsubscribe(String parentPath, HelixPropertyListener listener)
Remove a listener from a parent path.
void unsubscribeChildChanges(String path, IZkChildListener listener)
Unsubscribe child listener to path
void unsubscribeDataChanges(String path, IZkDataListener listener)
Unsubscribe data listener to path
boolean update(String path, DataUpdater<T> updater, int options)
This will attempt to update the data using the updater.
boolean[] updateChildren(List<String> paths, List<DataUpdater<T>> updaters, int options)
Can update multiple nodes using async api for better performance.
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.apache.helix.BaseDataAccessor
From interface org.apache.helix.store.HelixPropertyStore

Fields

protected WriteThroughCache<T> _wtCache

protected ZkCallbackCache<T> _zkCache

Public Constructors

public ZkCacheBaseDataAccessor (ZkBaseDataAccessor<T> baseAccessor, List<String> wtCachePaths)

public ZkCacheBaseDataAccessor (ZkBaseDataAccessor<T> baseAccessor, String chrootPath, List<String> wtCachePaths, List<String> zkCachePaths)

public ZkCacheBaseDataAccessor (String zkAddress, ZkSerializer serializer, String chrootPath, List<String> wtCachePaths, List<String> zkCachePaths)

Public Methods

public boolean create (String path, T data, int options)

This will always attempt to create the znode, if it exists it will return false. Will create parents if they do not exist. For performance reasons, it may try to create child first and only if it fails it will try to create parents

Parameters
path path to the ZNode to create
data the data to write to the ZNode
options Set the type of ZNode see the valid values in AccessOption
Returns
  • true if creation succeeded, false otherwise (e.g. if the ZNode exists)

public boolean[] createChildren (List<String> paths, List<T> records, int options)

Use it when creating children under a parent node. This will use async api for better performance. If the child already exists it will return false.

Parameters
paths the paths to the children ZNodes
options Set the type of ZNode see the valid values in AccessOption
Returns
  • For each child: true if creation succeeded, false otherwise (e.g. if the child exists)

public boolean[] exists (List<String> paths, int options)

checks if the all the paths exists

Parameters
paths paths to the ZNodes to test
options Set the type of ZNode see the valid values in AccessOption
Returns
  • for each path, true if a valid ZNode exists, false otherwise

public boolean exists (String path, int options)

checks if the path exists in zk

Parameters
path path to the ZNode to test
options Set the type of ZNode see the valid values in AccessOption
Returns
  • true if the ZNode exists, false otherwise

public List<T> get (List<String> paths, List<Stat> stats, int options)

Get List of T corresponding to the paths using async api

Parameters
paths paths to the ZNodes
stats retrieve a list of stats for the ZNodes
options Set the type of ZNode see the valid values in AccessOption
Returns
  • List of record data stored at each ZNode

public T get (String path, Stat stat, int options)

Get the T corresponding to the path

Parameters
path path to the ZNode
stat retrieve the stat of the ZNode
options Set the type of ZNode see the valid values in AccessOption
Returns
  • the record data stored at the ZNode

public List<String> getChildNames (String parentPath, int options)

Returns the child names given a parent path

Parameters
parentPath path to the immediate parent ZNode
options Set the type of ZNode see the valid values in AccessOption
Returns
  • a list of the names of all of the parent ZNode's children

public List<T> getChildren (String parentPath, List<Stat> stats, int options)

Get the children under a parent path using async api

Parameters
stats Zookeeper Stat objects corresponding to each child
options Set the type of ZNode see the valid values in AccessOption
Returns
  • A list of children of the parent ZNode

public Stat getStat (String path, int options)

Get the stats of a single path

Parameters
path path of the ZNode to query
options Set the type of ZNode see the valid values in AccessOption
Returns
  • Zookeeper Stat object corresponding to the ZNode

public Stat[] getStats (List<String> paths, int options)

Get the stats of all the paths

Parameters
paths paths of the ZNodes to query
options Set the type of ZNode see the valid values in AccessOption
Returns
  • Zookeeper Stat object for each path

public boolean[] remove (List<String> paths, int options)

remove multiple paths using async api. will remove any child nodes if any

Parameters
paths paths to the ZNodes to remove
options Set the type of ZNode see the valid values in AccessOption
Returns
  • For each ZNode, true if successfully removed, false otherwise

public boolean remove (String path, int options)

This will remove the ZNode and all its descendants if any

Parameters
path path to the root ZNode to remove
options Set the type of ZNode see the valid values in AccessOption
Returns
  • true if the removal succeeded, false otherwise

public void reset ()

TODO refactor this. reset() should not be in data accessor reset the cache if any, when session expiry happens

public boolean set (String path, T data, int options)

This will always attempt to set the data on existing node. If the ZNode does not exist it will create it and all its parents ZNodes if necessary

Parameters
path path to the ZNode to set
data the data to write to the ZNode
options Set the type of ZNode see the valid values in AccessOption
Returns
  • true if data was successfully set, false otherwise

public boolean set (String path, T data, int expectVersion, int options)

This will attempt to set the data on existing node only if version matches. If the ZNode does not exist it will create it and all its parent ZNodes only if expected version is -1

Parameters
path path to the ZNode to set
data the data to write to the ZNode
expectVersion the expected version of the data to be overwritten, -1 means match any version
options Set the type of ZNode see the valid values in AccessOption
Returns
  • true if data was successfully set, false otherwise (e.g. if the version mismatches)

public boolean[] setChildren (List<String> paths, List<T> records, int options)

can set multiple children under a parent node. This will use async api for better performance. If this child does not exist it will create it.

Parameters
paths the paths to the children ZNodes
options Set the type of ZNode see the valid values in AccessOption
Returns
  • For each child: true if the data was set, false otherwise

public void start ()

Perform resource allocation when property store starts Resource allocation includes: - start an internal thread for fire callbacks

public void stop ()

Perform clean up when property store stops Cleanup includes: - stop the internal thread for fire callbacks

public void subscribe (String parentPath, HelixPropertyListener listener)

Register a listener to a parent path. Subscribing to a parent path means any changes happening under the parent path will notify the listener

public List<String> subscribeChildChanges (String path, IZkChildListener listener)

Subscribe child listener to path

Parameters
path path to the immediate parent ZNode
listener the listener to register for changes

public void subscribeDataChanges (String path, IZkDataListener listener)

Subscribe data listener to path

Parameters
path path to the ZNode to listen to
listener the listener to register for changes

public void unsubscribe (String parentPath, HelixPropertyListener listener)

Remove a listener from a parent path. This will remove the listener from receiving any notifications happening under the parent path

public void unsubscribeChildChanges (String path, IZkChildListener listener)

Unsubscribe child listener to path

Parameters
path path to the immediate parent ZNode
listener the listener currently subscribed to the children

public void unsubscribeDataChanges (String path, IZkDataListener listener)

Unsubscribe data listener to path

Parameters
path path to the ZNode to stop listening to
listener the listener currently subscribed to the ZNode

public boolean update (String path, DataUpdater<T> updater, int options)

This will attempt to update the data using the updater. If the ZNode does not exist it will create it and all its parent ZNodes. Updater will be invoked with null value if node does not exist.

Parameters
path path to the ZNode to update
updater an update routine for the data to merge in
options Set the type of ZNode see the valid values in AccessOption
Returns
  • true if data update succeeded, false otherwise

public boolean[] updateChildren (List<String> paths, List<DataUpdater<T>> updaters, int options)

Can update multiple nodes using async api for better performance. If a child does not exist it will create it.

Parameters
updaters List of update routines for records to update
options Set the type of ZNode see the valid values in AccessOption
Returns
  • For each child, true if the data is updated successfully, false otherwise