Package org.ehcache.sizeof
Class ObjectGraphWalker
- java.lang.Object
-
- org.ehcache.sizeof.ObjectGraphWalker
-
final class ObjectGraphWalker extends java.lang.Object
This 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 interface
ObjectGraphWalker.Visitor
The 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 boolean
bypassFlyweight
private WeakIdentityConcurrentMap<java.lang.Class<?>,java.lang.Boolean>
classCache
private WeakIdentityConcurrentMap<java.lang.Class<?>,java.lang.ref.SoftReference<java.util.Collection<java.lang.reflect.Field>>>
fieldCache
private static org.slf4j.Logger
LOG
private SizeOfFilter
sizeOfFilter
private static boolean
USE_VERBOSE_DEBUG_LOGGING
private static java.lang.String
VERBOSE_DEBUG_LOGGING
private ObjectGraphWalker.Visitor
visitor
-
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 boolean
byPassIfFlyweight(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 boolean
getVerboseSizeOfDebugLogging()
private static void
nullSafeAdd(java.util.Deque<java.lang.Object> toVisit, java.lang.Object o)
private boolean
shouldWalkClass(java.lang.Class<?> refClass)
(package private) long
walk(java.lang.Object... root)
Walk the graph and call into the "visitor"(package private) long
walk(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)
-
-