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 */
018
019package org.apache.hadoop.mapreduce.counters;
020
021import org.apache.hadoop.classification.InterfaceAudience;
022import org.apache.hadoop.classification.InterfaceAudience.Private;
023import org.apache.hadoop.classification.InterfaceStability;
024import org.apache.hadoop.io.Writable;
025import org.apache.hadoop.mapreduce.Counter;
026
027/**
028 * The common counter group interface.
029 *
030 * @param <T> type of the counter for the group
031 */
032@InterfaceAudience.Public
033@InterfaceStability.Evolving
034public interface CounterGroupBase<T extends Counter>
035    extends Writable, Iterable<T> {
036
037  /**
038   * Get the internal name of the group
039   * @return the internal name
040   */
041  String getName();
042
043  /**
044   * Get the display name of the group.
045   * @return the human readable name
046   */
047  String getDisplayName();
048
049  /**
050   * Set the display name of the group
051   * @param displayName of the group
052   */
053  void setDisplayName(String displayName);
054
055  /** Add a counter to this group.
056   * @param counter to add
057   */
058  void addCounter(T counter);
059
060  /**
061   * Add a counter to this group
062   * @param name  of the counter
063   * @param displayName of the counter
064   * @param value of the counter
065   * @return the counter
066   */
067  T addCounter(String name, String displayName, long value);
068
069  /**
070   * Find a counter in the group.
071   * @param counterName the name of the counter
072   * @param displayName the display name of the counter
073   * @return the counter that was found or added
074   */
075  T findCounter(String counterName, String displayName);
076
077  /**
078   * Find a counter in the group
079   * @param counterName the name of the counter
080   * @param create create the counter if not found if true
081   * @return the counter that was found or added or null if create is false
082   */
083  T findCounter(String counterName, boolean create);
084
085  /**
086   * Find a counter in the group.
087   * @param counterName the name of the counter
088   * @return the counter that was found or added
089   */
090  T findCounter(String counterName);
091
092  /**
093   * @return the number of counters in this group.
094   */
095  int size();
096
097  /**
098   * Increment all counters by a group of counters
099   * @param rightGroup  the group to be added to this group
100   */
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   */
108  CounterGroupBase<T> getUnderlyingGroup();
109}