public interface Engine extends Closeable
Provides the base functionality for a Grengine
,
without all the convenience methods.
Modifier and Type | Method and Description |
---|---|
ClassLoader |
asClassLoader(Loader loader)
returns a class loader based on this engine and the given loader.
|
void |
close()
release metadata for all classed ever loaded using this engine.
|
Loader |
getLoader()
gets the default attached loader.
|
Class<?> |
loadClass(Loader loader,
Source source,
String name)
loads a class with the given name and from the given source from the given loader.
|
Class<?> |
loadClass(Loader loader,
String name)
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.
|
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.
|
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.
|
void |
setCodeLayers(List<Code> codeLayers)
sets (replaces) code layers of the engine, based on already compiled code layers.
|
void |
setCodeLayersBySource(List<Sources> sourcesLayers)
sets (replaces) code layers of the engine, based on sources to compile to code layers.
|
Loader getLoader()
Loader newAttachedLoader()
Loader newDetachedLoader()
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).
Class<?> loadMainClass(Loader loader, Source source)
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.
loader
- loadersource
- sourceCompileException
- if compilation was necessary to load the class and failedLoadException
- if loading failed, including if the class was not foundClass<?> loadClass(Loader loader, Source source, String name)
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.
loader
- loadersource
- sourcename
- class nameCompileException
- if compilation was necessary to load the class and failedLoadException
- if loading failed, including if the class was not foundClass<?> loadClass(Loader loader, String name)
Note that a top code cache is not searched in this case, because each set of source has its own top loader.
loader
- loadername
- class nameLoadException
- if loading failed, including if the class was not foundvoid setCodeLayers(List<Code> codeLayers)
Note that normally it is supported to do this "live", while the engine is used.
codeLayers
- code layersClassNameConflictException
- 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 nullvoid setCodeLayersBySource(List<Sources> sourcesLayers)
Note that normally it is supported to do this "live", while the engine is used.
sourcesLayers
- sources layersCompileException
- 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 nullvoid close()
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.
close
in interface AutoCloseable
close
in interface Closeable
ClassLoader asClassLoader(Loader loader)
Note that the returned class loader typically does not load classes itself; it just wraps the engine and its loader.
loader
- loaderNullPointerException
- if the loader is nullIllegalArgumentException
- if the loader does not match the engine