org.apache.curator.framework.recipes.cache
Class NodeCache

java.lang.Object
  extended by org.apache.curator.framework.recipes.cache.NodeCache
All Implemented Interfaces:
Closeable

public class NodeCache
extends Object
implements Closeable

A utility that attempts to keep the data from a node locally cached. This class will watch the node, respond to update/create/delete events, pull down the data, etc. You can register a listener that will get notified when changes occur.

IMPORTANT - it's not possible to stay transactionally in sync. Users of this class must be prepared for false-positives and false-negatives. Additionally, always use the version number when updating data to avoid overwriting another process' change.


Constructor Summary
NodeCache(org.apache.curator.framework.CuratorFramework client, String path)
           
NodeCache(org.apache.curator.framework.CuratorFramework client, String path, boolean dataIsCompressed)
           
 
Method Summary
 void close()
           
 ChildData getCurrentData()
          Return the current data.
 org.apache.curator.framework.listen.ListenerContainer<NodeCacheListener> getListenable()
          Return the cache listenable
 void rebuild()
          NOTE: this is a BLOCKING method.
 void start()
          Start the cache.
 void start(boolean buildInitial)
          Same as start() but gives the option of doing an initial build
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NodeCache

public NodeCache(org.apache.curator.framework.CuratorFramework client,
                 String path)
Parameters:
client - curztor client
path - the full path to the node to cache

NodeCache

public NodeCache(org.apache.curator.framework.CuratorFramework client,
                 String path,
                 boolean dataIsCompressed)
Parameters:
client - curztor client
path - the full path to the node to cache
dataIsCompressed - if true, data in the path is compressed
Method Detail

start

public void start()
           throws Exception
Start the cache. The cache is not started automatically. You must call this method.

Throws:
Exception - errors

start

public void start(boolean buildInitial)
           throws Exception
Same as start() but gives the option of doing an initial build

Parameters:
buildInitial - if true, rebuild() will be called before this method returns in order to get an initial view of the node
Throws:
Exception - errors

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Throws:
IOException

getListenable

public org.apache.curator.framework.listen.ListenerContainer<NodeCacheListener> getListenable()
Return the cache listenable

Returns:
listenable

rebuild

public void rebuild()
             throws Exception
NOTE: this is a BLOCKING method. Completely rebuild the internal cache by querying for all needed data WITHOUT generating any events to send to listeners.

Throws:
Exception - errors

getCurrentData

public ChildData getCurrentData()
Return the current data. There are no guarantees of accuracy. This is merely the most recent view of the data. If the node does not exist, this returns null

Returns:
data or null


Copyright © 2011–2014 The Apache Software Foundation. All rights reserved.