org.apache.zookeeper.AsyncCallback, org.apache.zookeeper.AsyncCallback.StatCallback, org.apache.zookeeper.AsyncCallback.StringCallback@Private
@Evolving
public class ActiveStandbyElector
extends java.lang.Object
implements org.apache.zookeeper.AsyncCallback.StatCallback, org.apache.zookeeper.AsyncCallback.StringCallback
ActiveStandbyElector.ActiveStandbyElectorCallback
to interact with the elector| Modifier and Type | Class | 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.AllChildrenNumberCallback, org.apache.zookeeper.AsyncCallback.Children2Callback, org.apache.zookeeper.AsyncCallback.ChildrenCallback, org.apache.zookeeper.AsyncCallback.Create2Callback, org.apache.zookeeper.AsyncCallback.DataCallback, org.apache.zookeeper.AsyncCallback.EphemeralsCallback, org.apache.zookeeper.AsyncCallback.MultiCallback, org.apache.zookeeper.AsyncCallback.StatCallback, org.apache.zookeeper.AsyncCallback.StringCallback, org.apache.zookeeper.AsyncCallback.VoidCallback| Modifier and Type | Field | Description |
|---|---|---|
protected static java.lang.String |
BREADCRUMB_FILENAME |
|
protected static java.lang.String |
LOCK_FILENAME |
Name of the lock znode used by the library.
|
static org.slf4j.Logger |
LOG |
| Constructor | Description |
|---|---|
ActiveStandbyElector(java.lang.String zookeeperHostPorts,
int zookeeperSessionTimeout,
java.lang.String parentZnodeName,
java.util.List<org.apache.zookeeper.data.ACL> acl,
java.util.List<ZKUtil.ZKAuthInfo> authInfo,
ActiveStandbyElector.ActiveStandbyElectorCallback app,
int maxRetryNum,
boolean failFast,
SecurityUtil.TruststoreKeystore truststoreKeystore) |
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. |
ActiveStandbyElector(java.lang.String zookeeperHostPorts,
int zookeeperSessionTimeout,
java.lang.String parentZnodeName,
java.util.List<org.apache.zookeeper.data.ACL> acl,
java.util.List<ZKUtil.ZKAuthInfo> authInfo,
ActiveStandbyElector.ActiveStandbyElectorCallback app,
int maxRetryNum,
SecurityUtil.TruststoreKeystore truststoreKeystore) |
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 | Description |
|---|---|---|
void |
clearParentZNode() |
Clear all of the state held within the parent ZNode.
|
protected org.apache.zookeeper.ZooKeeper |
connectToZooKeeper() |
Get a new zookeeper client instance.
|
protected org.apache.zookeeper.ZooKeeper |
createZooKeeper() |
Get a new zookeeper client instance.
|
void |
ensureParentZNode() |
Utility function to ensure that the configured base znode exists.
|
byte[] |
getActiveData() |
get data set by the active leader
|
java.lang.String |
getHAZookeeperConnectionState() |
|
boolean |
getWantToBeInElection() |
|
protected org.apache.zookeeper.ZooKeeper |
initiateZookeeper(org.apache.zookeeper.client.ZKClientConfig zkClientConfig) |
|
void |
joinElection(byte[] data) |
To participate in election, the app will call joinElection.
|
boolean |
parentZNodeExists() |
|
void |
processResult(int rc,
java.lang.String path,
java.lang.Object ctx,
java.lang.String name) |
interface implementation of Zookeeper callback for create
|
void |
processResult(int rc,
java.lang.String path,
java.lang.Object ctx,
org.apache.zookeeper.data.Stat stat) |
interface implementation of Zookeeper callback for monitor (exists)
|
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.
|
void |
terminateConnection() |
|
java.lang.String |
toString() |
@VisibleForTesting protected static final java.lang.String LOCK_FILENAME
@VisibleForTesting protected static final java.lang.String BREADCRUMB_FILENAME
public static final org.slf4j.Logger LOG
public ActiveStandbyElector(java.lang.String zookeeperHostPorts,
int zookeeperSessionTimeout,
java.lang.String parentZnodeName,
java.util.List<org.apache.zookeeper.data.ACL> acl,
java.util.List<ZKUtil.ZKAuthInfo> authInfo,
ActiveStandbyElector.ActiveStandbyElectorCallback app,
int maxRetryNum,
SecurityUtil.TruststoreKeystore truststoreKeystore)
throws java.io.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 objectmaxRetryNum - maxRetryNum.truststoreKeystore - truststore keystore, that we will use for ZK if SSL/TLS is enabledjava.io.IOException - raised on errors performing I/O.HadoopIllegalArgumentException - if valid data is not supplied.org.apache.zookeeper.KeeperException - other zookeeper operation errors.public ActiveStandbyElector(java.lang.String zookeeperHostPorts,
int zookeeperSessionTimeout,
java.lang.String parentZnodeName,
java.util.List<org.apache.zookeeper.data.ACL> acl,
java.util.List<ZKUtil.ZKAuthInfo> authInfo,
ActiveStandbyElector.ActiveStandbyElectorCallback app,
int maxRetryNum,
boolean failFast,
SecurityUtil.TruststoreKeystore truststoreKeystore)
throws java.io.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 objectfailFast - whether need to add the retry when establishing ZK connection.maxRetryNum - max Retry NumtruststoreKeystore - truststore keystore, that we will use for ZK if SSL/TLS is enabledjava.io.IOException - raised on errors performing I/O.HadoopIllegalArgumentException - if valid data is not supplied.org.apache.zookeeper.KeeperException - other zookeeper operation errors.public 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 java.io.IOException,
java.lang.InterruptedException
java.io.IOException - raised on errors performing I/O.java.lang.InterruptedException - interrupted exception.public void ensureParentZNode()
throws java.io.IOException,
java.lang.InterruptedException,
org.apache.zookeeper.KeeperException
java.io.IOException - raised on errors performing I/O.java.lang.InterruptedException - interrupted exception.org.apache.zookeeper.KeeperException - other zookeeper operation errors.public void clearParentZNode()
throws java.io.IOException,
java.lang.InterruptedException
java.io.IOException - raised on errors performing I/O.java.lang.InterruptedException - interrupted exception.public 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,
java.lang.InterruptedException,
java.io.IOException
ActiveStandbyElector.ActiveNotFoundException - when there is no active leaderorg.apache.zookeeper.KeeperException - other zookeeper operation errorsjava.lang.InterruptedException - interrupted exception.java.io.IOException - when ZooKeeper connection could not be establishedpublic void processResult(int rc,
java.lang.String path,
java.lang.Object ctx,
java.lang.String name)
processResult in interface org.apache.zookeeper.AsyncCallback.StringCallbackpublic void processResult(int rc,
java.lang.String path,
java.lang.Object ctx,
org.apache.zookeeper.data.Stat stat)
processResult in interface org.apache.zookeeper.AsyncCallback.StatCallback@VisibleForTesting public boolean getWantToBeInElection()
protected org.apache.zookeeper.ZooKeeper connectToZooKeeper()
throws java.io.IOException,
org.apache.zookeeper.KeeperException
java.io.IOException - raised on errors performing I/O.org.apache.zookeeper.KeeperException - zookeeper connectionloss exceptionprotected org.apache.zookeeper.ZooKeeper createZooKeeper()
throws java.io.IOException
java.io.IOException - raised on errors performing I/O.protected org.apache.zookeeper.ZooKeeper initiateZookeeper(org.apache.zookeeper.client.ZKClientConfig zkClientConfig)
throws java.io.IOException
java.io.IOException@VisibleForTesting protected void sleepFor(int sleepMs)
sleepMs - sleep ms.@Private public void terminateConnection()
public java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.String getHAZookeeperConnectionState()
Copyright © 2008–2025 Apache Software Foundation. All rights reserved.