@Override
  public PairOfSameType<Integer> getRegionCounts() {
    try {
      if (!master.isInitialized()) {
        return new PairOfSameType<>(0, 0);
      }
      Integer onlineRegionCount = 0;
      Integer offlineRegionCount = 0;

      List<TableDescriptor> descriptors = master.listTableDescriptors(null, null, null, false);

      for (TableDescriptor htDesc : descriptors) {
        TableName tableName = htDesc.getTableName();
        Map<RegionState.State, List<RegionInfo>> tableRegions =
          master.getAssignmentManager().getRegionStates().getRegionByStateOfTable(tableName);
        onlineRegionCount += tableRegions.get(RegionState.State.OPEN).size();
        offlineRegionCount += tableRegions.get(RegionState.State.OFFLINE).size();
      }
      return new PairOfSameType<>(onlineRegionCount, offlineRegionCount);
    } catch (IOException e) {
      return new PairOfSameType<>(0, 0);
    }
  }
Impl for exposing HMaster Information through JMX
hbase-server/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterWrapperImpl.java