Interface GremlinScriptEngineManager
- All Known Implementing Classes:
CachedGremlinScriptEngineManager,DefaultGremlinScriptEngineManager
public interface GremlinScriptEngineManager
The
ScriptEngineManager implements a discovery, instantiation and configuration mechanism for
GremlinScriptEngine classes and also maintains a collection of key/value pairs storing state shared by all
engines created by it. This class uses the ServiceProvider mechanism to enumerate all the
implementations of GremlinScriptEngineFactory. The ScriptEngineManager provides a method
to return a list of all these factories as well as utility methods which look up factories on the basis of language
name, file extension and mime type.
The Bindings of key/value pairs, referred to as the "Global Scope" maintained by the manager is available
to all instances of @code ScriptEngine} created by the GremlinScriptEngineManager. The values
in the Bindings are generally exposed in all scripts.
This interface is based quite heavily on the workings of the ScriptEngineManager supplied in the
javax.script packages, but adds some additional features that are specific to Gremlin and TinkerPop.
Unfortunately, it's not easily possible to extend ScriptEngineManager directly as there certain behaviors
don't appear to be be straightforward to implement and member variables are all private. It is important to note
that this interface is designed to provide support for "Gremlin-enabled" ScriptEngine instances (i.e. those
that extend from GremlinScriptEngine) and is not meant to manage just any ScriptEngine instance
that may be on the path.- Author:
- Stephen Mallette (http://stephen.genoprime.com)
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddPlugin(GremlinPlugin plugin) AddGremlinPlugininstances to customize newly createdGremlinScriptEngineinstances.Gets the value for the specified key in the global scope.Gets the bindings of theBindingsin global scope.getCustomizers(String scriptEngineName) Get the list ofCustomizerinstances filtered by thescriptEngineName.getEngineByExtension(String extension) Look up and create aGremlinScriptEnginefor a given extension.getEngineByMimeType(String mimeType) Look up and create aGremlinScriptEnginefor a given mime type.getEngineByName(String shortName) Looks up and creates aGremlinScriptEnginefor a given name.Returns a list whose elements are instances of all theGremlinScriptEngineFactoryclasses found by the discovery mechanism.voidSets the specified key/value pair in the global scope.voidregisterEngineExtension(String extension, GremlinScriptEngineFactory factory) Registers aGremlinScriptEngineFactoryto handle an extension.voidregisterEngineMimeType(String type, GremlinScriptEngineFactory factory) Registers aGremlinScriptEngineFactoryto handle a mime type.voidregisterEngineName(String name, GremlinScriptEngineFactory factory) Registers aGremlinScriptEngineFactoryto handle a language name.voidsetBindings(Bindings bindings) Stores the specifiedBindingsas a global for allGremlinScriptEngineobjects created by it.
-
Method Details
-
setBindings
Stores the specifiedBindingsas a global for allGremlinScriptEngineobjects created by it.- Throws:
IllegalArgumentException- if bindings is null.
-
getBindings
Bindings getBindings()Gets the bindings of theBindingsin global scope. -
put
Sets the specified key/value pair in the global scope. The key may not be null or empty.- Throws:
IllegalArgumentException- if key is null or empty.
-
get
Gets the value for the specified key in the global scope. -
getEngineByName
Looks up and creates aGremlinScriptEnginefor a given name. The algorithm first searches for aGremlinScriptEngineFactorythat has been registered as a handler for the specified name using theregisterEngineExtension(String, GremlinScriptEngineFactory)method. If one is not found, it searches the set ofGremlinScriptEngineFactoryinstances stored by the constructor for one with the specified name. If aScriptEngineFactoryis found by either method, it is used to create instance ofGremlinScriptEngine.- Parameters:
shortName- The short name of theGremlinScriptEngineimplementation returned by theScriptEngineFactory.getNames()method.- Returns:
- A
GremlinScriptEnginecreated by the factory located in the search. Returnsnullif no such factory was found. The global scope of this manager is applied to the newly createdGremlinScriptEngine - Throws:
NullPointerException- if shortName isnull.
-
getEngineByExtension
Look up and create aGremlinScriptEnginefor a given extension. The algorithm used bygetEngineByName(String)is used except that the search starts by looking for aGremlinScriptEngineFactoryregistered to handle the given extension usingregisterEngineExtension(String, GremlinScriptEngineFactory).- Returns:
- The engine to handle scripts with this extension. Returns
nullif not found. - Throws:
NullPointerException- if extension isnull.
-
getEngineByMimeType
Look up and create aGremlinScriptEnginefor a given mime type. The algorithm used bygetEngineByName(String)is used except that the search starts by looking for aGremlinScriptEngineFactoryregistered to handle the given mime type usingregisterEngineMimeType(String, GremlinScriptEngineFactory).- Parameters:
mimeType- The given mime type- Returns:
- The engine to handle scripts with this mime type. Returns
nullif not found. - Throws:
NullPointerException- if mime-type isnull.
-
getEngineFactories
List<GremlinScriptEngineFactory> getEngineFactories()Returns a list whose elements are instances of all theGremlinScriptEngineFactoryclasses found by the discovery mechanism.- Returns:
- List of all discovered
GremlinScriptEngineFactoryobjects.
-
addPlugin
AddGremlinPlugininstances to customize newly createdGremlinScriptEngineinstances. -
registerEngineName
Registers aGremlinScriptEngineFactoryto handle a language name. Overrides any such association found using the discovery mechanism.- Parameters:
name- The name to be associated with theGremlinScriptEngineFactoryfactory- The class to associate with the given name.- Throws:
NullPointerException- if any of the parameters is null.
-
registerEngineMimeType
Registers aGremlinScriptEngineFactoryto handle a mime type. Overrides any such association found using the discovery mechanism.- Parameters:
type- The mime type to be associated with theGremlinScriptEngineFactory.factory- The class to associate with the given mime type.- Throws:
NullPointerException- if any of the parameters is null.
-
registerEngineExtension
Registers aGremlinScriptEngineFactoryto handle an extension. Overrides any such association found using the discovery mechanism.- Parameters:
extension- The extension type to be associated with theGremlinScriptEngineFactoryfactory- The class to associate with the given extension.- Throws:
NullPointerException- if any of the parameters is null.
-
getCustomizers
Get the list ofCustomizerinstances filtered by thescriptEngineName.
-