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
BindingCodecContext instance, so any generated classes from it can be garbage-collected when the context
is destroyed, as well as to prevent two contexts trampling over each other.
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 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
Instantiate a new BindingClassLoader, which serves as the root of generated code loading.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()
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
Instantiate 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
-
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
-