org.apache.hadoop.hbase
Class MasterAddressTracker

java.lang.Object
  extended by org.apache.hadoop.hbase.zookeeper.ZooKeeperListener
      extended by org.apache.hadoop.hbase.zookeeper.ZooKeeperNodeTracker
          extended by org.apache.hadoop.hbase.MasterAddressTracker

public class MasterAddressTracker
extends ZooKeeperNodeTracker

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 ZooKeeperNodeTracker for zk interactions.

You can get the current master via getMasterAddress()


Field Summary
 
Fields inherited from class org.apache.hadoop.hbase.zookeeper.ZooKeeperNodeTracker
abortable, node
 
Fields inherited from class org.apache.hadoop.hbase.zookeeper.ZooKeeperListener
watcher
 
Constructor Summary
MasterAddressTracker(ZooKeeperWatcher watcher, Abortable abortable)
          Construct a master address listener with the specified zookeeper reference.
 
Method Summary
 HServerAddress getMasterAddress()
          Get the address of the current master if one is available.
 boolean hasMaster()
          Check if there is a master available.
 HServerAddress waitForMaster(long timeout)
          Get the address of the current master.
 
Methods inherited from class org.apache.hadoop.hbase.zookeeper.ZooKeeperNodeTracker
blockUntilAvailable, blockUntilAvailable, getData, getNode, nodeCreated, nodeDataChanged, nodeDeleted, start, stop
 
Methods inherited from class org.apache.hadoop.hbase.zookeeper.ZooKeeperListener
nodeChildrenChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MasterAddressTracker

public MasterAddressTracker(ZooKeeperWatcher watcher,
                            Abortable abortable)
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 ZooKeeperNodeTracker.start() to begin tracking of the master address.

Parameters:
watcher - zk reference and watcher
abortable - abortable in case of fatal error
Method Detail

getMasterAddress

public HServerAddress getMasterAddress()
Get the address of the current master if one is available. Returns null if no current master.

Returns:
server address of current active master, or null if none available

hasMaster

public boolean hasMaster()
Check if there is a master available.

Returns:
true if there is a master set, false if not.

waitForMaster

public HServerAddress waitForMaster(long timeout)
                             throws InterruptedException
Get the address of the current master. If no master is available, method will block until one is available, the thread is interrupted, or timeout has passed.

Parameters:
timeout - maximum time to wait for master in millis, 0 for forever
Returns:
server address of current active master, null if timed out
Throws:
InterruptedException - if the thread is interrupted while waiting


Copyright © 2011 The Apache Software Foundation. All Rights Reserved.