Class LayeredEngine

java.lang.Object
ch.grengine.engine.LayeredEngine
All Implemented Interfaces:
Engine, Closeable, AutoCloseable

public class LayeredEngine extends Object implements Engine
Engine based on instances of LayeredClassLoader.
Since:
1.0
Author:
Alain Stalder, Made in Switzerland.
  • Constructor Details

    • LayeredEngine

      protected LayeredEngine(LayeredEngine.Builder builder)
      constructor from builder.
      Parameters:
      builder - builder
      Since:
      1.0
  • Method Details

    • getLoader

      public Loader getLoader()
      Description copied from interface: Engine
      gets the default attached loader.
      Specified by:
      getLoader in interface Engine
      Returns:
      default attached loader
    • newAttachedLoader

      public Loader newAttachedLoader()
      creates and gets a new attached loader, backed by the same bytecode as all other shared loaders created by this engine, with a top code cache shared with all other attached loaders of this engine and automatically updated if code layers are set.
      Specified by:
      newAttachedLoader in interface Engine
      Returns:
      new attached loader
      Since:
      1.0
    • newDetachedLoader

      public Loader newDetachedLoader()
      creates and gets a new detached loader, backed initially by the same bytecode as all attached loaders created by this engine (code layers and top code cache), but not updated if code layers are set and with a separate top code cache instance.

      For example, a web application might create a detached loader for each new HTTP session: A new loader in order to separate static variables of scripts between sessions (security feature); a detached loader in order to keep code layers constant during the lifetime of the session (consistent behavior of Groovy script calls).

      Specified by:
      newDetachedLoader in interface Engine
      Returns:
      new detached loader
      Since:
      1.0
    • loadMainClass

      public Class<?> loadMainClass(Loader loader, Source source)
      Description copied from interface: Engine
      loads the main class of the given source from the given loader.

      Note that if a class with the main class name is available for loading, but was not compiled as part of a set of Source that included the given source, that class will not count for loading.

      Specified by:
      loadMainClass in interface Engine
      Parameters:
      loader - loader
      source - source
      Returns:
      loaded class
    • loadClass

      public Class<?> loadClass(Loader loader, Source source, String name)
      Description copied from interface: Engine
      loads a class with the given name and from the given source from the given loader.

      Note that if a class with the given class name is available for loading, but was not compiled as part of a set of Source that included the given source, that class will not count for loading.

      Specified by:
      loadClass in interface Engine
      Parameters:
      loader - loader
      source - source
      name - class name
      Returns:
      loaded class
    • loadClass

      public Class<?> loadClass(Loader loader, String name)
      Description copied from interface: Engine
      loads a class by name from the given loader.

      Note that a top code cache is not searched in this case, because each set of source has its own top loader.

      Specified by:
      loadClass in interface Engine
      Parameters:
      loader - loader
      name - class name
      Returns:
      loaded class
    • setCodeLayers

      public void setCodeLayers(List<Code> codeLayers)
      Description copied from interface: Engine
      sets (replaces) code layers of the engine, based on already compiled code layers.

      Note that normally it is supported to do this "live", while the engine is used.

      Specified by:
      setCodeLayers in interface Engine
      Parameters:
      codeLayers - code layers
    • setCodeLayersBySource

      public void setCodeLayersBySource(List<Sources> sourcesLayers)
      Description copied from interface: Engine
      sets (replaces) code layers of the engine, based on sources to compile to code layers.

      Note that normally it is supported to do this "live", while the engine is used.

      Specified by:
      setCodeLayersBySource in interface Engine
      Parameters:
      sourcesLayers - sources layers
    • close

      public void close()
      Description copied from interface: Engine
      release metadata for all classed ever loaded using this engine.

      Allows to remove metadata associated by Groovy (or Java) with a class, which is often necessary to get on-the-fly garbage collection.

      Generally call only when really done using this engine and all loaded classes; subsequently trying to use this engine or its classes results generally in undefined behavior.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface Engine
    • asClassLoader

      public ClassLoader asClassLoader(Loader loader)
      Description copied from interface: Engine
      returns a class loader based on this engine and the given loader.

      Note that the returned class loader typically does not load classes itself; it just wraps the engine and its loader.

      Specified by:
      asClassLoader in interface Engine
      Parameters:
      loader - loader
      Returns:
      class loader
    • getBuilder

      public LayeredEngine.Builder getBuilder()
      gets the builder.
      Returns:
      builder
      Since:
      1.0