Class BindingClassLoader
java.lang.Object
java.lang.ClassLoader
org.opendaylight.yangtools.binding.loader.BindingClassLoader
A
ClassLoader
hosting types generated for a particular type. A root instance is attached to a particular user
a root class loader and should be used to load classes, which are used by a particular user instance. When used
correctly, the classes loaded through this instance become eligible for GC when the user instance becomes
unreachable.
It semantically combines two class loaders: the class loader in which this class is loaded and the class loader in which a target Binding interface/class is loaded. This inherently supports multi-classloader environments -- the root instance has visibility only into codec classes and for each classloader we encounter when presented with a binding class we create a leaf instance and cache it in the root instance. Leaf instances are using the root loader as their parent, but consult the binding class's class loader if the root loader fails to load a particular class.
In single-classloader environments, obviously, the root loader can load all binding classes, and hence no leaf loader is created.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
A builder ofBindingClassLoader
instances.static interface
A class generator, generating a class of a particular type.static final class
Result of class generation. -
Method Summary
Modifier and TypeMethodDescriptionstatic @NonNull BindingClassLoader.Builder
static @NonNull BindingClassLoader
Deprecated.final boolean
final <T> @NonNull Class
<T> generateClass
(Class<?> bindingInterface, String fqcn, BindingClassLoader.ClassGenerator<T> generator) Generate a class which is related to specified compile-type-generated interface.final @NonNull Class
<?> getGeneratedClass
(Class<?> bindingInterface, String fqcn) final int
hashCode()
static @NonNull BindingClassLoader
ofRootClass
(Class<?> rootClass) Instantiate a new BindingClassLoader, which serves as the root of generated code loading.final String
toString()
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findClass, findLibrary, findLoadedClass, findResource, findResource, findResources, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
Method Details
-
create
@Deprecated(since="14.0.7") public static @NonNull BindingClassLoader create(Class<?> rootClass, @Nullable File dumpDir) Deprecated.Usebuilder(Class)
insteadInstantiate a new BindingClassLoader, which serves as the root of generated code loading.- Parameters:
rootClass
- Class from which to derive the class loaderdumpDir
- Directory in which to dump loaded bytecode- Returns:
- A new BindingClassLoader.
- Throws:
NullPointerException
- ifparentLoader
isnull
-
builder
-
ofRootClass
Instantiate a new BindingClassLoader, which serves as the root of generated code loading.- Parameters:
rootClass
- Class from which to derive the class loader- Returns:
- A new BindingClassLoader.
- Throws:
NullPointerException
- ifparentLoader
isnull
-
generateClass
public final <T> @NonNull Class<T> generateClass(Class<?> bindingInterface, String fqcn, BindingClassLoader.ClassGenerator<T> generator) Generate a class which is related to specified compile-type-generated interface.- Type Parameters:
T
- Type of generated class- Parameters:
bindingInterface
- Binding compile-time-generated interfacefqcn
- Fully-Qualified Class Name of the generated classgenerator
- Code generator to run- Returns:
- A generated class object
- Throws:
NullPointerException
- if any argument is null
-
getGeneratedClass
-
hashCode
public final int hashCode() -
equals
-
toString
-
builder(Class)
instead