Interface Engine
- All Superinterfaces:
AutoCloseable,Closeable
- All Known Implementing Classes:
LayeredEngine
Provides the base functionality for a Grengine,
without all the convenience methods.
- Since:
- 1.0
- Author:
- Alain Stalder, Made in Switzerland.
-
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 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 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, but not updated if code layers are set.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.
-
Method Details
-
getLoader
Loader getLoader()gets the default attached loader.- Returns:
- default attached loader
- Since:
- 1.0
-
newAttachedLoader
Loader newAttachedLoader()creates and gets a new attached loader, backed by the same bytecode as all other shared loaders created by this engine and automatically updated if code layers are set.- Returns:
- new attached loader
- Since:
- 1.0
-
newDetachedLoader
Loader newDetachedLoader()creates and gets a new detached loader, backed initially by the same bytecode as all attached loaders created by this engine, but not updated if code layers are set.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).
- Returns:
- new detached loader
- Since:
- 1.0
-
loadMainClass
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
Sourcethat included the given source, that class will not count for loading.- Parameters:
loader- loadersource- source- Returns:
- loaded class
- Throws:
CompileException- if compilation was necessary to load the class and failedLoadException- if loading failed, including if the class was not found- Since:
- 1.0
-
loadClass
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
Sourcethat included the given source, that class will not count for loading.- Parameters:
loader- loadersource- sourcename- class name- Returns:
- loaded class
- Throws:
CompileException- if compilation was necessary to load the class and failedLoadException- if loading failed, including if the class was not found- Since:
- 1.0
-
loadClass
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.
- Parameters:
loader- loadername- class name- Returns:
- loaded class
- Throws:
LoadException- if loading failed, including if the class was not found- Since:
- 1.0
-
setCodeLayers
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.
- Parameters:
codeLayers- code layers- Throws:
ClassNameConflictException- optionally if the same class name occurs in different code layers or would already be available from a parent class loaderNullPointerException- if code layers are null- Since:
- 1.0
-
setCodeLayersBySource
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.
- Parameters:
sourcesLayers- sources layers- Throws:
CompileException- if compilation failedClassNameConflictException- optionally if the same class name resulted from compiling different sources layers or would already be available from a parent class loaderNullPointerException- if sources layers are null- Since:
- 1.0
-
close
void close()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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Since:
- 1.1
-
asClassLoader
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.
- Parameters:
loader- loader- Returns:
- class loader
- Throws:
NullPointerException- if the loader is nullIllegalArgumentException- if the loader does not match the engine- Since:
- 1.3
-