org.apache.hadoop.mapreduce.counters
Class AbstractCounters<C extends Counter,G extends CounterGroupBase<C>>

java.lang.Object
  extended by 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>, org.apache.hadoop.io.Writable
Direct Known Subclasses:
Counters, Counters

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

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


Field Summary
protected static org.apache.commons.logging.Log LOG
           
 
Constructor Summary
AbstractCounters(AbstractCounters<C1,G1> counters, CounterGroupFactory<C,G> groupFactory)
          Construct from another counters object.
AbstractCounters(CounterGroupFactory<C,G> gf)
           
 
Method Summary
 G addGroup(G group)
          Add a group.
 G addGroup(String name, String displayName)
          Add a new group
 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 scheme, FileSystemCounter key)
          Find the file system counter for the given scheme and 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.
 boolean getWriteAllCounters()
          Get the "writeAllCounters" option
 int hashCode()
           
 void incrAllCounters(AbstractCounters<C,G> other)
          Increments multiple counters by their amounts in another Counters instance.
 Iterator<G> iterator()
           
 Limits limits()
           
 void readFields(DataInput in)
           
 void setWriteAllCounters(boolean send)
          Set the "writeAllCounters" option to true or false
 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
 

Field Detail

LOG

protected static final org.apache.commons.logging.Log LOG
Constructor Detail

AbstractCounters

@InterfaceAudience.Private
public AbstractCounters(CounterGroupFactory<C,G> gf)

AbstractCounters

@InterfaceAudience.Private
public AbstractCounters(AbstractCounters<C1,G1> 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

addGroup

@InterfaceAudience.Private
public G addGroup(G group)
Add a group.

Parameters:
group - object to add
Returns:
the group

addGroup

@InterfaceAudience.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

@InterfaceAudience.Private
public C findCounter(String scheme,
                                               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<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 org.apache.hadoop.io.Writable
Throws:
IOException

readFields

public void readFields(DataInput in)
                throws IOException
Specified by:
readFields in interface org.apache.hadoop.io.Writable
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

setWriteAllCounters

@InterfaceAudience.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

@InterfaceAudience.Private
public boolean getWriteAllCounters()
Get the "writeAllCounters" option

Returns:
true of all counters would serialized

limits

@InterfaceAudience.Private
public Limits limits()


Copyright © 2012 Apache Software Foundation. All Rights Reserved.