Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
package org.apache.hadoop.hbase.zookeeper;
Tracks the load balancer state up in ZK
public class LoadBalancerTracker extends ZooKeeperNodeTracker {
  private static final Log LOG = LogFactory.getLog(LoadBalancerTracker.class);
      Abortable abortable) {

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) {
      .error("ZK state for LoadBalancer could not be parsed " + Bytes.toStringBinary(upData));
      // return false to be safe.
      return false;

Set the balancer on/off

  public void setBalancerOn(boolean balancerOnthrows KeeperException {
  byte [] upData = toByteArray(balancerOn);
    try {
    } catch(KeeperException.NoNodeException nne) {
  private byte [] toByteArray(boolean isBalancerOn) {
    return ProtobufUtil.prependPBMagic(;
  private LoadBalancerProtos.LoadBalancerState parseFrom(byte [] pbBytes)
    try {
      int magicLen = ProtobufUtil.lengthOfPBMagic();
      builder.mergeFrom(pbBytesmagicLenpbBytes.length - magicLen);
    } catch (InvalidProtocolBufferException e) {
      throw new DeserializationException(e);
New to GrepCode? Check out our FAQ X