001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.hbtop.mode;
019
020import edu.umd.cs.findbugs.annotations.Nullable;
021import java.util.List;
022import java.util.Objects;
023import org.apache.hadoop.hbase.ClusterMetrics;
024import org.apache.hadoop.hbase.hbtop.Record;
025import org.apache.hadoop.hbase.hbtop.RecordFilter;
026import org.apache.hadoop.hbase.hbtop.field.Field;
027import org.apache.hadoop.hbase.hbtop.field.FieldInfo;
028import org.apache.yetus.audience.InterfaceAudience;
029
030
031/**
032 * Represents a display mode in the top screen.
033 */
034@InterfaceAudience.Private
035public enum Mode {
036  NAMESPACE("Namespace", "Record per Namespace", new NamespaceModeStrategy()),
037  TABLE("Table", "Record per Table", new TableModeStrategy()),
038  REGION("Region", "Record per Region", new RegionModeStrategy()),
039  REGION_SERVER("RegionServer", "Record per RegionServer", new RegionServerModeStrategy()),
040  USER("User", "Record per user", new UserModeStrategy()),
041  CLIENT("Client", "Record per client", new ClientModeStrategy());
042
043  private final String header;
044  private final String description;
045  private final ModeStrategy modeStrategy;
046
047  Mode(String header, String description, ModeStrategy modeStrategy) {
048    this.header  = Objects.requireNonNull(header);
049    this.description = Objects.requireNonNull(description);
050    this.modeStrategy = Objects.requireNonNull(modeStrategy);
051  }
052
053  public String getHeader() {
054    return header;
055  }
056
057  public String getDescription() {
058    return description;
059  }
060
061  public List<Record> getRecords(ClusterMetrics clusterMetrics,
062      List<RecordFilter> pushDownFilters) {
063    return modeStrategy.getRecords(clusterMetrics, pushDownFilters);
064  }
065
066  public List<FieldInfo> getFieldInfos() {
067    return modeStrategy.getFieldInfos();
068  }
069
070  public Field getDefaultSortField() {
071    return modeStrategy.getDefaultSortField();
072  }
073
074  @Nullable
075  public DrillDownInfo drillDown(Record currentRecord) {
076    return modeStrategy.drillDown(currentRecord);
077  }
078}