public interface

BaseDataAccessor

org.apache.helix.BaseDataAccessor<T>
Known Indirect Subclasses

Class Overview

Generic interface for accessing and manipulating data on a backing store like Zookeeper.

Summary

Public Methods
abstract boolean create(String path, T record, int options)
This will always attempt to create the znode, if it exists it will return false.
abstract boolean[] createChildren(List<String> paths, List<T> records, int options)
Use it when creating children under a parent node.
abstract boolean[] exists(List<String> paths, int options)
checks if the all the paths exists
abstract boolean exists(String path, int options)
checks if the path exists in zk
abstract List<T> get(List<String> paths, List<Stat> stats, int options)
Get List of T corresponding to the paths using async api
abstract T get(String path, Stat stat, int options)
Get the T corresponding to the path
abstract List<String> getChildNames(String parentPath, int options)
Returns the child names given a parent path
abstract List<T> getChildren(String parentPath, List<Stat> stats, int options)
Get the children under a parent path using async api
abstract Stat getStat(String path, int options)
Get the stats of a single path
abstract Stat[] getStats(List<String> paths, int options)
Get the stats of all the paths
abstract boolean[] remove(List<String> paths, int options)
remove multiple paths using async api.
abstract boolean remove(String path, int options)
This will remove the ZNode and all its descendants if any
abstract void reset()
TODO refactor this.
abstract boolean set(String path, T record, int options)
This will always attempt to set the data on existing node.
abstract boolean set(String path, T record, int expectVersion, int options)
This will attempt to set the data on existing node only if version matches.
abstract boolean[] setChildren(List<String> paths, List<T> records, int options)
can set multiple children under a parent node.
abstract List<String> subscribeChildChanges(String path, IZkChildListener listener)
Subscribe child listener to path
abstract void subscribeDataChanges(String path, IZkDataListener listener)
Subscribe data listener to path
abstract void unsubscribeChildChanges(String path, IZkChildListener listener)
Unsubscribe child listener to path
abstract void unsubscribeDataChanges(String path, IZkDataListener listener)
Unsubscribe data listener to path
abstract boolean update(String path, DataUpdater<T> updater, int options)
This will attempt to update the data using the updater.
abstract boolean[] updateChildren(List<String> paths, List<DataUpdater<T>> updaters, int options)
Can update multiple nodes using async api for better performance.

Public Methods

public abstract boolean create (String path, T record, 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
record 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 abstract 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 abstract 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 abstract 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 abstract 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 abstract 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 abstract 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 abstract 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 abstract 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 abstract 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 abstract 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 abstract 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 abstract void reset ()

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

public abstract boolean set (String path, T record, 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
record 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 abstract boolean set (String path, T record, 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
record 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 abstract 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 abstract 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 abstract 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 abstract 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 abstract 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 abstract 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 abstract 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