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 
19 package org.apache.hadoop.mapreduce.counters;
20 
21 import org.apache.hadoop.classification.InterfaceAudience;
22 import org.apache.hadoop.classification.InterfaceAudience.Private;
23 import org.apache.hadoop.classification.InterfaceStability;
24 import org.apache.hadoop.io.Writable;
25 import org.apache.hadoop.mapreduce.Counter;
26 
27 /**
28  * The common counter group interface.
29  *
30  * @param <T> type of the counter for the group
31  */
32 @InterfaceAudience.Public
33 @InterfaceStability.Evolving
34 public interface CounterGroupBase<T extends Counter>
35     extends Writable, Iterable<T> {
36 
37   /**
38    * Get the internal name of the group
39    * @return the internal name
40    */
getName()41   String getName();
42 
43   /**
44    * Get the display name of the group.
45    * @return the human readable name
46    */
getDisplayName()47   String getDisplayName();
48 
49   /**
50    * Set the display name of the group
51    * @param displayName of the group
52    */
setDisplayName(String displayName)53   void setDisplayName(String displayName);
54 
55   /** Add a counter to this group.
56    * @param counter to add
57    */
addCounter(T counter)58   void addCounter(T counter);
59 
60   /**
61    * Add a counter to this group
62    * @param name  of the counter
63    * @param displayName of the counter
64    * @param value of the counter
65    * @return the counter
66    */
addCounter(String name, String displayName, long value)67   T addCounter(String name, String displayName, long value);
68 
69   /**
70    * Find a counter in the group.
71    * @param counterName the name of the counter
72    * @param displayName the display name of the counter
73    * @return the counter that was found or added
74    */
findCounter(String counterName, String displayName)75   T findCounter(String counterName, String displayName);
76 
77   /**
78    * Find a counter in the group
79    * @param counterName the name of the counter
80    * @param create create the counter if not found if true
81    * @return the counter that was found or added or null if create is false
82    */
findCounter(String counterName, boolean create)83   T findCounter(String counterName, boolean create);
84 
85   /**
86    * Find a counter in the group.
87    * @param counterName the name of the counter
88    * @return the counter that was found or added
89    */
findCounter(String counterName)90   T findCounter(String counterName);
91 
92   /**
93    * @return the number of counters in this group.
94    */
size()95   int size();
96 
97   /**
98    * Increment all counters by a group of counters
99    * @param rightGroup  the group to be added to this group
100    */
incrAllCounters(CounterGroupBase<T> rightGroup)101   void incrAllCounters(CounterGroupBase<T> rightGroup);
102 
103   @Private
104   /**
105    * Exposes the underlying group type if a facade.
106    * @return the underlying object that this object is wrapping up.
107    */
getUnderlyingGroup()108   CounterGroupBase<T> getUnderlyingGroup();
109 }
110