View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.hbtop.mode;
19  
20  import edu.umd.cs.findbugs.annotations.Nullable;
21  import java.util.List;
22  import java.util.Objects;
23  
24  import org.apache.hadoop.hbase.ClusterStatus;
25  import org.apache.hadoop.hbase.classification.InterfaceAudience;
26  import org.apache.hadoop.hbase.hbtop.Record;
27  import org.apache.hadoop.hbase.hbtop.field.Field;
28  import org.apache.hadoop.hbase.hbtop.field.FieldInfo;
29  
30  /**
31   * Represents a display mode in the top screen.
32   */
33  @InterfaceAudience.Private
34  public enum Mode {
35    NAMESPACE("Namespace", "Record per Namespace", new NamespaceModeStrategy()),
36    TABLE("Table", "Record per Table", new TableModeStrategy()),
37    REGION("Region", "Record per Region", new RegionModeStrategy()),
38    REGION_SERVER("RegionServer", "Record per RegionServer", new RegionServerModeStrategy());
39  
40    private final String header;
41    private final String description;
42    private final ModeStrategy modeStrategy;
43  
44    Mode(String header, String description, ModeStrategy modeStrategy) {
45      this.header  = Objects.requireNonNull(header);
46      this.description = Objects.requireNonNull(description);
47      this.modeStrategy = Objects.requireNonNull(modeStrategy);
48    }
49  
50    public String getHeader() {
51      return header;
52    }
53  
54    public String getDescription() {
55      return description;
56    }
57  
58    public List<Record> getRecords(ClusterStatus clusterStatus) {
59      return modeStrategy.getRecords(clusterStatus);
60    }
61  
62    public List<FieldInfo> getFieldInfos() {
63      return modeStrategy.getFieldInfos();
64    }
65  
66    public Field getDefaultSortField() {
67      return modeStrategy.getDefaultSortField();
68    }
69  
70    @Nullable
71    public DrillDownInfo drillDown(Record currentRecord) {
72      return modeStrategy.drillDown(currentRecord);
73    }
74  }