@InterfaceAudience.Private @InterfaceStability.Evolving public class ActiveStandbyElector extends Object implements org.apache.zookeeper.AsyncCallback.StatCallback, org.apache.zookeeper.AsyncCallback.StringCallback
ActiveStandbyElector.ActiveStandbyElectorCallback
to interact with the elector| Modifier and Type | Class and Description |
|---|---|
static class |
ActiveStandbyElector.ActiveNotFoundException
Exception thrown when there is no active leader
|
static interface |
ActiveStandbyElector.ActiveStandbyElectorCallback
Callback interface to interact with the ActiveStandbyElector object.
|
org.apache.zookeeper.AsyncCallback.ACLCallback, org.apache.zookeeper.AsyncCallback.Children2Callback, org.apache.zookeeper.AsyncCallback.ChildrenCallback, org.apache.zookeeper.AsyncCallback.DataCallback, org.apache.zookeeper.AsyncCallback.StatCallback, org.apache.zookeeper.AsyncCallback.StringCallback, org.apache.zookeeper.AsyncCallback.VoidCallback| Modifier and Type | Field and Description |
|---|---|
protected static String |
BREADCRUMB_FILENAME |
protected static String |
LOCK_FILENAME
Name of the lock znode used by the library.
|
static org.apache.commons.logging.Log |
LOG |
| Constructor and Description |
|---|
ActiveStandbyElector(String zookeeperHostPorts,
int zookeeperSessionTimeout,
String parentZnodeName,
List<org.apache.zookeeper.data.ACL> acl,
List<ZKUtil.ZKAuthInfo> authInfo,
ActiveStandbyElector.ActiveStandbyElectorCallback app)
Create a new ActiveStandbyElector object
The elector is created by providing to it the Zookeeper configuration, the parent znode under which to create the znode and a reference to the callback interface. |
| Modifier and Type | Method and Description |
|---|---|
void |
clearParentZNode()
Clear all of the state held within the parent ZNode.
|
void |
ensureParentZNode()
Utility function to ensure that the configured base znode exists.
|
byte[] |
getActiveData()
get data set by the active leader
|
protected org.apache.zookeeper.ZooKeeper |
getNewZooKeeper()
Get a new zookeeper client instance.
|
void |
joinElection(byte[] data)
To participate in election, the app will call joinElection.
|
boolean |
parentZNodeExists() |
void |
processResult(int rc,
String path,
Object ctx,
org.apache.zookeeper.data.Stat stat)
interface implementation of Zookeeper callback for monitor (exists)
|
void |
processResult(int rc,
String path,
Object ctx,
String name)
interface implementation of Zookeeper callback for create
|
void |
quitElection(boolean needFence)
Any service instance can drop out of the election by calling quitElection.
|
protected void |
sleepFor(int sleepMs)
Sleep for the given number of milliseconds.
|
String |
toString() |
protected static final String LOCK_FILENAME
protected static final String BREADCRUMB_FILENAME
public static final org.apache.commons.logging.Log LOG
public ActiveStandbyElector(String zookeeperHostPorts, int zookeeperSessionTimeout, String parentZnodeName, List<org.apache.zookeeper.data.ACL> acl, List<ZKUtil.ZKAuthInfo> authInfo, ActiveStandbyElector.ActiveStandbyElectorCallback app) throws IOException, HadoopIllegalArgumentException, org.apache.zookeeper.KeeperException
zookeeperHostPorts - ZooKeeper hostPort for all ZooKeeper serverszookeeperSessionTimeout - ZooKeeper session timeoutparentZnodeName - znode under which to create the lockacl - ZooKeeper ACL'sauthInfo - a list of authentication credentials to add to the
ZK connectionapp - reference to callback interface objectIOExceptionHadoopIllegalArgumentExceptionorg.apache.zookeeper.KeeperExceptionpublic void joinElection(byte[] data)
throws HadoopIllegalArgumentException
data - to be set by the app. non-null data must be set.HadoopIllegalArgumentException - if valid data is not suppliedpublic boolean parentZNodeExists()
throws IOException,
InterruptedException
IOExceptionInterruptedExceptionpublic void ensureParentZNode()
throws IOException,
InterruptedException
IOExceptionInterruptedExceptionpublic void clearParentZNode()
throws IOException,
InterruptedException
IOExceptionInterruptedExceptionpublic void quitElection(boolean needFence)
needFence - true if the underlying daemon may need to be fenced
if a failover occurs due to dropping out of the election.public byte[] getActiveData()
throws ActiveStandbyElector.ActiveNotFoundException,
org.apache.zookeeper.KeeperException,
InterruptedException,
IOException
ActiveStandbyElector.ActiveNotFoundException - when there is no active leaderorg.apache.zookeeper.KeeperException - other zookeeper operation errorsInterruptedExceptionIOException - when ZooKeeper connection could not be establishedpublic void processResult(int rc,
String path,
Object ctx,
String name)
processResult in interface org.apache.zookeeper.AsyncCallback.StringCallbackpublic void processResult(int rc,
String path,
Object ctx,
org.apache.zookeeper.data.Stat stat)
processResult in interface org.apache.zookeeper.AsyncCallback.StatCallbackprotected org.apache.zookeeper.ZooKeeper getNewZooKeeper()
throws IOException,
org.apache.zookeeper.KeeperException
IOExceptionorg.apache.zookeeper.KeeperException - zookeeper connectionloss exceptionprotected void sleepFor(int sleepMs)
Copyright © 2013 Apache Software Foundation. All rights reserved.