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 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.

  • Method Details

    • create

      @Deprecated(since="14.0.7") public static @NonNull BindingClassLoader create(Class<?> rootClass, @Nullable File dumpDir)
      Deprecated.
      Use builder(Class) instead
      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
    • builder

      public static @NonNull BindingClassLoader.Builder builder(Class<?> rootClass)
    • ofRootClass

      public static @NonNull BindingClassLoader ofRootClass(Class<?> rootClass)
      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 - 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