ZooKeeperWatcher源代码

ZooKeeperWatcher 是 Hadoop HBase 中实现的 ZooKeeper 观察者类,它作为单一的 ZooKeeper 监听器,用于处理 Master、RegionServer 和客户端进程的 ZooKeeper 事件。这个类不仅实现了 Watcher 接口,还负责管理和维护与 ZooKeeper 的连接。当接收到 ZooKeeper 事件时,ZooKeeperWatcher 将事件分发给已注册的监听器。同时,它还处理连接相关的异常和事件,如连接状态变化、节点创建、删除、数据改变和子节点变更等。
摘要由CSDN通过智能技术生成
1   /**
2   *
3   * Licensed to the Apache Software Foundation (ASF) under one
4   * or more contributor license agreements.  See the NOTICE file
5   * distributed with this work for additional information
6   * regarding copyright ownership.  The ASF licenses this file
7   * to you under the Apache License, Version 2.0 (the
8   * "License"); you may not use this file except in compliance
9   * with the License.  You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19  package org.apache.hadoop.hbase.zookeeper;
20 
21  import java.io.Closeable;
22  import java.io.IOException;
23  import java.util.ArrayList;
24  import java.util.List;
25  import java.util.concurrent.CopyOnWriteArrayList;
26  import java.util.concurrent.CountDownLatch;
27 
28  import org.apache.commons.logging.Log;
29  import org.apache.commons.logging.LogFactory;
30  import org.apache.hadoop.classification.InterfaceAudience;
31  import org.apache.hadoop.conf.Configuration;
32  import org.apache.hadoop.hbase.Abortable;
33  import org.apache.hadoop.hbase.HConstants;
34  import org.apache.hadoop.hbase.ZooKeeperConnectionException;
35  import org.apache.hadoop.hbase.util.Threads;
36  import org.apache.zookeeper.KeeperException;
37  import org.apache.zookeeper.WatchedEvent;
38  import org.apache.zookeeper.Watcher;
39  import org.apache.zookeeper.ZooDefs;
40  import org.apache.zookeeper.data.ACL;
41 
42  /**
43  * Acts as the single ZooKeeper Watcher.  One instance of this is instantiated
44  * for each Master, RegionServer, and client process.
45  *
46  * <p>This is the only class that implements {@link Watcher}.  Other internal
47  * classes which need to be notified of ZooKeeper events must register with
48  * the local instance of this watcher via {@link #registerListener}.
49  *
50  * <p>This class also holds and manages the connection to ZooKeeper.  Code to
51  * deal with connection related events and exceptions are handled here.
52  */
53  @InterfaceAudience.Private
54  public class ZooKeeperWatcher implements Watcher, Abortable, Closeable {
55    private static final Log LOG = LogFactory.getLog(ZooKeeperWatcher. class);
56 
57    // Identifier for this watcher (for logging only).  It is made of the prefix
58    // passed on construction and the zookeeper sessionid.
59    private String identifier;
60 
61    // zookeeper quorum
62    private String quorum;
63 
64    // zookeeper connection
65    private RecoverableZooKeeper recoverableZooKeeper;
66 
67    // abortable in case of zk failure
68    protected Abortable abortable;
69    // Used if abortable is null
70    private boolean aborted = false;
71 
72    // listeners to be notified
73    private final List<ZooKeeperListener> listeners =
74      new CopyOnWriteArrayList<ZooKeeperListener>();
75 
76    // Used by ZKUtil:waitForZKConnectionIfAuthenticating to wait for SASL
77    // negotiation to complete
78    public CountDownLatch saslLatch = new CountDownLatch(1);
79 
80    // node names
81 
82    // base znode for this cluster
83    public String baseZNode;
84    // znode containing location of server hosting meta region
85    public String metaServerZNode;
86    // znode containing ephemeral nodes of the regionservers
87    public String rsZNode;
88    // znode containing ephemeral nodes of the draining regionservers
89    public String drainingZNode;
90    // znode of currently active master
91    private String masterAddressZNode;
92    // znode of this master in backup master directory, if not the active master
93    public String backupMasterAddressesZNode;
94    // znode containing the current cluster state
95    public String clusterStateZNode;
96    // znode used for region transitioning and assignment
97    public String assignmentZNode;
98    // znode used for table disabling/enabling
99    public String tableZNode;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值