Class BindingClassLoader

java.lang.Object
java.lang.ClassLoader
org.opendaylight.yangtools.binding.loader.BindingClassLoader

public abstract sealed class BindingClassLoader extends ClassLoader
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.

  • Method Details

    • create

      public static @NonNull BindingClassLoader create(Class<?> rootClass, @Nullable File dumpDir)
      Instantiate a new BindingClassLoader, which serves as the root of generated code loading.
      Parameters:
      rootClass - Class from which to derive the class loader
      dumpDir - Directory in which to dump loaded bytecode
      Returns:
      A new BindingClassLoader.
      Throws:
      NullPointerException - if parentLoader is null
    • 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 interface
      fqcn - Fully-Qualified Class Name of the generated class
      generator - Code generator to run
      Returns:
      A generated class object
      Throws:
      NullPointerException - if any argument is null
    • getGeneratedClass

      public final @NonNull Class<?> getGeneratedClass(Class<?> bindingInterface, String fqcn)
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public final boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public final String toString()
      Overrides:
      toString in class Object