Class Counters

All Implemented Interfaces:
Iterable<Counters.Group>, Writable

@Public @Stable public class Counters extends AbstractCounters<Counters.Counter,Counters.Group>
A set of named counters.

Counters represent global counters, defined either by the Map-Reduce framework or applications. Each Counter can be of any Enum type.

Counters are bunched into Counters.Groups, each comprising of counters from a particular Enum class.

  • Field Details

    • MAX_COUNTER_LIMIT

      public static final int MAX_COUNTER_LIMIT
    • MAX_GROUP_LIMIT

      public static final int MAX_GROUP_LIMIT
  • Constructor Details

    • Counters

      public Counters()
    • Counters

      public Counters(Counters newCounters)
  • Method Details

    • getGroup

      public Counters.Group getGroup(String groupName)
      Description copied from class: AbstractCounters
      Returns the named counter group, or an empty group if there is none with the specified name.
      Overrides:
      getGroup in class AbstractCounters<Counters.Counter,Counters.Group>
      Parameters:
      groupName - name of the group
      Returns:
      the group
    • getGroupNames

      public Collection<String> getGroupNames()
      Description copied from class: AbstractCounters
      Returns the names of all counter classes.
      Overrides:
      getGroupNames in class AbstractCounters<Counters.Counter,Counters.Group>
      Returns:
      Set of counter names.
    • makeCompactString

      public String makeCompactString()
    • findCounter

      public Counters.Counter findCounter(String group, String name)
      Description copied from class: AbstractCounters
      Find a counter, create one if necessary
      Overrides:
      findCounter in class AbstractCounters<Counters.Counter,Counters.Group>
      Parameters:
      group - of the counter
      name - name of the counter
      Returns:
      the matching counter
    • findCounter

      @Deprecated public Counters.Counter findCounter(String group, int id, String name)
      Deprecated.
      Find a counter by using strings
      Parameters:
      group - the name of the group
      id - the id of the counter within the group (0 to N-1)
      name - the internal name of the counter
      Returns:
      the counter for that name
    • incrCounter

      public void incrCounter(Enum<?> key, long amount)
      Increments the specified counter by the specified amount, creating it if it didn't already exist.
      Parameters:
      key - identifies a counter
      amount - amount by which counter is to be incremented
    • incrCounter

      public void incrCounter(String group, String counter, long amount)
      Increments the specified counter by the specified amount, creating it if it didn't already exist.
      Parameters:
      group - the name of the group
      counter - the internal name of the counter
      amount - amount by which counter is to be incremented
    • getCounter

      public long getCounter(Enum<?> key)
      Returns current value of the specified counter, or 0 if the counter does not exist.
      Parameters:
      key - the counter enum to lookup
      Returns:
      the counter value or 0 if counter not found
    • incrAllCounters

      public void incrAllCounters(Counters other)
      Increments multiple counters by their amounts in another Counters instance.
      Parameters:
      other - the other Counters instance
    • size

      public int size()
      Deprecated.
      Returns:
      the total number of counters
    • sum

      public static Counters sum(Counters a, Counters b)
      Convenience method for computing the sum of two sets of counters.
      Parameters:
      a - the first counters
      b - the second counters
      Returns:
      a new summed counters object
    • log

      public void log(org.slf4j.Logger log)
      Logs the current counter values.
      Parameters:
      log - The log to use.
    • makeEscapedCompactString

      public String makeEscapedCompactString()
      Represent the counter in a textual format that can be converted back to its object form
      Returns:
      the string in the following format {(groupName)(group-displayName)[(counterName)(displayName)(value)][]*}*
    • fromEscapedCompactString

      public static Counters fromEscapedCompactString(String compactString) throws ParseException
      Convert a stringified (by makeEscapedCompactString() counter representation into a counter object.
      Parameters:
      compactString - to parse
      Returns:
      a new counters object
      Throws:
      ParseException