Package org.opendaylight.yangtools.util
Class RecursiveObjectLeaker
- java.lang.Object
-
- org.opendaylight.yangtools.util.RecursiveObjectLeaker
-
@Beta public final class RecursiveObjectLeaker extends Object
Thread-local hack to make recursive extensions work without too much hassle. The idea is that prior to instantiating an extension, the definition object checks whether it is already present on the stack, recorded object is returned.If it is not, it will push itself to the stack as unresolved and invoke the constructor. The constructor's lowermost class calls to this class and if the topmost entry is not resolved, it will leak itself.
Upon return from the constructor, the topmost entry is removed and if the queue is empty, the thread-local variable will be cleaned up.
WARNING: BE CAREFUL WHEN USING THIS CLASS. IT LEAKS OBJECTS WHICH ARE NOT COMPLETELY INITIALIZED.
WARNING: THIS CLASS LEAVES THREAD-LOCAL RESIDUE. MAKE SURE IT IS OKAY OR CALL
cleanup()
IN APPROPRIATE PLACES.THIS CLASS IS EXTREMELY DANGEROUS (okay, not as much as sun.misc.unsafe). YOU HAVE BEEN WARNED. IF SOMETHING BREAKS IT IS PROBABLY YOUR FAULT AND YOU ARE ON YOUR OWN.
- Author:
- Robert Varga
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
afterConstructor(Object key)
static void
beforeConstructor(Object key)
static void
cleanup()
static void
inConstructor(Object obj)
static <T> @Nullable T
lookup(Object key, Class<T> requiredClass)
-