com.ibm.dtfj.analyzer.util
Class ObjectIterator

java.lang.Object
  extended by com.ibm.dtfj.analyzer.util.ObjectIterator

public abstract class ObjectIterator
extends java.lang.Object

Iterate over all the objects in a heap or runtime. During the iteration we ignore all corrupt objects and then apply a set of user definable filters to the remaining ones. A set of filters is provided in com.ibm.dtfj.analyzer.util.filter and may be extended by implementing a filter interface (See ObjectFilter). This iterator can be reset to conveniently allow multiple passes over a set of objects. For an object to be accepted by a set of filters it must be accepted by at least one of them and not rejected by any of them. To simplify the definition of these filter chains it is possible to change to starting 'state' of objects - accepted or rejected. By default this iterator starts with all objects in the rejected state and thus you must add at least one filter to see any objects. By changing the defaultAcceptState to true the iterator will accept all objects and a filter must be added if we want to reject any.


Field Summary
protected  IAnalyzerContext context
           
static int DEFAULT_LIMIT
          Define the maximum number of corrupt data objects we will handle from a given iterator.
 
Method Summary
 void addFilter(ObjectFilter filter)
          Add a filter which will decide if any given object is a part of the set to iterate.
static ObjectIterator build(com.ibm.dtfj.java.JavaHeap heap)
          Iterate over all the objects in a JavaHeap.
static ObjectIterator build(com.ibm.dtfj.java.JavaHeap heap, IAnalyzerContext ctx)
          Iterate over all the objects in a JavaHeap.
static ObjectIterator build(com.ibm.dtfj.java.JavaRuntime run)
          Iterate over all the objects in a JavaRuntime.
static ObjectIterator build(com.ibm.dtfj.java.JavaRuntime run, IAnalyzerContext ctx)
          Iterate over all the objects in a JavaRuntime.
 int getCorruptObjectCount()
          Count the total nummer of CorruptData objects that have been seen so far.
 boolean getDefaultAcceptState()
          Return the initial assumption on accepting objects.
protected abstract  com.ibm.dtfj.java.JavaHeap getHeap()
           
protected  boolean handleMoreCorruptObjects(java.lang.Object obj)
          A convenience method that can be overridden to change the handling of corrupt objects.
protected  boolean handleMoreNulls(java.lang.Object obj)
           
 boolean hasNext()
          Test the iterator to see if thera are any more objects to be returned to next().
protected abstract  boolean hasNextRaw()
           
 void iterateOverObjects(ObjectObserver observer)
          Iterate over all the objects in the current set and call the given observer for each of them.
 long length()
          Get the total nubmer of elements which will be iterated over.
 com.ibm.dtfj.java.JavaObject next()
          Get the next object from the iterator.
protected abstract  com.ibm.dtfj.java.JavaObject nextRaw()
           
 void removeAllFilters()
          Remove all the filters from this iterator.
 void removeFilter(ObjectFilter filter)
          Remove the given filter from the set of active filters.
 void reset()
          Reset the iterator so that we scan the objects from the start.
 void setDefaultAcceptState(boolean accept)
          Define the initial assumption on accepting objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_LIMIT

public static final int DEFAULT_LIMIT
Define the maximum number of corrupt data objects we will handle from a given iterator.

See Also:
Constant Field Values

context

protected IAnalyzerContext context
Method Detail

build

public static ObjectIterator build(com.ibm.dtfj.java.JavaRuntime run)
Iterate over all the objects in a JavaRuntime. By default the iterator will reject all objects (See setDefaultAcceptState(boolean)).

Parameters:
run - the runtime to operate with - iterate over all objects
Returns:
an iterator over all the objects

build

public static ObjectIterator build(com.ibm.dtfj.java.JavaRuntime run,
                                   IAnalyzerContext ctx)
Iterate over all the objects in a JavaRuntime. By default the iterator will reject all objects (See setDefaultAcceptState(boolean)).

Parameters:
run - the runtime to operate with - iterate over all objects
ctx - context for reporting errors
Returns:
an iterator over all the objects

build

public static ObjectIterator build(com.ibm.dtfj.java.JavaHeap heap)
Iterate over all the objects in a JavaHeap. By default the iterator will reject all objects (See setDefaultAcceptState(boolean)).

Parameters:
heap - the heap operate with - iterate over all objects
Returns:
an iterator over all the objects

build

public static ObjectIterator build(com.ibm.dtfj.java.JavaHeap heap,
                                   IAnalyzerContext ctx)
Iterate over all the objects in a JavaHeap. By default the iterator will reject all objects (See setDefaultAcceptState(boolean)).

Parameters:
heap - the heap operate with - iterate over all objects
ctx - context for reporting errors
Returns:
an iterator over all the objects

setDefaultAcceptState

public void setDefaultAcceptState(boolean accept)
Define the initial assumption on accepting objects. If true then all objects will be accepted unless a filter rejects them. If false then all objects will be rejected until a filter accepts them.

Parameters:
accept - true to accept objects, false to reject them.

getDefaultAcceptState

public boolean getDefaultAcceptState()
Return the initial assumption on accepting objects.

Returns:
true if the default is to accept objects

hasNext

public boolean hasNext()
Test the iterator to see if thera are any more objects to be returned to next().

Returns:
true if there are more objects

next

public com.ibm.dtfj.java.JavaObject next()
Get the next object from the iterator.

Returns:
the next object

length

public long length()
Get the total nubmer of elements which will be iterated over. Note that this operation will reset the iterator.

Returns:
total number of items to be iterated over

addFilter

public void addFilter(ObjectFilter filter)
Add a filter which will decide if any given object is a part of the set to iterate. If multiple filters are added then at least one of them must accept the object and none must reject it for it to be a part of the set. Note that adding a filter does NOT reset the iterator - the filter applies to all subsequent objects. It does however make the count no longer valid.

Parameters:
filter - the filter to add - which must not be null

removeFilter

public void removeFilter(ObjectFilter filter)
Remove the given filter from the set of active filters. Note that removing a filter does NOT reset the iterator - the filter applies to all subsequent objects. It does however make the count no longer valid.

Parameters:
filter - the filter to remove - which must have been previously added

removeAllFilters

public void removeAllFilters()
Remove all the filters from this iterator. It will iterate over all elements in the set. Note that removing filters does NOT reset the iterator - the filter applies to all subsequent objects. It does however make the count no longer valid.


getCorruptObjectCount

public int getCorruptObjectCount()
Count the total nummer of CorruptData objects that have been seen so far.

Returns:
total CorruptData objects.

iterateOverObjects

public void iterateOverObjects(ObjectObserver observer)
Iterate over all the objects in the current set and call the given observer for each of them. This is an alternative to manually invoking hasNext and next and may be more convenient for some applications.

Parameters:
observer - the observer that will be invoked on each object.

reset

public final void reset()
Reset the iterator so that we scan the objects from the start.


handleMoreCorruptObjects

protected boolean handleMoreCorruptObjects(java.lang.Object obj)
A convenience method that can be overridden to change the handling of corrupt objects.

Parameters:
obj - the corrupt object to handle
Returns:
true if we should continue iterating or false to terminate

handleMoreNulls

protected boolean handleMoreNulls(java.lang.Object obj)

getHeap

protected abstract com.ibm.dtfj.java.JavaHeap getHeap()

hasNextRaw

protected abstract boolean hasNextRaw()

nextRaw

protected abstract com.ibm.dtfj.java.JavaObject nextRaw()


© Copyright IBM Corp. 2007, 2008 All Rights Reserved. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.