All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.hadoop.hbase.MasterAddressTracker Maven / Gradle / Ivy

Go to download

This OSGi bundle wraps hbase-common, hbase-client, hbase-prefix-tree, hbase-protocol, hbase-server, hbase-hadoop-compat ${pkgVersion} jar files.

There is a newer version: 2.4.4_1
Show newest version
/**
 * Copyright 2010 The Apache Software Foundation
 *
 * 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
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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;

import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.zookeeper.ZooKeeperNodeTracker;
import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;

/**
 * Manages the location of the current active Master for this RegionServer.
 * 

* Listens for ZooKeeper events related to the master address. The node * /master will contain the address of the current master. * This listener is interested in * NodeDeleted and NodeCreated events on * /master. *

* Utilizes {@link ZooKeeperNodeTracker} for zk interactions. *

* You can get the current master via {@link #getMasterAddress()} */ public class MasterAddressTracker extends ZooKeeperNodeTracker { /** * Construct a master address listener with the specified * zookeeper reference. *

* This constructor does not trigger any actions, you must call methods * explicitly. Normally you will just want to execute {@link #start()} to * begin tracking of the master address. * * @param watcher zk reference and watcher * @param abortable abortable in case of fatal error */ public MasterAddressTracker(ZooKeeperWatcher watcher, Abortable abortable) { super(watcher, watcher.masterAddressZNode, abortable); } /** * Get the address of the current master if one is available. Returns null * if no current master. * @return Server name or null if timed out. */ public ServerName getMasterAddress() { return bytesToServerName(super.getData(false)); } /** * 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; } /** * @param bytes Byte array of {@link ServerName#toString()} * @return A {@link ServerName} instance. */ private ServerName bytesToServerName(final byte [] bytes) { return bytes == null ? null: ServerName.parseVersionedServerName(bytes); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy