View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
3    * agreements. See the NOTICE file distributed with this work for additional information regarding
4    * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
5    * "License"); you may not use this file except in compliance with the License. You may obtain a
6    * copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable
7    * law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
8    * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
9    * for the specific language governing permissions and limitations under the License.
10   */
11  package org.apache.hadoop.hbase.quotas;
12  
13  import java.util.HashSet;
14  import java.util.Set;
15  
16  import org.apache.hadoop.hbase.classification.InterfaceAudience;
17  import org.apache.hadoop.hbase.classification.InterfaceStability;
18  import org.apache.hadoop.hbase.util.Strings;
19  
20  /**
21   * Filter to use to filter the QuotaRetriever results.
22   */
23  @InterfaceAudience.Public
24  @InterfaceStability.Evolving
25  public class QuotaFilter {
26    private Set<QuotaType> types = new HashSet<QuotaType>();
27    private boolean hasFilters = false;
28    private String namespaceRegex;
29    private String tableRegex;
30    private String userRegex;
31  
32    public QuotaFilter() {
33    }
34  
35    /**
36     * Set the user filter regex
37     * @param regex the user filter
38     * @return the quota filter object
39     */
40    public QuotaFilter setUserFilter(final String regex) {
41      this.userRegex = regex;
42      hasFilters |= !Strings.isEmpty(regex);
43      return this;
44    }
45  
46    /**
47     * Set the table filter regex
48     * @param regex the table filter
49     * @return the quota filter object
50     */
51    public QuotaFilter setTableFilter(final String regex) {
52      this.tableRegex = regex;
53      hasFilters |= !Strings.isEmpty(regex);
54      return this;
55    }
56  
57    /**
58     * Set the namespace filter regex
59     * @param regex the namespace filter
60     * @return the quota filter object
61     */
62    public QuotaFilter setNamespaceFilter(final String regex) {
63      this.namespaceRegex = regex;
64      hasFilters |= !Strings.isEmpty(regex);
65      return this;
66    }
67  
68    /**
69     * Add a type to the filter list
70     * @param type the type to filter on
71     * @return the quota filter object
72     */
73    public QuotaFilter addTypeFilter(final QuotaType type) {
74      this.types.add(type);
75      hasFilters |= true;
76      return this;
77    }
78  
79    /** @return true if the filter is empty */
80    public boolean isNull() {
81      return !hasFilters;
82    }
83  
84    /** @return the QuotaType types that we want to filter one */
85    public Set<QuotaType> getTypeFilters() {
86      return types;
87    }
88  
89    /** @return the Namespace filter regex */
90    public String getNamespaceFilter() {
91      return namespaceRegex;
92    }
93  
94    /** @return the Table filter regex */
95    public String getTableFilter() {
96      return tableRegex;
97    }
98  
99    /** @return the User filter regex */
100   public String getUserFilter() {
101     return userRegex;
102   }
103 }