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

@Public @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
    Description
    protected static final org.slf4j.Logger
     
  • Constructor Summary

    Constructors
    Constructor
    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

    Modifier and Type
    Method
    Description
    addGroup(G group)
    Add a group.
    addGroup(String name, String displayName)
    Add a new group
    int
    Returns the total number of counters, by summing the number of counters in each group.
    boolean
    equals(Object genericRight)
     
    findCounter(Enum<?> key)
    Find the counter for the given enum.
    findCounter(String groupName, String counterName)
    Find a counter, create one if necessary
    findCounter(String scheme, org.apache.hadoop.mapreduce.FileSystemCounter key)
    Find the file system counter for the given scheme and enum.
    getGroup(String groupName)
    Returns the named counter group, or an empty group if there is none with the specified name.
    Returns the names of all counter classes.
    boolean
    getWriteAllCounters()
    Get the "writeAllCounters" option
    int
     
    void
    Increments multiple counters by their amounts in another Counters instance.
     
    org.apache.hadoop.mapreduce.counters.Limits
    limits()
     
    void
    Deserialize the fields of this object from in.
    void
    setWriteAllCounters(boolean send)
    Set the "writeAllCounters" option to true or false
    Return textual representation of the counter values.
    void
    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 Details

    • LOG

      protected static final org.slf4j.Logger LOG
  • Constructor Details

    • AbstractCounters

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

      @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 Details

    • addGroup

      @Private public G addGroup(G group)
      Add a group.
      Parameters:
      group - object to add
      Returns:
      the group
    • addGroup

      @Private public G addGroup(String name, String displayName)
      Add a new group
      Parameters:
      name - of the group
      displayName - of the group
      Returns:
      the group
    • 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
    • findCounter

      @Private public C findCounter(String scheme, org.apache.hadoop.mapreduce.FileSystemCounter key)
      Find the file system counter for the given scheme and enum.
      Parameters:
      scheme - of the file system
      key - the enum of the counter
      Returns:
      the file system counter
    • 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<C extends Counter>
    • 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 - any other problem for write.
    • 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 - any other problem for readFields.
    • 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
    • setWriteAllCounters

      @Private public void setWriteAllCounters(boolean send)
      Set the "writeAllCounters" option to true or false
      Parameters:
      send - if true all counters would be serialized, otherwise only framework counters would be serialized in write(DataOutput)
    • getWriteAllCounters

      @Private public boolean getWriteAllCounters()
      Get the "writeAllCounters" option
      Returns:
      true of all counters would serialized
    • limits

      @Private public org.apache.hadoop.mapreduce.counters.Limits limits()