public class LayeredEngine extends Object implements Engine
LayeredClassLoader
.Modifier and Type | Class and Description |
---|---|
static class |
LayeredEngine.Builder
Builder for instances of
LayeredEngine . |
Modifier | Constructor and Description |
---|---|
protected |
LayeredEngine(LayeredEngine.Builder builder)
constructor from builder.
|
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.
|
LayeredEngine.Builder |
getBuilder()
gets the builder.
|
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,
with a top code cache shared with all other attached loaders
of 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 (code layers
and top code cache), but not updated if code layers are set
and with a separate top code cache instance.
|
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.
|
protected LayeredEngine(LayeredEngine.Builder builder)
builder
- builderpublic Loader getLoader()
Engine
public Loader newAttachedLoader()
newAttachedLoader
in interface Engine
public 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).
newDetachedLoader
in interface Engine
public Class<?> loadMainClass(Loader loader, Source source)
Engine
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.
loadMainClass
in interface Engine
loader
- loadersource
- sourcepublic Class<?> loadClass(Loader loader, Source source, String name)
Engine
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.
public Class<?> loadClass(Loader loader, String name)
Engine
Note that a top code cache is not searched in this case, because each set of source has its own top loader.
public void setCodeLayers(List<Code> codeLayers)
Engine
Note that normally it is supported to do this "live", while the engine is used.
setCodeLayers
in interface Engine
codeLayers
- code layerspublic void setCodeLayersBySource(List<Sources> sourcesLayers)
Engine
Note that normally it is supported to do this "live", while the engine is used.
setCodeLayersBySource
in interface Engine
sourcesLayers
- sources layerspublic void close()
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.
public ClassLoader asClassLoader(Loader loader)
Engine
Note that the returned class loader typically does not load classes itself; it just wraps the engine and its loader.
asClassLoader
in interface Engine
loader
- loaderpublic LayeredEngine.Builder getBuilder()