gpt4 book ai didi

org.apache.hadoop.hbase.zookeeper.ZKNodeTracker类的使用及代码示例

转载 作者:知者 更新时间:2024-03-13 09:48:41 25 4
gpt4 key购买 nike

本文整理了Java中org.apache.hadoop.hbase.zookeeper.ZKNodeTracker类的一些代码示例,展示了ZKNodeTracker类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZKNodeTracker类的具体详情如下:
包路径:org.apache.hadoop.hbase.zookeeper.ZKNodeTracker
类名称:ZKNodeTracker

ZKNodeTracker介绍

[英]Tracks the availability and value of a single ZooKeeper node.

Utilizes the ZKListener interface to get the necessary ZooKeeper events related to the node.

This is the base class used by trackers in both the Master and RegionServers.
[中]跟踪单个ZooKeeper节点的可用性和价值。
利用ZKListener接口获取与节点相关的必要ZooKeeper事件。
这是主服务器和区域服务器中跟踪器使用的基类。

代码示例

代码示例来源:origin: apache/hbase

/**
 * Gets the data of the node, blocking until the node is available.
 *
 * @return data of the node
 * @throws InterruptedException if the waiting thread is interrupted
 */
public synchronized byte [] blockUntilAvailable()
 throws InterruptedException {
 return blockUntilAvailable(0, false);
}

代码示例来源:origin: apache/hbase

/**
 * Checks if cluster is up.
 * @return true if the cluster up ('shutdown' is its name up in zk) znode
 *         exists with data, false if not
 */
public boolean isClusterUp() {
 return super.getData(false) != null;
}

代码示例来源:origin: apache/hbase

@Override
public synchronized void nodeDataChanged(String path) {
 if(path.equals(node)) {
  nodeCreated(path);
 }
}

代码示例来源:origin: apache/hbase

/**
 * Set the switch on/off
 * @param enabled switch enabled or not?
 * @throws KeeperException keepException will be thrown out
 */
public void setSwitchEnabled(boolean enabled) throws KeeperException {
 byte [] upData = toByteArray(enabled);
 try {
  ZKUtil.setData(watcher, node, upData);
 } catch(KeeperException.NoNodeException nne) {
  ZKUtil.createAndWatch(watcher, node, upData);
 }
 super.nodeDataChanged(node);
}

代码示例来源:origin: apache/hbase

@Override
public synchronized void nodeCreated(String path) {
 if (!path.equals(node)) {
  return;
 }
 try {
  byte [] data = ZKUtil.getDataAndWatch(watcher, node);
  if (data != null) {
   this.data = data;
   notifyAll();
  } else {
   nodeDeleted(path);
  }
 } catch(KeeperException e) {
  abortable.abort("Unexpected exception handling nodeCreated event", e);
 }
}

代码示例来源:origin: apache/hbase

/**
 * Starts the tracking of the node in ZooKeeper.
 *
 * <p>Use {@link #blockUntilAvailable()} to block until the node is available
 * or {@link #getData(boolean)} to get the data of the node if it is available.
 */
public synchronized void start() {
 this.watcher.registerListener(this);
 try {
  if(ZKUtil.watchAndCheckExists(watcher, node)) {
   byte [] data = ZKUtil.getDataAndWatch(watcher, node);
   if(data != null) {
    this.data = data;
   } else {
    // It existed but now does not, try again to ensure a watch is set
    LOG.debug("Try starting again because there is no data from " + node);
    start();
   }
  }
 } catch (KeeperException e) {
  abortable.abort("Unexpected exception during initialization, aborting", e);
 }
}

代码示例来源:origin: apache/hbase

/**
 * Set region normalizer on/off
 * @param normalizerOn whether normalizer should be on or off
 * @throws KeeperException if a ZooKeeper operation fails
 */
public void setNormalizerOn(boolean normalizerOn) throws KeeperException {
 byte [] upData = toByteArray(normalizerOn);
 try {
  ZKUtil.setData(watcher, watcher.getZNodePaths().regionNormalizerZNode, upData);
 } catch(KeeperException.NoNodeException nne) {
  ZKUtil.createAndWatch(watcher, watcher.getZNodePaths().regionNormalizerZNode, upData);
 }
 super.nodeDataChanged(watcher.getZNodePaths().regionNormalizerZNode);
}

代码示例来源:origin: org.apache.hbase/hbase-zookeeper

@Override
public synchronized void nodeCreated(String path) {
 if (!path.equals(node)) {
  return;
 }
 try {
  byte [] data = ZKUtil.getDataAndWatch(watcher, node);
  if (data != null) {
   this.data = data;
   notifyAll();
  } else {
   nodeDeleted(path);
  }
 } catch(KeeperException e) {
  abortable.abort("Unexpected exception handling nodeCreated event", e);
 }
}

代码示例来源:origin: org.apache.hbase/hbase-zookeeper

/**
 * Starts the tracking of the node in ZooKeeper.
 *
 * <p>Use {@link #blockUntilAvailable()} to block until the node is available
 * or {@link #getData(boolean)} to get the data of the node if it is available.
 */
public synchronized void start() {
 this.watcher.registerListener(this);
 try {
  if(ZKUtil.watchAndCheckExists(watcher, node)) {
   byte [] data = ZKUtil.getDataAndWatch(watcher, node);
   if(data != null) {
    this.data = data;
   } else {
    // It existed but now does not, try again to ensure a watch is set
    LOG.debug("Try starting again because there is no data from " + node);
    start();
   }
  }
 } catch (KeeperException e) {
  abortable.abort("Unexpected exception during initialization, aborting", e);
 }
}

代码示例来源:origin: apache/hbase

/**
 * Check if there is a master available.
 * @return true if there is a master set, false if not.
 */
public boolean hasMaster() {
 return super.getData(false) != null;
}

代码示例来源:origin: apache/hbase

/**
 * Set the balancer on/off.
 *
 * @param balancerOn true if the balancher should be on, false otherwise
 * @throws KeeperException if a ZooKeeper operation fails
 */
public void setBalancerOn(boolean balancerOn) throws KeeperException {
 byte [] upData = toByteArray(balancerOn);
 try {
  ZKUtil.setData(watcher, watcher.getZNodePaths().balancerZNode, upData);
 } catch(KeeperException.NoNodeException nne) {
  ZKUtil.createAndWatch(watcher, watcher.getZNodePaths().balancerZNode, upData);
 }
 super.nodeDataChanged(watcher.getZNodePaths().balancerZNode);
}

代码示例来源:origin: apache/hbase

/**
 * Utilty method to wait indefinitely on a znode availability while checking
 * if the region server is shut down
 * @param tracker znode tracker to use
 * @throws IOException any IO exception, plus if the RS is stopped
 * @throws InterruptedException
 */
private void blockAndCheckIfStopped(ZKNodeTracker tracker)
  throws IOException, InterruptedException {
 while (tracker.blockUntilAvailable(this.msgInterval, false) == null) {
  if (this.stopped) {
   throw new IOException("Received the shutdown message while waiting.");
  }
 }
}

代码示例来源:origin: apache/hbase

@Override
public synchronized void nodeDeleted(String path) {
 if(path.equals(node)) {
  try {
   if(ZKUtil.watchAndCheckExists(watcher, node)) {
    nodeCreated(path);
   } else {
    this.data = null;
   }
  } catch(KeeperException e) {
   abortable.abort("Unexpected exception handling nodeDeleted event", e);
  }
 }
}

代码示例来源:origin: apache/hbase

/**
 * Get the address of the current master if one is available.  Returns null
 * if no current master. If refresh is set, try to load the data from ZK again,
 * otherwise, cached data will be used.
 *
 * @param refresh whether to refresh the data by calling ZK directly.
 * @return Server name or null if timed out.
 */
public ServerName getMasterAddress(final boolean refresh) {
 try {
  return ProtobufUtil.parseServerNameFrom(super.getData(refresh));
 } catch (DeserializationException e) {
  LOG.warn("Failed parse", e);
  return null;
 }
}

代码示例来源:origin: org.apache.hbase/hbase-zookeeper

/**
 * Set region normalizer on/off
 * @param normalizerOn whether normalizer should be on or off
 * @throws KeeperException if a ZooKeeper operation fails
 */
public void setNormalizerOn(boolean normalizerOn) throws KeeperException {
 byte [] upData = toByteArray(normalizerOn);
 try {
  ZKUtil.setData(watcher, watcher.getZNodePaths().regionNormalizerZNode, upData);
 } catch(KeeperException.NoNodeException nne) {
  ZKUtil.createAndWatch(watcher, watcher.getZNodePaths().regionNormalizerZNode, upData);
 }
 super.nodeDataChanged(watcher.getZNodePaths().regionNormalizerZNode);
}

代码示例来源:origin: org.apache.hbase/hbase-zookeeper

/**
 * Gets the data of the node, blocking until the node is available.
 *
 * @return data of the node
 * @throws InterruptedException if the waiting thread is interrupted
 */
public synchronized byte [] blockUntilAvailable()
 throws InterruptedException {
 return blockUntilAvailable(0, false);
}

代码示例来源:origin: org.apache.hbase/hbase-zookeeper

@Override
public synchronized void nodeDataChanged(String path) {
 if(path.equals(node)) {
  nodeCreated(path);
 }
}

代码示例来源:origin: apache/hbase

/**
 * Return true if the balance switch is on, false otherwise
 */
public boolean isBalancerOn() {
 byte [] upData = super.getData(false);
 try {
  // if data in ZK is null, use default of on.
  return upData == null || parseFrom(upData).getBalancerOn();
 } catch (DeserializationException dex) {
  LOG.error("ZK state for LoadBalancer could not be parsed " + Bytes.toStringBinary(upData));
  // return false to be safe.
  return false;
 }
}

代码示例来源:origin: org.apache.hbase/hbase-zookeeper

/**
 * Set the balancer on/off.
 *
 * @param balancerOn true if the balancher should be on, false otherwise
 * @throws KeeperException if a ZooKeeper operation fails
 */
public void setBalancerOn(boolean balancerOn) throws KeeperException {
 byte [] upData = toByteArray(balancerOn);
 try {
  ZKUtil.setData(watcher, watcher.getZNodePaths().balancerZNode, upData);
 } catch(KeeperException.NoNodeException nne) {
  ZKUtil.createAndWatch(watcher, watcher.getZNodePaths().balancerZNode, upData);
 }
 super.nodeDataChanged(watcher.getZNodePaths().balancerZNode);
}

代码示例来源:origin: org.apache.hbase/hbase-zookeeper

@Override
public synchronized void nodeDeleted(String path) {
 if(path.equals(node)) {
  try {
   if(ZKUtil.watchAndCheckExists(watcher, node)) {
    nodeCreated(path);
   } else {
    this.data = null;
   }
  } catch(KeeperException e) {
   abortable.abort("Unexpected exception handling nodeDeleted event", e);
  }
 }
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com