Class CachedGremlinScriptEngineManager
java.lang.Object
org.apache.tinkerpop.gremlin.jsr223.DefaultGremlinScriptEngineManager
org.apache.tinkerpop.gremlin.jsr223.CachedGremlinScriptEngineManager
- All Implemented Interfaces:
GremlinScriptEngineManager
An implementation of the
GremlinScriptEngineManager that caches the instances of the
GremlinScriptEngine instances that are created by it. Note that the cache is relevant to the instance
of the CachedGremlinScriptEngineManager and is not global to the JVM.
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 class 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 straightforward to implement and member variables are all private. It is important to note
that this class 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.
As this is a "Gremlin" ScriptEngine, certain common imports are automatically applied when a
GremlinScriptEngine is instantiated via the GremlinScriptEngineFactory.. Initial imports from
gremlin-core come from the CoreImports.-
Constructor Summary
ConstructorsConstructorDescriptionCachedGremlinScriptEngineManager(Set<String> allowedEngines) Creates a cached manager with an allowlist of engine names. -
Method Summary
Modifier and TypeMethodDescriptiongetEngineByExtension(String extension) Gets aGremlinScriptEnginefrom cache or creates a new one from theGremlinScriptEngineFactory.getEngineByMimeType(String mimeType) Gets aGremlinScriptEnginefrom cache or creates a new one from theGremlinScriptEngineFactory.getEngineByName(String shortName) Gets aGremlinScriptEnginefrom cache or creates a new one from theGremlinScriptEngineFactory.Methods inherited from class org.apache.tinkerpop.gremlin.jsr223.DefaultGremlinScriptEngineManager
addPlugin, get, getBindings, getCustomizers, getEngineFactories, put, registerEngineExtension, registerEngineMimeType, registerEngineName, setBindings
-
Constructor Details
-
CachedGremlinScriptEngineManager
public CachedGremlinScriptEngineManager()- See Also:
-
CachedGremlinScriptEngineManager
-
CachedGremlinScriptEngineManager
Creates a cached manager with an allowlist of engine names.- See Also:
-
-
Method Details
-
getEngineByName
Gets aGremlinScriptEnginefrom cache or creates a new one from theGremlinScriptEngineFactory. 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 theDefaultGremlinScriptEngineManager.registerEngineExtension(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.- Specified by:
getEngineByNamein interfaceGremlinScriptEngineManager- Overrides:
getEngineByNamein classDefaultGremlinScriptEngineManager- 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
-
getEngineByExtension
Gets aGremlinScriptEnginefrom cache or creates a new one from theGremlinScriptEngineFactory. Look up and create aGremlinScriptEnginefor a given extension. The algorithm used byDefaultGremlinScriptEngineManager.getEngineByName(String)is used except that the search starts by looking for aGremlinScriptEngineFactoryregistered to handle the given extension usingDefaultGremlinScriptEngineManager.registerEngineExtension(String, GremlinScriptEngineFactory).- Specified by:
getEngineByExtensionin interfaceGremlinScriptEngineManager- Overrides:
getEngineByExtensionin classDefaultGremlinScriptEngineManager- Returns:
- The engine to handle scripts with this extension. Returns
nullif not found.
-
getEngineByMimeType
Gets aGremlinScriptEnginefrom cache or creates a new one from theGremlinScriptEngineFactory. Look up and create aGremlinScriptEnginefor a given mime type. The algorithm used byDefaultGremlinScriptEngineManager.getEngineByName(String)is used except that the search starts by looking for aGremlinScriptEngineFactoryregistered to handle the given mime type usingDefaultGremlinScriptEngineManager.registerEngineMimeType(String, GremlinScriptEngineFactory).- Specified by:
getEngineByMimeTypein interfaceGremlinScriptEngineManager- Overrides:
getEngineByMimeTypein classDefaultGremlinScriptEngineManager- Parameters:
mimeType- The given mime type- Returns:
- The engine to handle scripts with this mime type. Returns
nullif not found.
-