Class CachedGremlinScriptEngineManager
- java.lang.Object
-
- org.apache.tinkerpop.gremlin.jsr223.DefaultGremlinScriptEngineManager
-
- org.apache.tinkerpop.gremlin.jsr223.CachedGremlinScriptEngineManager
-
- All Implemented Interfaces:
GremlinScriptEngineManager
public class CachedGremlinScriptEngineManager extends DefaultGremlinScriptEngineManager
An implementation of theGremlinScriptEngineManager
that caches the instances of theGremlinScriptEngine
instances that are created by it. Note that the cache is relevant to the instance of theCachedGremlinScriptEngineManager
and is not global to the JVM. TheScriptEngineManager
implements a discovery, instantiation and configuration mechanism forGremlinScriptEngine
classes and also maintains a collection of key/value pairs storing state shared by all engines created by it. This class uses theServiceProvider
mechanism to enumerate all the implementations ofGremlinScriptEngineFactory
. TheScriptEngineManager
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. TheBindings
of key/value pairs, referred to as the "Global Scope" maintained by the manager is available to all instances of @code ScriptEngine} created by theGremlinScriptEngineManager
. The values in theBindings
are generally exposed in all scripts. This class is based quite heavily on the workings of theScriptEngineManager
supplied in thejavax.script
packages, but adds some additional features that are specific to Gremlin and TinkerPop. Unfortunately, it's not easily possible to extendScriptEngineManager
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 class is designed to provide support for "Gremlin-enabled"ScriptEngine
instances (i.e. those that extend fromGremlinScriptEngine
) and is not meant to manage just anyScriptEngine
instance that may be on the path. As this is a "Gremlin"ScriptEngine
, certain common imports are automatically applied when aGremlinScriptEngine
is instantiated via theGremlinScriptEngineFactory
.. Initial imports from gremlin-core come from theCoreImports
.
-
-
Constructor Summary
Constructors Constructor Description CachedGremlinScriptEngineManager()
CachedGremlinScriptEngineManager(ClassLoader loader)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description GremlinScriptEngine
getEngineByExtension(String extension)
Gets aGremlinScriptEngine
from cache or creates a new one from theGremlinScriptEngineFactory
.GremlinScriptEngine
getEngineByMimeType(String mimeType)
Gets aGremlinScriptEngine
from cache or creates a new one from theGremlinScriptEngineFactory
.GremlinScriptEngine
getEngineByName(String shortName)
Gets aGremlinScriptEngine
from 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 Detail
-
CachedGremlinScriptEngineManager
public CachedGremlinScriptEngineManager()
- See Also:
DefaultGremlinScriptEngineManager()
-
CachedGremlinScriptEngineManager
public CachedGremlinScriptEngineManager(ClassLoader loader)
-
-
Method Detail
-
getEngineByName
public GremlinScriptEngine getEngineByName(String shortName)
Gets aGremlinScriptEngine
from cache or creates a new one from theGremlinScriptEngineFactory
. Looks up and creates aGremlinScriptEngine
for a given name. The algorithm first searches for aGremlinScriptEngineFactory
that 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 ofGremlinScriptEngineFactory
instances stored by the constructor for one with the specified name. If aScriptEngineFactory
is found by either method, it is used to create instance ofGremlinScriptEngine
.- Specified by:
getEngineByName
in interfaceGremlinScriptEngineManager
- Overrides:
getEngineByName
in classDefaultGremlinScriptEngineManager
- Parameters:
shortName
- The short name of theGremlinScriptEngine
implementation returned by theScriptEngineFactory.getNames()
method.- Returns:
- A
GremlinScriptEngine
created by the factory located in the search. Returnsnull
if no such factory was found. The global scope of this manager is applied to the newly createdGremlinScriptEngine
-
getEngineByExtension
public GremlinScriptEngine getEngineByExtension(String extension)
Gets aGremlinScriptEngine
from cache or creates a new one from theGremlinScriptEngineFactory
. Look up and create aGremlinScriptEngine
for a given extension. The algorithm used byDefaultGremlinScriptEngineManager.getEngineByName(String)
is used except that the search starts by looking for aGremlinScriptEngineFactory
registered to handle the given extension usingDefaultGremlinScriptEngineManager.registerEngineExtension(String, GremlinScriptEngineFactory)
.- Specified by:
getEngineByExtension
in interfaceGremlinScriptEngineManager
- Overrides:
getEngineByExtension
in classDefaultGremlinScriptEngineManager
- Returns:
- The engine to handle scripts with this extension. Returns
null
if not found.
-
getEngineByMimeType
public GremlinScriptEngine getEngineByMimeType(String mimeType)
Gets aGremlinScriptEngine
from cache or creates a new one from theGremlinScriptEngineFactory
. Look up and create aGremlinScriptEngine
for a given mime type. The algorithm used byDefaultGremlinScriptEngineManager.getEngineByName(String)
is used except that the search starts by looking for aGremlinScriptEngineFactory
registered to handle the given mime type usingDefaultGremlinScriptEngineManager.registerEngineMimeType(String, GremlinScriptEngineFactory)
.- Specified by:
getEngineByMimeType
in interfaceGremlinScriptEngineManager
- Overrides:
getEngineByMimeType
in classDefaultGremlinScriptEngineManager
- Parameters:
mimeType
- The given mime type- Returns:
- The engine to handle scripts with this mime type. Returns
null
if not found.
-
-