org.apache.tinkerpop.gremlin.jsr223

## 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 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 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

    Constructors
    Constructor and Description
    `CachedGremlinScriptEngineManager()`
    `CachedGremlinScriptEngineManager(ClassLoader loader)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `GremlinScriptEngine` | `getEngineByExtension(String extension)` Gets a `GremlinScriptEngine` from cache or creates a new one from the `GremlinScriptEngineFactory`.
    `GremlinScriptEngine` | `getEngineByMimeType(String mimeType)` Gets a `GremlinScriptEngine` from cache or creates a new one from the `GremlinScriptEngineFactory`.
    `GremlinScriptEngine` | `getEngineByName(String shortName)` Gets a `GremlinScriptEngine` from cache or creates a new one from the `GremlinScriptEngineFactory`.

    - ### Methods inherited from class org.apache.tinkerpop.gremlin.jsr223.DefaultGremlinScriptEngineManager

      `addPlugin, get, getBindings, getCustomizers, getEngineFactories, put, registerEngineExtension, registerEngineMimeType, registerEngineName, setBindings`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### CachedGremlinScriptEngineManager

          public CachedGremlinScriptEngineManager()

      See Also:
        `DefaultGremlinScriptEngineManager.DefaultGremlinScriptEngineManager()`

    - #### CachedGremlinScriptEngineManager

          public CachedGremlinScriptEngineManager(ClassLoader loader)

      See Also:
        `DefaultGremlinScriptEngineManager.DefaultGremlinScriptEngineManager(ClassLoader loader)`

  - ### Method Detail

    - #### getEngineByName

          public GremlinScriptEngine getEngineByName(String shortName)

      Gets a `GremlinScriptEngine` from cache or creates a new one from the `GremlinScriptEngineFactory`.

      Looks up and creates a `GremlinScriptEngine` for a given name. The algorithm first searches for a `GremlinScriptEngineFactory` that has been registered as a handler for the specified name using the `DefaultGremlinScriptEngineManager.registerEngineExtension(String, GremlinScriptEngineFactory)` method. If one is not found, it searches the set of `GremlinScriptEngineFactory` instances stored by the constructor for one with the specified name. If a `ScriptEngineFactory` is found by either method, it is used to create instance of `GremlinScriptEngine`.
      Specified by:
        `getEngineByName` in interface `GremlinScriptEngineManager`
      Overrides:
        `getEngineByName` in class `DefaultGremlinScriptEngineManager`
      Parameters:
        `shortName` - The short name of the `GremlinScriptEngine` implementation returned by the `ScriptEngineFactory.getNames()` method.
      Returns:
        A `GremlinScriptEngine` created by the factory located in the search. Returns `null` if no such factory was found. The global scope of this manager is applied to the newly created `GremlinScriptEngine`

    - #### getEngineByExtension

          public GremlinScriptEngine getEngineByExtension(String extension)

      Gets a `GremlinScriptEngine` from cache or creates a new one from the `GremlinScriptEngineFactory`.

      Look up and create a `GremlinScriptEngine` for a given extension. The algorithm used by `DefaultGremlinScriptEngineManager.getEngineByName(String)` is used except that the search starts by looking for a `GremlinScriptEngineFactory` registered to handle the given extension using `DefaultGremlinScriptEngineManager.registerEngineExtension(String, GremlinScriptEngineFactory)`.
      Specified by:
        `getEngineByExtension` in interface `GremlinScriptEngineManager`
      Overrides:
        `getEngineByExtension` in class `DefaultGremlinScriptEngineManager`
      Returns:
        The engine to handle scripts with this extension. Returns `null` if not found.

    - #### getEngineByMimeType

          public GremlinScriptEngine getEngineByMimeType(String mimeType)

      Gets a `GremlinScriptEngine` from cache or creates a new one from the `GremlinScriptEngineFactory`.

      Look up and create a `GremlinScriptEngine` for a given mime type. The algorithm used by `DefaultGremlinScriptEngineManager.getEngineByName(String)` is used except that the search starts by looking for a `GremlinScriptEngineFactory` registered to handle the given mime type using `DefaultGremlinScriptEngineManager.registerEngineMimeType(String, GremlinScriptEngineFactory)`.
      Specified by:
        `getEngineByMimeType` in interface `GremlinScriptEngineManager`
      Overrides:
        `getEngineByMimeType` in class `DefaultGremlinScriptEngineManager`
      Parameters:
        `mimeType` - The given mime type
      Returns:
        The engine to handle scripts with this mime type. Returns `null` if not found.

Copyright © 2013–2019 Apache Software Foundation. All rights reserved.