Top Description Inners Fields Constructors Methods
net.sf.ehcache.pool.sizeof

pack-priv final Class ObjectGraphWalker

extends Object
Class Inheritance
Imports
java.lang.ref.SoftReference, java.lang.reflect.Array, .Field, .Modifier, java.text.MessageFormat, java.util.ArrayList, .Collection, .IdentityHashMap, .Stack, net.sf.ehcache.pool.sizeof.filter.SizeOfFilter, net.sf.ehcache.util.WeakIdentityConcurrentMap, org.slf4j.Logger, .LoggerFactory

This will walk an object graph and let you execute some "function" along the way
Author
Alex Snaps

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv 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

Modifier and TypeField and Description
private static final String
private final WeakIdentityConcurrentMap<Class<?>, Boolean>
private static final String
private final WeakIdentityConcurrentMap<Class<?>, SoftReference<Collection<Field>>>
private static final Logger
private final SizeOfFilter
private static final String
private static final boolean
private static final String
private final ObjectGraphWalker.Visitor

Constructor Summary

AccessConstructor and Description
pack-priv
ObjectGraphWalker(ObjectGraphWalker.Visitor
the visitor to use
visitor
,
SizeOfFilter
the filtering
filter
)

Constructor

Method Summary

Modifier and TypeMethod and Description
private long
private boolean
checkMaxDepth(final int maxDepth, final boolean abortWhenMaxDepthExceeded, boolean warned, final IdentityHashMap<Object, Object> visited)

private static Collection<Field>

Returns:

all fields for that type
getAllFields
(Class<?>
the type
refClass
)

Returns all non-primitive fields for the entire class hierarchy of a type

private Collection<Field>

Returns:

A collection of fields to be visited
getFilteredFields
(Class<?>
the type
refClass
)

Returns the filtered fields for a particular type

private static boolean
private static boolean
private static void
nullSafeAdd(final Stack<Object> toVisit, final Object o)

private boolean
shouldWalkClass(Class<?> refClass)

pack-priv long

Returns:

the sum of all Visitor#visit returned values
walk
(int
maximum depth to traverse the object graph
maxDepth
,
boolean
true if the object traversal should be aborted when the max depth is exceeded
abortWhenMaxDepthExceeded
,
Object...
the roots of the objects (a shared graph will only be visited once)
root
)

Walk the graph and call into the "visitor"

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ABORT_MESSAGEback to summary
private static final String ABORT_MESSAGE
classCacheback to summary
private final WeakIdentityConcurrentMap<Class<?>, Boolean> classCache
CONTINUE_MESSAGEback to summary
private static final String CONTINUE_MESSAGE
fieldCacheback to summary
private final WeakIdentityConcurrentMap<Class<?>, SoftReference<Collection<Field>>> fieldCache
LOGback to summary
private static final Logger LOG
sizeOfFilterback to summary
private final SizeOfFilter sizeOfFilter
TC_INTERNAL_FIELD_PREFIXback to summary
private static final String TC_INTERNAL_FIELD_PREFIX
USE_VERBOSE_DEBUG_LOGGINGback to summary
private static final boolean USE_VERBOSE_DEBUG_LOGGING
VERBOSE_DEBUG_LOGGINGback to summary
private static final String VERBOSE_DEBUG_LOGGING
visitorback to summary
private final ObjectGraphWalker.Visitor visitor

Constructor Detail

ObjectGraphWalkerback to summary
pack-priv ObjectGraphWalker(ObjectGraphWalker.Visitor visitor, SizeOfFilter filter)

Constructor

Parameters
visitor:ObjectGraphWalker.Visitor

the visitor to use

filter:SizeOfFilter

the filtering

See Also
Visitor, SizeOfFilter

Method Detail

calculateSizeback to summary
private long calculateSize(Object ref)
checkMaxDepthback to summary
private boolean checkMaxDepth(final int maxDepth, final boolean abortWhenMaxDepthExceeded, boolean warned, final IdentityHashMap<Object, Object> visited)
getAllFieldsback to summary
private static Collection<Field> getAllFields(Class<?> refClass)

Returns all non-primitive fields for the entire class hierarchy of a type

Parameters
refClass:Class<?>

the type

Returns:Collection<Field>

all fields for that type

getFilteredFieldsback to summary
private Collection<Field> getFilteredFields(Class<?> refClass)

Returns the filtered fields for a particular type

Parameters
refClass:Class<?>

the type

Returns:Collection<Field>

A collection of fields to be visited

getVerboseSizeOfDebugLoggingback to summary
private static boolean getVerboseSizeOfDebugLogging()
isSharedFlyweightback to summary
private static boolean isSharedFlyweight(Object obj)
nullSafeAddback to summary
private static void nullSafeAdd(final Stack<Object> toVisit, final Object o)
shouldWalkClassback to summary
private boolean shouldWalkClass(Class<?> refClass)
walkback to summary
pack-priv long walk(int maxDepth, boolean abortWhenMaxDepthExceeded, Object... root)

Walk the graph and call into the "visitor"

Parameters
maxDepth:int

maximum depth to traverse the object graph

abortWhenMaxDepthExceeded:boolean

true if the object traversal should be aborted when the max depth is exceeded

root:Object[]

the roots of the objects (a shared graph will only be visited once)

Returns:long

the sum of all Visitor#visit returned values

net.sf.ehcache.pool.sizeof back to summary

pack-priv Interface ObjectGraphWalker.Visitor

Known Direct Implementers
net.sf.ehcache.pool.sizeof.SizeOf.SizeOfVisitor, net.sf.ehcache.pool.sizeof.SizeOf.CachingSizeOfVisitor

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!

Method Summary

Modifier and TypeMethod and Description
public long

Returns:

a long for you to do things with...
visit
(Object
the reference at that node
object
)

The visit method executed on each node

Method Detail

visitback to summary
public long visit(Object object)

The visit method executed on each node

Parameters
object:Object

the reference at that node

Returns:long

a long for you to do things with...