Class ModuleLayerBuilder

java.lang.Object
org.tentackle.common.ModuleLayerBuilder

public final class ModuleLayerBuilder extends Object
Builds a graph of ModuleLayers from a LayerGraphSpec.

Each layer is defined with exactly one classloader for all its modules (ModuleLayer.defineModulesWithOneLoader(Configuration, List, ClassLoader)), so a layer is the unit of isolation: two sibling layers may hold different versions of the same module, but modules placed in the very same layer are not isolated from each other.

Layers are built in an order such that a layer's parents always exist before the layer itself is built. Unknown or cyclic parent relationships are detected and rejected.

The classloader of a layer is parented on the classloader of its first parent layer (or on the given parent classloader for layers parented on the boot layer). This affects only the lookup of classes not defined in any module.

A layer with several parents that each (still) define a different, conflicting module of the same name is rejected explicitly (see checkDisjointAncestry(List, String)), since the JDK's own module resolution does not reject this itself — it would otherwise silently bind to just one of them.

Author:
harald
  • Method Details

    • build

      public static Map<String, ModuleLayer> build(LayerGraphSpec spec, ModuleLayer bootLayer, ClassLoader parentLoader)
      Builds the module layer graph described by the given spec. If the spec names a LayerGraphSpec.leafMainModule(), the package of the main class is opened to tentackle-common, so that LayerBootstrap can invoke the main method reflectively.
      Parameters:
      spec - the layer graph spec
      bootLayer - the boot layer, usually ModuleLayer.boot()
      parentLoader - the classloader to use as the parent of layers directly parented on the boot layer
      Returns:
      the built layers, keyed by layer name
      Throws:
      TentackleRuntimeException - if layer names are duplicate, parents are unknown or cyclic, a layer cannot be resolved, a layer has conflicting parents, the leaf layer is not defined, or the leaf main module is not found in the leaf layer