Package org.ehcache.sizeof
Class ObjectGraphWalker
- java.lang.Object
-
- org.ehcache.sizeof.ObjectGraphWalker
-
final class ObjectGraphWalker extends java.lang.ObjectThis will walk an object graph and let you execute some "function" along the way
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static interfaceObjectGraphWalker.VisitorThe visitor to execute the function on each node of the graph This is only to be used for the sizing of an object graph in memory!
-
Field Summary
Fields Modifier and Type Field Description private booleanbypassFlyweightprivate WeakIdentityConcurrentMap<java.lang.Class<?>,java.lang.Boolean>classCacheprivate WeakIdentityConcurrentMap<java.lang.Class<?>,java.lang.ref.SoftReference<java.util.Collection<java.lang.reflect.Field>>>fieldCacheprivate static org.slf4j.LoggerLOGprivate SizeOfFiltersizeOfFilterprivate static booleanUSE_VERBOSE_DEBUG_LOGGINGprivate static java.lang.StringVERBOSE_DEBUG_LOGGINGprivate ObjectGraphWalker.Visitorvisitor
-
Constructor Summary
Constructors Constructor Description ObjectGraphWalker(ObjectGraphWalker.Visitor visitor, SizeOfFilter filter, boolean bypassFlyweight)Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private booleanbyPassIfFlyweight(java.lang.Object obj)private static java.util.Collection<java.lang.reflect.Field>getAllFields(java.lang.Class<?> refClass)Returns all non-primitive fields for the entire class hierarchy of a typeprivate java.util.Collection<java.lang.reflect.Field>getFilteredFields(java.lang.Class<?> refClass)Returns the filtered fields for a particular typeprivate static booleangetVerboseSizeOfDebugLogging()private static voidnullSafeAdd(java.util.Deque<java.lang.Object> toVisit, java.lang.Object o)private booleanshouldWalkClass(java.lang.Class<?> refClass)(package private) longwalk(java.lang.Object... root)Walk the graph and call into the "visitor"(package private) longwalk(VisitorListener visitorListener, java.lang.Object... root)Walk the graph and call into the "visitor"
-
-
-
Field Detail
-
LOG
private static final org.slf4j.Logger LOG
-
VERBOSE_DEBUG_LOGGING
private static final java.lang.String VERBOSE_DEBUG_LOGGING
- See Also:
- Constant Field Values
-
USE_VERBOSE_DEBUG_LOGGING
private static final boolean USE_VERBOSE_DEBUG_LOGGING
-
fieldCache
private final WeakIdentityConcurrentMap<java.lang.Class<?>,java.lang.ref.SoftReference<java.util.Collection<java.lang.reflect.Field>>> fieldCache
-
classCache
private final WeakIdentityConcurrentMap<java.lang.Class<?>,java.lang.Boolean> classCache
-
bypassFlyweight
private final boolean bypassFlyweight
-
sizeOfFilter
private final SizeOfFilter sizeOfFilter
-
visitor
private final ObjectGraphWalker.Visitor visitor
-
-
Constructor Detail
-
ObjectGraphWalker
ObjectGraphWalker(ObjectGraphWalker.Visitor visitor, SizeOfFilter filter, boolean bypassFlyweight)
Constructor- Parameters:
visitor- the visitor to usefilter- the filteringbypassFlyweight- the filtering- See Also:
ObjectGraphWalker.Visitor,SizeOfFilter
-
-
Method Detail
-
getVerboseSizeOfDebugLogging
private static boolean getVerboseSizeOfDebugLogging()
-
walk
long walk(java.lang.Object... root)
Walk the graph and call into the "visitor"- Parameters:
root- the roots of the objects (a shared graph will only be visited once)- Returns:
- the sum of all Visitor#visit returned values
-
walk
long walk(VisitorListener visitorListener, java.lang.Object... root)
Walk the graph and call into the "visitor"- Parameters:
visitorListener- A decorator for the Visitorroot- the roots of the objects (a shared graph will only be visited once)- Returns:
- the sum of all Visitor#visit returned values
-
getFilteredFields
private java.util.Collection<java.lang.reflect.Field> getFilteredFields(java.lang.Class<?> refClass)
Returns the filtered fields for a particular type- Parameters:
refClass- the type- Returns:
- A collection of fields to be visited
-
shouldWalkClass
private boolean shouldWalkClass(java.lang.Class<?> refClass)
-
nullSafeAdd
private static void nullSafeAdd(java.util.Deque<java.lang.Object> toVisit, java.lang.Object o)
-
getAllFields
private static java.util.Collection<java.lang.reflect.Field> getAllFields(java.lang.Class<?> refClass)
Returns all non-primitive fields for the entire class hierarchy of a type- Parameters:
refClass- the type- Returns:
- all fields for that type
-
byPassIfFlyweight
private boolean byPassIfFlyweight(java.lang.Object obj)
-
-