org.apache.hadoop.mapreduce.counters

## Class AbstractCounters<C extends Counter,G extends CounterGroupBase<C>>

- java.lang.Object
- - org.apache.hadoop.mapreduce.counters.AbstractCounters<C,G>

- Type Parameters:
    `C` - type of counter inside the counters
    `G` - type of group inside the counters
  All Implemented Interfaces:
    Iterable<G>, Writable
  Direct Known Subclasses:
    Counters, Counters

      @InterfaceAudience.Public
       @InterfaceStability.Stable
      public abstract class AbstractCounters<C extends Counter,G extends CounterGroupBase<C>>
      extends Object
      implements Writable, Iterable<G>

  An abstract class to provide common implementation for the Counters container in both mapred and mapreduce packages.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static org.slf4j.Logger` | `LOG`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractCounters(AbstractCounters<C1,G1> counters, org.apache.hadoop.mapreduce.counters.CounterGroupFactory<C,G> groupFactory)` Construct from another counters object.
    `AbstractCounters(org.apache.hadoop.mapreduce.counters.CounterGroupFactory<C,G> gf)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `countCounters()` Returns the total number of counters, by summing the number of counters in each group.
    `boolean` | `equals(Object genericRight)`
    `C` | `findCounter(Enum<?> key)` Find the counter for the given enum.
    `C` | `findCounter(String groupName, String counterName)` Find a counter, create one if necessary
    `G` | `getGroup(String groupName)` Returns the named counter group, or an empty group if there is none with the specified name.
    `Iterable<String>` | `getGroupNames()` Returns the names of all counter classes.
    `int` | `hashCode()`
    `void` | `incrAllCounters(AbstractCounters<C,G> other)` Increments multiple counters by their amounts in another Counters instance.
    `Iterator<G>` | `iterator()`
    `void` | `readFields(DataInput in)` Deserialize the fields of this object from `in`.
    `String` | `toString()` Return textual representation of the counter values.
    `void` | `write(DataOutput out)` Write the set of groups.

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface java.lang.Iterable

      `forEach, spliterator`

- - ### Field Detail

    - #### LOG

          protected static final org.slf4j.Logger LOG

  - ### Constructor Detail

    - #### AbstractCounters

          @InterfaceAudience.Private
          public AbstractCounters(org.apache.hadoop.mapreduce.counters.CounterGroupFactory<C,G> gf)

    - #### AbstractCounters

          @InterfaceAudience.Private
          public AbstractCounters(AbstractCounters<C1,G1> counters,
                                                             org.apache.hadoop.mapreduce.counters.CounterGroupFactory<C,G> groupFactory)

      Construct from another counters object.
      Type Parameters:
        `C1` - type of the other counter
        `G1` - type of the other counter group
      Parameters:
        `counters` - the counters object to copy
        `groupFactory` - the factory for new groups

  - ### Method Detail

    - #### findCounter

          public C findCounter(String groupName,
                               String counterName)

      Find a counter, create one if necessary
      Parameters:
        `groupName` - of the counter
        `counterName` - name of the counter
      Returns:
        the matching counter

    - #### findCounter

          public C findCounter(Enum<?> key)

      Find the counter for the given enum. The same enum will always return the same counter.
      Parameters:
        `key` - the counter key
      Returns:
        the matching counter object

    - #### getGroupNames

          public Iterable<String> getGroupNames()

      Returns the names of all counter classes.
      Returns:
        Set of counter names.

    - #### iterator

          public Iterator<G> iterator()

      Specified by:
        `iterator` in interface `Iterable<G extends CounterGroupBase<C>>`

    - #### getGroup

          public G getGroup(String groupName)

      Returns the named counter group, or an empty group if there is none with the specified name.
      Parameters:
        `groupName` - name of the group
      Returns:
        the group

    - #### countCounters

          public int countCounters()

      Returns the total number of counters, by summing the number of counters in each group.
      Returns:
        the total number of counters

    - #### write

          public void write(DataOutput out)
                     throws IOException

      Write the set of groups. Counters ::= version #fgroups (groupId, group)* #groups (group)*
      Specified by:
        `write` in interface `Writable`
      Parameters:
        `out` - `DataOuput` to serialize this object into.
      Throws:
        `IOException`

    - #### readFields

          public void readFields(DataInput in)
                          throws IOException

      Description copied from interface: `Writable`
      Deserialize the fields of this object from `in`.

      For efficiency, implementations should attempt to re-use storage in the existing object where possible.

      Specified by:
        `readFields` in interface `Writable`
      Parameters:
        `in` - `DataInput` to deseriablize this object from.
      Throws:
        `IOException`

    - #### toString

          public String toString()

      Return textual representation of the counter values.
      Overrides:
        `toString` in class `Object`
      Returns:
        the string

    - #### incrAllCounters

          public void incrAllCounters(AbstractCounters<C,G> other)

      Increments multiple counters by their amounts in another Counters instance.
      Parameters:
        `other` - the other Counters instance

    - #### equals

          public boolean equals(Object genericRight)

      Overrides:
        `equals` in class `Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

Copyright © 2022 Apache Software Foundation. All rights reserved.