org.eclipse.viatra.query.runtime.api

## Class ViatraQueryEngineManager

- java.lang.Object
- - org.eclipse.viatra.query.runtime.api.ViatraQueryEngineManager

-     public class ViatraQueryEngineManager
      extends java.lang.Object

  Global registry of active VIATRA Query Engines.

  Manages an `ViatraQueryEngine` for each model (more precisely scope), that is created on demand. Managed engines are shared between clients querying the same model.

  It is also possible to create private, unmanaged engines that are not shared between clients.

  Only weak references are retained on the managed engines. So if there are no other references to the matchers or the engine, they can eventually be GC'ed, and they won't block the model from being GC'ed either.

- - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addQueryEngineInitializationListener(ViatraQueryEngineInitializationListener listener)` Registers a listener for new engine initialization.
    `java.util.Set<ViatraQueryEngine>` | `getExistingQueryEngines()` Collects all `ViatraQueryEngine` instances that still exist.
    `static ViatraQueryEngineManager` | `getInstance()`
    `ViatraQueryEngine` | `getQueryEngine(QueryScope scope)` Creates a managed VIATRA Query Engine at a given scope (e.g.
    `ViatraQueryEngine` | `getQueryEngine(QueryScope scope, ViatraQueryEngineOptions options)` Creates a managed VIATRA Query Engine at a given scope (e.g.
    `ViatraQueryEngine` | `getQueryEngineIfExists(QueryScope scope)` Retrieves an already existing managed VIATRA Query Engine.
    `protected void` | `notifyInitializationListeners(AdvancedViatraQueryEngine engine)` Notifies listeners that a new engine has been initialized.
    `void` | `removeQueryEngineInitializationListener(ViatraQueryEngineInitializationListener listener)` Removes a registered listener added with `addQueryEngineInitializationListener(org.eclipse.viatra.query.runtime.api.ViatraQueryEngineInitializationListener)`

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

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

- - ### Method Detail

    - #### getInstance

          public static ViatraQueryEngineManager getInstance()

      Returns:
        the singleton instance

    - #### getQueryEngine

          public ViatraQueryEngine getQueryEngine(QueryScope scope)

      Creates a managed VIATRA Query Engine at a given scope (e.g. an EMF Resource or ResourceSet, as in `EMFScope`) or retrieves an already existing one. Repeated invocations for a single model root will return the same engine. Consequently, the engine will be reused between different clients querying the same model, providing performance benefits.

      The match set of any patterns will be incrementally refreshed upon updates from this scope.

      Parameters:
        `scope` - the scope of query evaluation; the definition of the set of model elements that this engine is operates on. Provide e.g. a `EMFScope` for evaluating queries on an EMF model.
      Returns:
        a new or previously existing engine

    - #### getQueryEngine

          public ViatraQueryEngine getQueryEngine(QueryScope scope,
                                                  ViatraQueryEngineOptions options)

      Creates a managed VIATRA Query Engine at a given scope (e.g. an EMF Resource or ResourceSet, as in `EMFScope`) or retrieves an already existing one. Repeated invocations for a single model root will return the same engine. Consequently, the engine will be reused between different clients querying the same model, providing performance benefits.

      The match set of any patterns will be incrementally refreshed upon updates from this scope.

      Parameters:
        `scope` - the scope of query evaluation; the definition of the set of model elements that this engine is operates on. Provide e.g. a `EMFScope` for evaluating queries on an EMF model.
      Returns:
        a new or previously existing engine
      Since:
        1.4

    - #### getQueryEngineIfExists

          public ViatraQueryEngine getQueryEngineIfExists(QueryScope scope)

      Retrieves an already existing managed VIATRA Query Engine.
      Parameters:
        `scope` - the scope of query evaluation; the definition of the set of model elements that this engine is operates on. Provide e.g. a `EMFScope` for evaluating queries on an EMF model.
      Returns:
        a previously existing engine, or null if no engine is active for the given EMF model root

    - #### getExistingQueryEngines

          public java.util.Set<ViatraQueryEngine> getExistingQueryEngines()

      Collects all `ViatraQueryEngine` instances that still exist.
      Returns:
        set of engines if there is any, otherwise EMTPY_SET

    - #### addQueryEngineInitializationListener

          public void addQueryEngineInitializationListener(ViatraQueryEngineInitializationListener listener)

      Registers a listener for new engine initialization.

      For removal, use `removeQueryEngineInitializationListener(org.eclipse.viatra.query.runtime.api.ViatraQueryEngineInitializationListener)`
      Parameters:
        `listener` - the listener to register

    - #### removeQueryEngineInitializationListener

          public void removeQueryEngineInitializationListener(ViatraQueryEngineInitializationListener listener)

      Removes a registered listener added with `addQueryEngineInitializationListener(org.eclipse.viatra.query.runtime.api.ViatraQueryEngineInitializationListener)`
      Parameters:
        `listener` -

    - #### notifyInitializationListeners

          protected void notifyInitializationListeners(AdvancedViatraQueryEngine engine)

      Notifies listeners that a new engine has been initialized.
      Parameters:
        `engine` - the initialized engine