Class ScriptContext<FactoryType>
- java.lang.Object
-
- org.elasticsearch.script.ScriptContext<FactoryType>
-
public final class ScriptContext<FactoryType> extends java.lang.ObjectThe information necessary to compile and run a script. AScriptContextcontains the information related to a single use case and the interfaces and methods necessary for aScriptEngineto implement.There are at least two (and optionally a third) related classes which must be defined.
The InstanceType is a class which users of the script api call to execute a script. It may be stateful. Instances of the InstanceType may be executed multiple times by a caller with different arguments. This class must have an abstract method named
executewhichScriptEngineimplementations will define.The FactoryType is a factory class returned by the
ScriptServicewhen compiling a script. This class must be stateless so it is cacheable by theScriptService. It must have one of the following:- An abstract method named
newInstancewhich returns an instance of InstanceType - An abstract method named
newFactorywhich returns an instance of StatefulFactoryType
The StatefulFactoryType is an optional class which allows a stateful factory from the stateless factory type required by the
ScriptService. If defined, the StatefulFactoryType must have a method namednewInstancewhich returns an instance of InstanceType.Both the FactoryType and StatefulFactoryType may have abstract methods to indicate whether a variable is used in a script. These method should return a
booleanand their name should start withneeds, followed by the variable name, with the first letter uppercased. For example, to check if a variabledocis used, a methodboolean needsDoc()should be added. If the variable name starts with an underscore, for example,_score, the needs method would beboolean needs_score(). - An abstract method named
-
-
Field Summary
Fields Modifier and Type Field Description java.lang.Class<FactoryType>factoryClazzA factory class for constructing script or stateful factory instances.java.lang.Class<?>instanceClazzA class that is an instance of a script.java.lang.StringnameA unique identifier for this context.java.lang.Class<?>statefulFactoryClazzA factory class for construct script instances.
-
Constructor Summary
Constructors Constructor Description ScriptContext(java.lang.String name, java.lang.Class<FactoryType> factoryClazz)Construct a context with the related instance and compiled classes.
-
-
-
Field Detail
-
name
public final java.lang.String name
A unique identifier for this context.
-
factoryClazz
public final java.lang.Class<FactoryType> factoryClazz
A factory class for constructing script or stateful factory instances.
-
statefulFactoryClazz
public final java.lang.Class<?> statefulFactoryClazz
A factory class for construct script instances.
-
instanceClazz
public final java.lang.Class<?> instanceClazz
A class that is an instance of a script.
-
-
Constructor Detail
-
ScriptContext
public ScriptContext(java.lang.String name, java.lang.Class<FactoryType> factoryClazz)Construct a context with the related instance and compiled classes.
-
-