Class ScriptContext<FactoryType>

java.lang.Object
org.elasticsearch.script.ScriptContext<FactoryType>

public final class ScriptContext<FactoryType> extends Object
The information necessary to compile and run a script. A ScriptContext contains the information related to a single use case and the interfaces and methods necessary for a ScriptEngine to 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 execute which ScriptEngine implementations will define.

The FactoryType is a factory class returned by the ScriptService when compiling a script. This class must be stateless so it is cacheable by the ScriptService. It must have one of the following:

  • An abstract method named newInstance which returns an instance of InstanceType
  • An abstract method named newFactory which 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 named newInstance which 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 boolean and their name should start with needs, followed by the variable name, with the first letter uppercased. For example, to check if a variable doc is used, a method boolean needsDoc() should be added. If the variable name starts with an underscore, for example, _score, the needs method would be boolean needs_score().

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final boolean
    Determines if the script can be stored as part of the cluster state.
    final org.elasticsearch.core.TimeValue
    The default expiration of a script in the cache for the context, if not overridden
    final int
    The default size of the cache for the context if not overridden
    final boolean
    Is compilation rate limiting enabled for this context?
    static final org.elasticsearch.core.Tuple<Integer,org.elasticsearch.core.TimeValue>
    The default compilation rate limit for contexts with compilation rate limiting enabled
    A factory class for constructing script or stateful factory instances.
    final Class<?>
    A class that is an instance of a script.
    final String
    A unique identifier for this context.
    final Class<?>
    A factory class for construct script instances.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ScriptContext(String name, Class<FactoryType> factoryClazz)
    Construct a context with the related instance and compiled classes with defaults for cacheSizeDefault, cacheExpireDefault and compilationRateLimited and allow scripts of this context to be stored scripts
    ScriptContext(String name, Class<FactoryType> factoryClazz, int cacheSizeDefault, org.elasticsearch.core.TimeValue cacheExpireDefault, boolean compilationRateLimited, boolean allowStoredScript)
    Construct a context with the related instance and compiled classes with caller provided cache defaults
  • Method Summary

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_COMPILATION_RATE_LIMIT

      public static final org.elasticsearch.core.Tuple<Integer,org.elasticsearch.core.TimeValue> DEFAULT_COMPILATION_RATE_LIMIT
      The default compilation rate limit for contexts with compilation rate limiting enabled
    • name

      public final String name
      A unique identifier for this context.
    • factoryClazz

      public final Class<FactoryType> factoryClazz
      A factory class for constructing script or stateful factory instances.
    • statefulFactoryClazz

      public final Class<?> statefulFactoryClazz
      A factory class for construct script instances.
    • instanceClazz

      public final Class<?> instanceClazz
      A class that is an instance of a script.
    • cacheSizeDefault

      public final int cacheSizeDefault
      The default size of the cache for the context if not overridden
    • cacheExpireDefault

      public final org.elasticsearch.core.TimeValue cacheExpireDefault
      The default expiration of a script in the cache for the context, if not overridden
    • compilationRateLimited

      public final boolean compilationRateLimited
      Is compilation rate limiting enabled for this context?
    • allowStoredScript

      public final boolean allowStoredScript
      Determines if the script can be stored as part of the cluster state.
  • Constructor Details

    • ScriptContext

      public ScriptContext(String name, Class<FactoryType> factoryClazz, int cacheSizeDefault, org.elasticsearch.core.TimeValue cacheExpireDefault, boolean compilationRateLimited, boolean allowStoredScript)
      Construct a context with the related instance and compiled classes with caller provided cache defaults
    • ScriptContext

      public ScriptContext(String name, Class<FactoryType> factoryClazz)
      Construct a context with the related instance and compiled classes with defaults for cacheSizeDefault, cacheExpireDefault and compilationRateLimited and allow scripts of this context to be stored scripts