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 theGremlinScriptEngineManagerthat caches the instances of theGremlinScriptEngineinstances that are created by it. Note that the cache is relevant to the instance of theCachedGremlinScriptEngineManagerand is not global to the JVM. TheScriptEngineManagerimplements a discovery, instantiation and configuration mechanism forGremlinScriptEngineclasses and also maintains a collection of key/value pairs storing state shared by all engines created by it. This class uses theServiceProvidermechanism to enumerate all the implementations ofGremlinScriptEngineFactory. TheScriptEngineManagerprovides 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. TheBindingsof 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 theBindingsare generally exposed in all scripts. This class is based quite heavily on the workings of theScriptEngineManagersupplied in thejavax.scriptpackages, but adds some additional features that are specific to Gremlin and TinkerPop. Unfortunately, it's not easily possible to extendScriptEngineManagerdirectly 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"ScriptEngineinstances (i.e. those that extend fromGremlinScriptEngine) and is not meant to manage just anyScriptEngineinstance that may be on the path. As this is a "Gremlin"ScriptEngine, certain common imports are automatically applied when aGremlinScriptEngineis 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 GremlinScriptEnginegetEngineByExtension(String extension)Gets aGremlinScriptEnginefrom cache or creates a new one from theGremlinScriptEngineFactory.GremlinScriptEnginegetEngineByMimeType(String mimeType)Gets aGremlinScriptEnginefrom cache or creates a new one from theGremlinScriptEngineFactory.GremlinScriptEnginegetEngineByName(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 Detail
-
CachedGremlinScriptEngineManager
public CachedGremlinScriptEngineManager()
- See Also:
DefaultGremlinScriptEngineManager()
-
CachedGremlinScriptEngineManager
public CachedGremlinScriptEngineManager(ClassLoader loader)
-
-
Method Detail
-
getEngineByName
public GremlinScriptEngine getEngineByName(String shortName)
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
public GremlinScriptEngine getEngineByExtension(String extension)
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
public GremlinScriptEngine getEngineByMimeType(String mimeType)
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.
-
-