public class Grengine extends BaseGrengine
See BaseGrengine
for most convenience methods for using Grengine.
The matrix for running scripts is as follows:
run(<loader>,<source>,<binding>)
<loader>
: can be a specific loader or be omitted for the default loader
<source>
: can be an instance of source or indicated by script text, file or URL
<binding>
: can be an instance of Binding
, a map or be omitted for an empty binding
Examples:
run("println 'hello world!'")
: default loader, text-based source, empty binding
run(myLoader, new URL("http://acme.org/myScript.groovy", myBinding)
:
given loader, URL-based source, given binding
The matrices for loading classes, creating script instances and for creating sources are similar:
load(<loader>,<source>)
create(<loader>,<source>)
source(<source>)
Grengine performance:
Script
is of the order of nanoseconds.
DefaultSourceFactory
.
Modifier and Type | Class and Description |
---|---|
static class |
Grengine.Builder
Builder for instances of
Grengine . |
static class |
Grengine.Grape
Convenience class for easily getting a Grengine that works with Grape,
eliminating also a Groovy issue related to Grape (GROOVY-7407).
|
Modifier and Type | Field and Description |
---|---|
static long |
LATENCY_MS_INFINITE_STATIC
constant for an infinite latency (static).
|
engine, loader, sourceFactory
Modifier | Constructor and Description |
---|---|
|
Grengine()
constructor for a Grengine without any (static) code layers,
but with a top code cache.
|
|
Grengine(ClassLoader parent)
constructor for a Grengine without any (static) code layers,
but with a top code cache.
|
|
Grengine(ClassLoader parent,
Collection<URL> urls)
constructor for a Grengine based on a collection of URL-based scripts,
with a top code cache, and with tracking URLs based on content.
|
|
Grengine(ClassLoader parent,
org.codehaus.groovy.control.CompilerConfiguration config)
constructor for a Grengine without any (static) code layers,
but with a top code cache.
|
|
Grengine(ClassLoader parent,
org.codehaus.groovy.control.CompilerConfiguration config,
Collection<URL> urls)
constructor for a Grengine based on a collection of URL-based scripts,
with a top code cache, and with tracking URLs based on content.
|
|
Grengine(ClassLoader parent,
org.codehaus.groovy.control.CompilerConfiguration config,
File dir)
constructor for a Grengine based on scripts in a given script
directory, without subdirectories, and with a top code cache.
|
|
Grengine(ClassLoader parent,
org.codehaus.groovy.control.CompilerConfiguration config,
File dir,
DirMode dirMode)
constructor for a Grengine based on scripts in a given script
directory, optionally including subdirectories (recursively),
and with a top code cache.
|
|
Grengine(ClassLoader parent,
File dir)
constructor for a Grengine based on scripts in a given script
directory, without subdirectories, and with a top code cache.
|
|
Grengine(ClassLoader parent,
File dir,
DirMode dirMode)
constructor for a Grengine based on scripts in a given script
directory, optionally including subdirectories (recursively),
and with a top code cache.
|
|
Grengine(Collection<URL> urls)
constructor for a Grengine based on a collection of URL-based scripts,
with a top code cache, and with tracking URLs based on content.
|
|
Grengine(org.codehaus.groovy.control.CompilerConfiguration config)
constructor for a Grengine without any (static) code layers,
but with a top code cache.
|
|
Grengine(org.codehaus.groovy.control.CompilerConfiguration config,
Collection<URL> urls)
constructor for a Grengine based on a collection of URL-based scripts,
with a top code cache, and with tracking URLs based on content.
|
|
Grengine(org.codehaus.groovy.control.CompilerConfiguration config,
File dir)
constructor for a Grengine based on scripts in a given script
directory, without subdirectories, and with a top code cache.
|
|
Grengine(org.codehaus.groovy.control.CompilerConfiguration config,
File dir,
DirMode dirMode)
constructor for a Grengine based on scripts in a given script
directory, optionally including subdirectories (recursively),
and with a top code cache.
|
|
Grengine(File dir)
constructor for a Grengine based on scripts in a given script
directory, without subdirectories, and with a top code cache.
|
|
Grengine(File dir,
DirMode dirMode)
constructor for a Grengine based on scripts in a given script
directory, optionally including subdirectories (recursively),
and with a top code cache.
|
protected |
Grengine(Grengine.Builder builder)
constructor from builder.
|
Modifier and Type | Method and Description |
---|---|
Grengine.Builder |
getBuilder()
gets the builder.
|
GrengineException |
getLastUpdateException()
updates code layers if necessary and gets the exception that occurred at the last update.
|
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<?> |
loadClass(Source source,
String name)
loads a class with the given name and from the given source from the default loader.
|
Class<?> |
loadClass(String name)
loads a class by name from the default loader.
|
Class<?> |
loadMainClass(Loader loader,
Source source)
loads the main class of the given source from the given loader.
|
Class<?> |
loadMainClass(Source source)
loads the main class of the given source from the default loader.
|
protected void |
updateEngineIfSourcesLayersModified()
updates the engine if sources layers have been modified.
|
asClassLoader, asClassLoader, binding, binding, binding, binding, binding, binding, close, create, create, create, create, create, create, create, create, create, create, create, getEngine, getLoader, getSourceFactory, load, load, load, load, load, load, load, load, load, load, newAttachedLoader, newDetachedLoader, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, source, source, source, source
public static final long LATENCY_MS_INFINITE_STATIC
protected Grengine(Grengine.Builder builder)
Call getLastUpdateException()
after constructing if you need
to make sure all sources could be compiled without errors.
builder
- builderpublic Grengine()
Constructed from a builder with default settings.
public Grengine(org.codehaus.groovy.control.CompilerConfiguration config)
Constructed from a builder with default settings.
config
- compiler configuration to use for compiling all sourcesNullPointerException
- if the compiler configuration is nullpublic Grengine(ClassLoader parent)
Constructed from a builder with default settings.
parent
- parent class loader for the engineNullPointerException
- if the parent class loader is nullpublic Grengine(ClassLoader parent, org.codehaus.groovy.control.CompilerConfiguration config)
Constructed from a builder with default settings.
parent
- parent class loader for the engineconfig
- compiler configuration to use for compiling all sourcesNullPointerException
- if any argument is nullpublic Grengine(File dir)
Script extensions are the single extension "groovy".
Load modes are "current first" for the script directory code layer and "parent first" for the top code cache.
Constructed from builders with otherwise default settings.
Call getLastUpdateException()
after constructing if you need to make sure
all sources can be compiled without errors.
dir
- script directoryNullPointerException
- if the directory is nullpublic Grengine(ClassLoader parent, File dir)
Script extensions are the single extension "groovy".
Load modes are "current first" for the script directory code layer and "parent first" for the top code cache.
Constructed from builders with otherwise default settings.
Call getLastUpdateException()
after constructing if you need to make sure
all sources can be compiled without errors.
parent
- parent class loader for the enginedir
- script directoryNullPointerException
- if any argument is nullpublic Grengine(org.codehaus.groovy.control.CompilerConfiguration config, File dir)
Script extensions are taken from the given compiler configuration, which defaults to the single extension "groovy".
Load modes are "current first" for the script directory code layer and "parent first" for the top code cache.
Constructed from builders with otherwise default settings.
Call getLastUpdateException()
after constructing if you need to make sure
all sources can be compiled without errors.
config
- compiler configuration to use for compiling all sourcesdir
- script directoryNullPointerException
- if any argument is nullpublic Grengine(ClassLoader parent, org.codehaus.groovy.control.CompilerConfiguration config, File dir)
Script extensions are taken from the given compiler configuration, which defaults to the single extension "groovy".
Load modes are "current first" for the script directory code layer and "parent first" for the top code cache.
Constructed from builders with otherwise default settings.
Call getLastUpdateException()
after constructing if you need to make sure
all sources can be compiled without errors.
parent
- parent class loader for the engineconfig
- compiler configuration to use for compiling all sourcesdir
- script directoryNullPointerException
- if any argument is nullpublic Grengine(File dir, DirMode dirMode)
Script extensions are the single extension "groovy".
Load modes are "current first" for the script directory code layer and "parent first" for the top code cache.
Constructed from builders with otherwise default settings.
Call getLastUpdateException()
after constructing if you need to make sure
all sources can be compiled without errors.
dir
- script directorydirMode
- dir modeNullPointerException
- if any argument is nullpublic Grengine(ClassLoader parent, File dir, DirMode dirMode)
Script extensions are the single extension "groovy".
Load modes are "current first" for the script directory code layer and "parent first" for the top code cache.
Constructed from builders with otherwise default settings.
Call getLastUpdateException()
after constructing if you need to make sure
all sources can be compiled without errors.
parent
- parent class loader for the enginedir
- script directorydirMode
- dir modeNullPointerException
- if any argument is nullpublic Grengine(org.codehaus.groovy.control.CompilerConfiguration config, File dir, DirMode dirMode)
Script extensions are taken from the given compiler configuration, which defaults to the single extension "groovy".
Load modes are "current first" for the script directory code layer and "parent first" for the top code cache.
Constructed from builders with otherwise default settings.
Call getLastUpdateException()
after constructing if you need to make sure
all sources can be compiled without errors.
config
- compiler configuration to use for compiling all sourcesdir
- script directorydirMode
- dir modeNullPointerException
- if any argument is nullpublic Grengine(ClassLoader parent, org.codehaus.groovy.control.CompilerConfiguration config, File dir, DirMode dirMode)
Script extensions are taken from the given compiler configuration, which defaults to the single extension "groovy".
Load modes are "current first" for the script directory code layer and "parent first" for the top code cache.
Constructed from builders with otherwise default settings.
Call getLastUpdateException()
after constructing if you need to make sure
all sources can be compiled without errors.
parent
- parent class loader for the engineconfig
- compiler configuration to use for compiling all sourcesdir
- script directorydirMode
- dir modeNullPointerException
- if any argument is nullpublic Grengine(Collection<URL> urls)
Load modes are "current first" for the script directory code layer and "parent first" for the top code cache.
Uses a DefaultSourceFactory
with tracking URL content set to true.
Constructed from builders with otherwise default settings.
Call getLastUpdateException()
after constructing if you need to make sure
all sources can be compiled without errors.
urls
- collection of URL-based scriptsNullPointerException
- if the URL collection is nullpublic Grengine(ClassLoader parent, Collection<URL> urls)
Load modes are "current first" for the script directory code layer and "parent first" for the top code cache.
Uses a DefaultSourceFactory
with tracking URL content set to true.
Constructed from builders with otherwise default settings.
Call getLastUpdateException()
after constructing if you need to make sure
all sources can be compiled without errors.
parent
- parent class loader for the engineurls
- collection of URL-based scriptsNullPointerException
- if the URL collection is nullpublic Grengine(org.codehaus.groovy.control.CompilerConfiguration config, Collection<URL> urls)
Load modes are "current first" for the script directory code layer and "parent first" for the top code cache.
Uses a DefaultSourceFactory
with tracking URL content set to true.
Constructed from builders with otherwise default settings.
Call getLastUpdateException()
after constructing if you need to make sure
all sources can be compiled without errors.
config
- compiler configuration to use for compiling all sourcesurls
- collection of URL-based scriptsNullPointerException
- if any argument is nullpublic Grengine(ClassLoader parent, org.codehaus.groovy.control.CompilerConfiguration config, Collection<URL> urls)
Load modes are "current first" for the script directory code layer and "parent first" for the top code cache.
Uses a DefaultSourceFactory
with tracking URL content set to true.
Constructed from builders with otherwise default settings.
Call getLastUpdateException()
after constructing if you need to make sure
all sources can be compiled without errors.
parent
- parent class loader for the engineconfig
- compiler configuration to use for compiling all sourcesurls
- collection of URL-based scriptsNullPointerException
- if any argument is nullpublic Grengine.Builder getBuilder()
public GrengineException getLastUpdateException()
protected void updateEngineIfSourcesLayersModified()
public Class<?> loadMainClass(Loader loader, Source source)
BaseGrengine
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 class BaseGrengine
loader
- loadersource
- sourceEngine.loadMainClass(Loader loader, Source source)
public Class<?> loadMainClass(Source source)
BaseGrengine
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 class BaseGrengine
source
- sourceEngine.loadMainClass(Loader loader, Source source)
public Class<?> loadClass(Loader loader, Source source, String name)
BaseGrengine
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.
loadClass
in class BaseGrengine
loader
- loadersource
- sourcename
- class nameEngine.loadClass(Loader loader, Source source, String name)
public Class<?> loadClass(Source source, String name)
BaseGrengine
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.
loadClass
in class BaseGrengine
source
- sourcename
- class nameEngine.loadClass(Loader loader, Source source, String name)
public Class<?> loadClass(Loader loader, String name)
BaseGrengine
Note that a top code cache is not searched in this case, because each set of source has its own top loader.
loadClass
in class BaseGrengine
loader
- loadername
- class nameEngine.loadClass(Loader loader, String name)
public Class<?> loadClass(String name)
BaseGrengine
Note that a top code cache is not searched in this case, because each set of source has its own top loader.
loadClass
in class BaseGrengine
name
- class nameEngine.loadClass(Loader loader, String name)