@InterfaceAudience.Private public abstract class ClientZKSyncer extends ZKListener
getPathsToWatch()
methodModifier and Type | Class and Description |
---|---|
private class |
ClientZKSyncer.ClientZkUpdater
Thread to synchronize znode data to client ZK cluster
|
private static class |
ClientZKSyncer.ZKData
Used to store the newest data which we want to sync to client zk.
|
Modifier and Type | Field and Description |
---|---|
private ZKWatcher |
clientZkWatcher |
private static org.slf4j.Logger |
LOG |
private ConcurrentMap<String,ClientZKSyncer.ZKData> |
queues |
private Server |
server |
watcher
Constructor and Description |
---|
ClientZKSyncer(ZKWatcher watcher,
ZKWatcher clientZkWatcher,
Server server) |
Modifier and Type | Method and Description |
---|---|
private void |
deleteDataForClientZkUntilSuccess(String node) |
private void |
getDataAndWatch(String path) |
protected abstract Set<String> |
getPathsToWatch()
Returns the zk path(s) to watch
|
void |
nodeCreated(String path)
Called when a new node has been created.
|
void |
nodeDataChanged(String path)
Called when an existing node has changed data.
|
void |
nodeDeleted(String path)
Called when a node has been deleted
|
private void |
reconnectAfterExpiration() |
protected void |
refreshWatchingList() |
private void |
removeQueue(String path) |
private void |
setDataForClientZkUntilSuccess(String node,
byte[] data)
Set data for client ZK and retry until succeed.
|
void |
start()
Starts the syncer
|
private void |
startNewSyncThread(String path) |
private void |
upsertQueue(String node,
byte[] data)
Update the value of the single element in queue if any, or else insert.
|
protected abstract boolean |
validate(String path)
Validate whether a znode path is watched by us
|
private void |
watchAndCheckExists(String node) |
getWatcher, nodeChildrenChanged
private static final org.slf4j.Logger LOG
private final ZKWatcher clientZkWatcher
private final ConcurrentMap<String,ClientZKSyncer.ZKData> queues
public ClientZKSyncer(ZKWatcher watcher, ZKWatcher clientZkWatcher, Server server)
private void startNewSyncThread(String path)
public void start() throws org.apache.zookeeper.KeeperException
org.apache.zookeeper.KeeperException
- if error occurs when trying to create base nodes on client ZKprivate void watchAndCheckExists(String node)
private void upsertQueue(String node, byte[] data)
data
- the data to write to queueprivate void setDataForClientZkUntilSuccess(String node, byte[] data) throws InterruptedException
node
- the znode to set on client ZKdata
- the data to set to client ZKInterruptedException
- if the thread is interrupted during processprivate void deleteDataForClientZkUntilSuccess(String node) throws InterruptedException
InterruptedException
private final void reconnectAfterExpiration() throws InterruptedException
InterruptedException
private void getDataAndWatch(String path)
private void removeQueue(String path)
public void nodeCreated(String path)
ZKListener
nodeCreated
in class ZKListener
path
- full path of the new nodepublic void nodeDataChanged(String path)
ZKListener
nodeDataChanged
in class ZKListener
path
- full path of the updated nodepublic void nodeDeleted(String path)
ZKListener
nodeDeleted
in class ZKListener
path
- full path of the deleted nodeprotected abstract boolean validate(String path)
path
- the path to validateprotected abstract Set<String> getPathsToWatch()
protected final void refreshWatchingList()
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.