Class LayeredEngine
- All Implemented Interfaces:
Engine,Closeable,AutoCloseable
LayeredClassLoader.- Since:
- 1.0
- Author:
- Alain Stalder, Made in Switzerland.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedLayeredEngine(LayeredEngine.Builder builder) constructor from builder. -
Method Summary
Modifier and TypeMethodDescriptionasClassLoader(Loader loader) returns a class loader based on this engine and the given loader.voidclose()release metadata for all classed ever loaded using this engine.gets the builder.gets the default attached loader.Class<?>loads a class with the given name and from the given source from the given loader.Class<?>loads a class by name from the given loader.Class<?>loadMainClass(Loader loader, Source source) loads the main class of the given source from the given loader.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.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.voidsetCodeLayers(List<Code> codeLayers) sets (replaces) code layers of the engine, based on already compiled code layers.voidsetCodeLayersBySource(List<Sources> sourcesLayers) sets (replaces) code layers of the engine, based on sources to compile to code layers.
-
Constructor Details
-
LayeredEngine
constructor from builder.- Parameters:
builder- builder- Since:
- 1.0
-
-
Method Details
-
getLoader
Description copied from interface:Enginegets the default attached 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:
newAttachedLoaderin interfaceEngine- Returns:
- new attached loader
- Since:
- 1.0
-
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:
newDetachedLoaderin interfaceEngine- Returns:
- new detached loader
- Since:
- 1.0
-
loadMainClass
Description copied from interface:Engineloads 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
Sourcethat included the given source, that class will not count for loading.- Specified by:
loadMainClassin interfaceEngine- Parameters:
loader- loadersource- source- Returns:
- loaded class
-
loadClass
Description copied from interface:Engineloads 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
Sourcethat included the given source, that class will not count for loading. -
loadClass
Description copied from interface:Engineloads 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.
-
setCodeLayers
Description copied from interface:Enginesets (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:
setCodeLayersin interfaceEngine- Parameters:
codeLayers- code layers
-
setCodeLayersBySource
Description copied from interface:Enginesets (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:
setCodeLayersBySourcein interfaceEngine- Parameters:
sourcesLayers- sources layers
-
close
public void close()Description copied from interface:Enginerelease 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.
-
asClassLoader
Description copied from interface:Enginereturns 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:
asClassLoaderin interfaceEngine- Parameters:
loader- loader- Returns:
- class loader
-
getBuilder
gets the builder.- Returns:
- builder
- Since:
- 1.0
-