Package com.yahoo.vespa.curator
Class Curator
- java.lang.Object
-
- com.yahoo.component.AbstractComponent
-
- com.yahoo.vespa.curator.Curator
-
- All Implemented Interfaces:
com.yahoo.component.Component
,com.yahoo.component.Deconstructable
,VespaCurator
,AutoCloseable
,Comparable<com.yahoo.component.Component>
- Direct Known Subclasses:
MockCurator
public class Curator extends com.yahoo.component.AbstractComponent implements VespaCurator, AutoCloseable
Curator interface for Vespa. This contains method for constructing common recipes and utilities as well as a small wrapper API for common operations which uses typed paths and avoids throwing checked exceptions.There is a mock implementation in MockCurator.
- Author:
- vegardh, bratseth
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
Curator.CompletionWaiter
Interface for waiting for completion of an operationstatic interface
Curator.DirectoryCache
A listenable cache of all the immediate children of a curator path.static interface
Curator.FileCache
A listenable cache of the content of a single curator path.
-
Constructor Summary
Constructors Modifier Constructor Description Curator(com.yahoo.cloud.config.CuratorConfig curatorConfig, com.yahoo.vespa.zookeeper.VespaZooKeeperServer server)
protected
Curator(String connectionSpec, String zooKeeperEnsembleConnectionSpec, Function<org.apache.curator.RetryPolicy,org.apache.curator.framework.CuratorFramework> curatorFactory)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
boolean
create(com.yahoo.path.Path path)
Creates an empty node at a path, creating any parents as necessary.static Curator
create(String connectionSpec)
Creates a curator instance from a comma-separated string of ZooKeeper host:port stringsstatic Curator
create(String connectionSpec, Optional<File> clientConfigFile)
void
createAtomically(com.yahoo.path.Path... paths)
Creates all the given paths in a single transaction.org.apache.curator.framework.recipes.atomic.DistributedAtomicLong
createAtomicCounter(String path)
For internal use; prefer creating aCuratorCounter
Curator.CompletionWaiter
createCompletionWaiter(com.yahoo.path.Path parentPath, String waiterNode, int numMembers, String id)
Curator.DirectoryCache
createDirectoryCache(String path, boolean cacheData, boolean dataIsCompressed, ExecutorService executorService)
Creates a listenable cache which keeps in sync with changes to all the immediate children of a pathCurator.FileCache
createFileCache(String path, boolean dataIsCompressed)
Creates a listenable cache which keeps in sync with changes to a given nodeorg.apache.curator.framework.recipes.locks.InterProcessLock
createMutex(String lockPath)
For internal use; prefer creating aLock
void
deconstruct()
void
delete(com.yahoo.path.Path path)
Deletes the given path and any children it may have.boolean
exists(com.yahoo.path.Path path)
A convenience method which returns whether the given path existsorg.apache.curator.framework.CuratorFramework
framework()
Returns the curator framework APIList<String>
getChildren(com.yahoo.path.Path path)
Returns the names of the children at the given path.Curator.CompletionWaiter
getCompletionWaiter(com.yahoo.path.Path waiterPath, int numMembers, String id)
Optional<byte[]>
getData(com.yahoo.path.Path path)
Returns the data at the given path, which may be a zero-length buffer if the node exists but have no data.Optional<org.apache.zookeeper.data.Stat>
getStat(com.yahoo.path.Path path)
Returns the stat data at the given path.Lock
lock(com.yahoo.path.Path path, Duration timeout)
Create and acquire a re-entrant lock in given pathvoid
set(com.yahoo.path.Path path, byte[] data)
A convenience method which sets some content at a path.String
zooKeeperEnsembleConnectionSpec()
int
zooKeeperEnsembleCount()
Returns the number of zooKeeper servers in this ensemble.
-
-
-
Method Detail
-
create
public static Curator create(String connectionSpec)
Creates a curator instance from a comma-separated string of ZooKeeper host:port strings
-
createAtomicCounter
public org.apache.curator.framework.recipes.atomic.DistributedAtomicLong createAtomicCounter(String path)
For internal use; prefer creating aCuratorCounter
-
createMutex
public org.apache.curator.framework.recipes.locks.InterProcessLock createMutex(String lockPath)
For internal use; prefer creating aLock
-
getCompletionWaiter
public Curator.CompletionWaiter getCompletionWaiter(com.yahoo.path.Path waiterPath, int numMembers, String id)
-
createCompletionWaiter
public Curator.CompletionWaiter createCompletionWaiter(com.yahoo.path.Path parentPath, String waiterNode, int numMembers, String id)
-
createDirectoryCache
public Curator.DirectoryCache createDirectoryCache(String path, boolean cacheData, boolean dataIsCompressed, ExecutorService executorService)
Creates a listenable cache which keeps in sync with changes to all the immediate children of a path
-
createFileCache
public Curator.FileCache createFileCache(String path, boolean dataIsCompressed)
Creates a listenable cache which keeps in sync with changes to a given node
-
exists
public boolean exists(com.yahoo.path.Path path)
A convenience method which returns whether the given path exists
-
set
public void set(com.yahoo.path.Path path, byte[] data)
A convenience method which sets some content at a path. If the path and any of its parents does not exists they are created.
-
create
public boolean create(com.yahoo.path.Path path)
Creates an empty node at a path, creating any parents as necessary. If the node already exists nothing is done. Returns whether a change was attempted.
-
createAtomically
public void createAtomically(com.yahoo.path.Path... paths)
Creates all the given paths in a single transaction. Any paths which already exists are ignored.
-
delete
public void delete(com.yahoo.path.Path path)
Deletes the given path and any children it may have. If the path does not exists nothing is done.
-
getChildren
public List<String> getChildren(com.yahoo.path.Path path)
Returns the names of the children at the given path. If the path does not exist or have no children an empty list (never null) is returned.
-
getData
public Optional<byte[]> getData(com.yahoo.path.Path path)
Returns the data at the given path, which may be a zero-length buffer if the node exists but have no data. Empty is returned if the path does not exist.
-
getStat
public Optional<org.apache.zookeeper.data.Stat> getStat(com.yahoo.path.Path path)
Returns the stat data at the given path. Empty is returned if the path does not exist.
-
lock
public Lock lock(com.yahoo.path.Path path, Duration timeout)
Create and acquire a re-entrant lock in given path- Specified by:
lock
in interfaceVespaCurator
-
framework
public org.apache.curator.framework.CuratorFramework framework()
Returns the curator framework API
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
-
deconstruct
public void deconstruct()
- Specified by:
deconstruct
in interfacecom.yahoo.component.Deconstructable
- Overrides:
deconstruct
in classcom.yahoo.component.AbstractComponent
-
zooKeeperEnsembleConnectionSpec
public String zooKeeperEnsembleConnectionSpec()
- Returns:
- The non-null connect string containing all ZooKeeper servers in the ensemble. WARNING: This may be different from the servers this Curator may connect to. TODO: Move method out of this class.
-
zooKeeperEnsembleCount
public int zooKeeperEnsembleCount()
Returns the number of zooKeeper servers in this ensemble. WARNING: This may be different from the number of servers this Curator may connect to. TODO: Move method out of this class.
-
-