com.bigdata.counters
Class AbstractCounterSet

java.lang.Object
  extended by com.bigdata.counters.AbstractCounterSet
All Implemented Interfaces:
ICounterNode, ICounterSet
Direct Known Subclasses:
CounterSet

public abstract class AbstractCounterSet
extends Object
implements ICounterSet

Version:
$Id: AbstractCounterSet.java 2265 2009-10-26 12:51:06Z thompsonbry $
Author:
Bryan Thompson

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.bigdata.counters.ICounterSet
ICounterSet.IInstrumentFactory
 
Field Summary
protected  String name
           
protected  AbstractCounterSet parent
           
 
Fields inherited from interface com.bigdata.counters.ICounterSet
pathSeparator
 
Constructor Summary
protected AbstractCounterSet(String name, CounterSet parent)
           
 
Method Summary
 void asXML(OutputStream os, String encoding, Pattern filter)
          Uses a post-order iteration to visit the CounterSets and for each CounterSet writes the current value of each Counter.
 String asXML(Pattern filter)
          Writes out the ICounterSet as XML on a string and returns that string.
 void asXML(Writer w, String encoding, Pattern filter)
          Alternative, but you are still required to specify the character set encoding in use by the writer.
 int getDepth()
          Depth of this node in the hierarchy, where the depth of the root is ZERO (0).
 String getName()
          The local name (does not include the path from the root).
 ICounterSet getParent()
          The immediate parent in the hierarchy -or- null iff this is the root of the hierarchy.
 String getPath()
          Complete path from the root inclusive of the local name.
 ICounterNode getPath(String path)
          Return the object described by the path.
 ICounterSet[] getPathComponents()
          The ordered array of counter sets from the root.
 AbstractCounterSet getRoot()
          The root of the hierarchy.
 boolean isCounter()
          true iff this is a counter.
 boolean isCounterSet()
          true iff this is a collection of counters.
 boolean isRoot()
          true iff this is the root of the hierarchy.
 String toString()
          A human readable representation of all counters in the hierarchy together with their current value.
 String toString(Pattern filter)
          A human readable representation of the counters in the hierarchy together with their current value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.bigdata.counters.ICounterSet
asXML, getCounters, makePath, readXML
 
Methods inherited from interface com.bigdata.counters.ICounterNode
getChild
 

Field Detail

name

protected final String name

parent

protected AbstractCounterSet parent
Constructor Detail

AbstractCounterSet

protected AbstractCounterSet(String name,
                             CounterSet parent)
Method Detail

getRoot

public AbstractCounterSet getRoot()
Description copied from interface: ICounterNode
The root of the hierarchy.

Specified by:
getRoot in interface ICounterNode

getName

public String getName()
Description copied from interface: ICounterNode
The local name (does not include the path from the root).

Specified by:
getName in interface ICounterNode

getPathComponents

public ICounterSet[] getPathComponents()
The ordered array of counter sets from the root.


getPath

public String getPath()
Description copied from interface: ICounterNode
Complete path from the root inclusive of the local name.

Specified by:
getPath in interface ICounterNode

getDepth

public int getDepth()
Description copied from interface: ICounterNode
Depth of this node in the hierarchy, where the depth of the root is ZERO (0).

Specified by:
getDepth in interface ICounterNode

getPath

public ICounterNode getPath(String path)
Description copied from interface: ICounterNode
Return the object described by the path.

Specified by:
getPath in interface ICounterNode
Parameters:
path - The path.
Returns:
The object or null if nothing exists for that path.

getParent

public ICounterSet getParent()
Description copied from interface: ICounterNode
The immediate parent in the hierarchy -or- null iff this is the root of the hierarchy.

Specified by:
getParent in interface ICounterNode

isRoot

public boolean isRoot()
Description copied from interface: ICounterNode
true iff this is the root of the hierarchy.

Specified by:
isRoot in interface ICounterNode

toString

public String toString()
Description copied from interface: ICounterSet
A human readable representation of all counters in the hierarchy together with their current value.

Specified by:
toString in interface ICounterSet
Overrides:
toString in class Object

toString

public String toString(Pattern filter)
Description copied from interface: ICounterSet
A human readable representation of the counters in the hierarchy together with their current value.

Specified by:
toString in interface ICounterSet
Parameters:
filter - An optional filter that will be used to select only specific counters.

isCounterSet

public final boolean isCounterSet()
Description copied from interface: ICounterNode
true iff this is a collection of counters.

Specified by:
isCounterSet in interface ICounterNode

isCounter

public final boolean isCounter()
Description copied from interface: ICounterNode
true iff this is a counter.

Specified by:
isCounter in interface ICounterNode

asXML

public void asXML(OutputStream os,
                  String encoding,
                  Pattern filter)
           throws IOException
Uses a post-order iteration to visit the CounterSets and for each CounterSet writes the current value of each Counter.

A sample output is below.

cs is a CounterSet element and has a path attribute which expresses the location of the counter set within the hierarchy (counter set elements are not nested inside of each other in the XML serialization). Only counter sets with counters are emitted.

c is a Counter element and is nested inside of the corresponding counter set. Each counter carries a name attribute, a simple XML Schema Datatype, a timestamp (milliseconds since the epoch per System.currentTimeMillis(), and has a counter value which is the inner content of the c element.

      <?xml version="1.0" encoding="UTF-8"?>
      <counters xmlns:xs="http://www.w3.org/2001/XMLSchema">
          <cs path="/www.bigdata.com/cpu">
              <c name="availableProcessors" type="xs:int" time="1205928108602">2</c>
          </cs>
          <cs path="/www.bigdata.com/memory">
              <c name="maxMemory" type="xs:long" time="1205928108602">517013504</c>
          </cs>
          <cs path="/">
              <c name="elapsed" type="xs:long" time="1205928108602">1205928108602</c>
          </cs>
           </counters>
 

Specified by:
asXML in interface ICounterSet
Parameters:
os - The sink on which the representation will be written.
encoding - The character set encoding that will be used, e.g., UTF-8.
filter - An optional filter that will be used to select only specific counters.
Throws:
IOException

asXML

public void asXML(Writer w,
                  String encoding,
                  Pattern filter)
           throws IOException
Alternative, but you are still required to specify the character set encoding in use by the writer.

Parameters:
w - The writer.
encoding - The character set encoding used by that writer.
filter - An optional filter.
Throws:
IOException

asXML

public String asXML(Pattern filter)
Description copied from interface: ICounterSet
Writes out the ICounterSet as XML on a string and returns that string.

Specified by:
asXML in interface ICounterSet
Parameters:
filter - An optional filter.


Copyright © 2006-2009 SYSTAP, LLC. All Rights Reserved.