Class InterpreterEngineImpl
- All Implemented Interfaces:
IQueryBackendHintProvider,IQueryCacheContext,IQueryResultProviderAccess
-
Constructor Summary
ConstructorsConstructorDescriptionInterpreterEngineImpl(QueryScope scope) InterpreterEngineImpl(QueryScope scope, InterpreterEngineOptions engineOptions) -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd an engine lifecycle listener to this engine instance.<Match extends IPatternMatch>
voidaddMatchUpdateListener(InterpreterMatcher<Match> matcher, IMatchUpdateListener<? super Match> listener, boolean fireNow) Registers low-level callbacks for match appearance and disappearance on this pattern matcher.voidAdd an model update event listener to this engine instance (that fires its callbacks according to its notification level).<V> VdelayUpdatePropagation(Callable<V> callable) The given callable will be executed, and all update propagation in stateful query backends will be delayed until the execution is done.voiddispose()Completely disconnects and dismantles the engine.voidProvides access to the internal base index component of the engine, responsible for keeping track of basic contents of the model.getCachingResultProvider(PQuery query) Returns a caching result provider for the given query; it must be constructed if it does not exist yet.Set<? extends InterpreterMatcher<? extends IPatternMatch>> Access a copy of availableInterpreterMatcherpattern matchers.Returns the immutableInterpreterEngineOptionsof the engine.<Matcher extends InterpreterMatcher<? extends IPatternMatch>>
MatchergetExistingMatcher(IQuerySpecification<Matcher> querySpecification) Access an existing pattern matcher based on aIQuerySpecification.<Matcher extends InterpreterMatcher<? extends IPatternMatch>>
MatchergetExistingMatcher(IQuerySpecification<Matcher> querySpecification, QueryEvaluationHint optionalOverrideHints) Access an existing pattern matcher based on aIQuerySpecification, and optional hints override.final org.apache.log4j.LoggerInterpreterMatcher<? extends IPatternMatch> getMatcher(String patternFQN) Access a pattern matcher for the graph pattern with the given fully qualified name.<Matcher extends InterpreterMatcher<? extends IPatternMatch>>
MatchergetMatcher(IQuerySpecification<Matcher> querySpecification) Access a pattern matcher based on aIQuerySpecification.<Matcher extends InterpreterMatcher<? extends IPatternMatch>>
MatchergetMatcher(IQuerySpecification<Matcher> querySpecification, QueryEvaluationHint optionalEvaluationHints) Access a pattern matcher based on aIQuerySpecification, overriding some of the default query evaluation hints.getQueryBackend(IQueryBackendFactory iQueryBackendFactory) Provides access to the selected query backend component of the Refinery Interpreter engine.getQueryEvaluationHint(PQuery query) Suggests query evaluation hints regarding a query.getResultProvider(IQuerySpecification<?> query) Returns an internal interface towards the query backend to feed the matcher with results.getResultProvider(IQuerySpecification<?> query, QueryEvaluationHint hint) Returns an internal interface towards the query backend to feed the matcher with results.getResultProvider(PQuery query, QueryEvaluationHint overrideHints) Get a result provider for the givenPQuery, which conforms the capabilities requested by the givenQueryEvaluationHintobject.getResultProviderOfMatcher(InterpreterMatcher<? extends IPatternMatch> matcher) Return the underlying result provider for the given matcher.getScope()booleanReturns true if theAdvancedInterpreterEngine.dispose()method was called on this engine previously.booleanisResultCached(PQuery query) Checks if there already is a caching result provider for the given query.booleanIndicates whether the engine is in a tainted, inconsistent state due to some internal errors.booleanReturns true if the update propagation in this engine is currently delayed, false otherwise.voidprepareGroup(IQueryGroup queryGroup, QueryEvaluationHint optionalEvaluationHints) Initializes matchers for a group of patterns as one step (optionally overriding some of the default query evaluation hints).voidRemove an existing lifecycle listener from this engine instance.<Match extends IPatternMatch>
voidremoveMatchUpdateListener(InterpreterMatcher<Match> matcher, IMatchUpdateListener<? super Match> listener) Remove an existing match update event listener to this engine instance.voidRemove an existing model update event listener to this engine instance.voidwipe()Discards any pattern matcher caches and forgets known patterns.<T> TwithFlushingChanges(Supplier<T> callback) Methods inherited from class tools.refinery.interpreter.api.AdvancedInterpreterEngine
createUnmanagedEngine, createUnmanagedEngine, fromMethods inherited from class tools.refinery.interpreter.api.InterpreterEngine
getRegisteredQuerySpecifications
-
Constructor Details
-
InterpreterEngineImpl
- Parameters:
scope-engineDefaultHint-- Since:
- 1.4
-
InterpreterEngineImpl
- Parameters:
scope-manager- null if unmanagedengineDefaultHint-
-
-
Method Details
-
isUpdatePropagationDelayed
public boolean isUpdatePropagationDelayed()Description copied from class:AdvancedInterpreterEngineReturns true if the update propagation in this engine is currently delayed, false otherwise.- Specified by:
isUpdatePropagationDelayedin classAdvancedInterpreterEngine
-
delayUpdatePropagation
Description copied from class:AdvancedInterpreterEngineThe given callable will be executed, and all update propagation in stateful query backends will be delayed until the execution is done. Within the callback, these backends will provide stale results.It is optional for a
IQueryBackendto support the delaying of update propagation; stateless backends will display up-to-date results. In this case, the given callable shall be executed, and the update propagation shall happen just like in non-delayed execution.Example: in the Rete network, no messages will be propagated until the given callable is executed. After the execution of the callable, all accumulated messages will be delivered.
The purpose of this method is that stateful query backends may save work when multiple model modifications are performed within the callback that partially cancel each other out.
- Specified by:
delayUpdatePropagationin classAdvancedInterpreterEngine- Parameters:
callable- the callable to be executed- Returns:
- the result of the callable
- Throws:
InvocationTargetException
-
flushChanges
public void flushChanges()- Specified by:
flushChangesin classInterpreterEngine
-
withFlushingChanges
- Specified by:
withFlushingChangesin classInterpreterEngine
-
getCurrentMatchers
Description copied from class:InterpreterEngineAccess a copy of availableInterpreterMatcherpattern matchers.- Specified by:
getCurrentMatchersin classInterpreterEngine- Returns:
- a copy of the set of currently available pattern matchers registered on this engine instance
-
getMatcher
public <Matcher extends InterpreterMatcher<? extends IPatternMatch>> Matcher getMatcher(IQuerySpecification<Matcher> querySpecification) Description copied from class:InterpreterEngineAccess a pattern matcher based on aIQuerySpecification. Multiple calls will return the same matcher.- Specified by:
getMatcherin classInterpreterEngine- Parameters:
querySpecification- aIQuerySpecificationthat describes a Refinery Interpreter query specification- Returns:
- a pattern matcher corresponding to the specification
-
getMatcher
public <Matcher extends InterpreterMatcher<? extends IPatternMatch>> Matcher getMatcher(IQuerySpecification<Matcher> querySpecification, QueryEvaluationHint optionalEvaluationHints) Description copied from class:AdvancedInterpreterEngineAccess a pattern matcher based on aIQuerySpecification, overriding some of the default query evaluation hints. Multiple calls may return the same matcher depending on the actual evaluation hints.It is guaranteed that this method will always return a matcher instance which is functionally compatible with the requested functionality (see
IMatcherCapability). Otherwise, the query evaluator is free to ignore any hints.For stateful query backends (Rete), hints may be effective only the first time a matcher is created.
- Specified by:
getMatcherin classAdvancedInterpreterEngine- Parameters:
querySpecification- aIQuerySpecificationthat describes a Refinery Interpreter queryoptionalEvaluationHints- additional / overriding options on query evaluation; passing null means default options associated with the query- Returns:
- a pattern matcher corresponding to the specification
-
getExistingMatcher
public <Matcher extends InterpreterMatcher<? extends IPatternMatch>> Matcher getExistingMatcher(IQuerySpecification<Matcher> querySpecification) Description copied from class:InterpreterEngineAccess an existing pattern matcher based on aIQuerySpecification.- Specified by:
getExistingMatcherin classInterpreterEngine- Parameters:
querySpecification- aIQuerySpecificationthat describes a Refinery Interpreter query specification- Returns:
- a pattern matcher corresponding to the specification,
nullif a matcher does not exist yet.
-
getExistingMatcher
public <Matcher extends InterpreterMatcher<? extends IPatternMatch>> Matcher getExistingMatcher(IQuerySpecification<Matcher> querySpecification, QueryEvaluationHint optionalOverrideHints) Description copied from class:AdvancedInterpreterEngineAccess an existing pattern matcher based on aIQuerySpecification, and optional hints override.- Specified by:
getExistingMatcherin classAdvancedInterpreterEngine- Parameters:
querySpecification- aIQuerySpecificationthat describes a Refinery Interpreter query specificationoptionalOverrideHints- aQueryEvaluationHintthat may override the pattern hints (can be null)- Returns:
- a pattern matcher corresponding to the specification,
nullif a matcher does not exist yet.
-
getMatcher
Description copied from class:InterpreterEngineAccess a pattern matcher for the graph pattern with the given fully qualified name. Will succeed only if a query specification for this fully qualified name has been generated and registered. Multiple calls will return the same matcher unless the registered specification changes.- Specified by:
getMatcherin classInterpreterEngine- Parameters:
patternFQN- the fully qualified name of a Refinery Interpreter query specification- Returns:
- a pattern matcher corresponding to the specification
-
getBaseIndex
Description copied from class:InterpreterEngineProvides access to the internal base index component of the engine, responsible for keeping track of basic contents of the model.If using an
, considerinvalid reference
EMFScopeinstead to access EMF-specific details.invalid reference
EMFScope#extractUnderlyingEMFIndex(InterpreterEngine)- Specified by:
getBaseIndexin classInterpreterEngine- Returns:
- the baseIndex the NavigationHelper maintaining the base index
-
getLogger
public final org.apache.log4j.Logger getLogger() -
getQueryBackend
Provides access to the selected query backend component of the Refinery Interpreter engine.- Specified by:
getQueryBackendin classAdvancedInterpreterEngine
-
dispose
public void dispose()Description copied from class:AdvancedInterpreterEngineCompletely disconnects and dismantles the engine. Cannot be reversed.Matcher objects will continue to return stale results. If no references are retained to the matchers or the engine, they can eventually be GC'ed, and they won't block the EMF model from being GC'ed anymore.
The base indexer (see
InterpreterEngine.getBaseIndex()) built on the model will be disposed alongside the engine, unless the user has manually added listeners on the base index that were not removed yet.Disallowed if the engine is managed (see
), as there may be other clients using it.invalid reference
#isManaged()If you explicitly share a private, unmanaged engine between multiple sites, register a callback using
AdvancedInterpreterEngine.addLifecycleListener(InterpreterEngineLifecycleListener)to learn when another client has called this destructive method.- Specified by:
disposein classAdvancedInterpreterEngine
-
wipe
public void wipe()Description copied from class:AdvancedInterpreterEngineDiscards any pattern matcher caches and forgets known patterns. The base index built directly on the underlying EMF model, however, is kept in memory to allow reuse when new pattern matchers are built. Use this method if you have e.g. new versions of the same patterns, to be matched on the same model.Matcher objects will continue to return stale results. If no references are retained to the matchers, they can eventually be GC'ed.
Disallowed if the engine is managed (see
), as there may be other clients using it.invalid reference
#isManaged()If you explicitly share a private, unmanaged engine between multiple sites, register a callback using
AdvancedInterpreterEngine.addLifecycleListener(InterpreterEngineLifecycleListener)to learn when another client has called this destructive method.- Specified by:
wipein classAdvancedInterpreterEngine
-
isTainted
public boolean isTainted()Description copied from class:AdvancedInterpreterEngineIndicates whether the engine is in a tainted, inconsistent state due to some internal errors. If true, results are no longer reliable; engine should be disposed.The engine is in a tainted state if any of its internal processes report back a fatal error. The
InterpreterEngineLifecycleListenerinterface provides a callback method for entering the tainted state.- Specified by:
isTaintedin classAdvancedInterpreterEngine- Returns:
- the tainted state
-
addMatchUpdateListener
public <Match extends IPatternMatch> void addMatchUpdateListener(InterpreterMatcher<Match> matcher, IMatchUpdateListener<? super Match> listener, boolean fireNow) Description copied from class:AdvancedInterpreterEngineRegisters low-level callbacks for match appearance and disappearance on this pattern matcher.Caution: This is a low-level callback that is invoked when the pattern matcher is not necessarily in a consistent state yet. Importantly, no model modification permitted during the callback.
Performance note: expected to be much more efficient than polling at
, but prone to "signal hazards", e.g. spurious match appearances that will disappear immediately afterwards.invalid reference
#addCallbackAfterUpdates(Runnable)The callback can be unregistered via
.invalid reference
#removeCallbackOnMatchUpdate(IMatchUpdateListener)- Specified by:
addMatchUpdateListenerin classAdvancedInterpreterEngine- Parameters:
matcher- theInterpreterMatcherfor which this listener should be activelistener- the listener that will be notified of each new match that appears or disappears, starting from now.fireNow- if true, appearCallback will be immediately invoked on all current matches as a one-time effect. See alsoInterpreterMatcher.forEachMatch(IMatchProcessor).
-
removeMatchUpdateListener
public <Match extends IPatternMatch> void removeMatchUpdateListener(InterpreterMatcher<Match> matcher, IMatchUpdateListener<? super Match> listener) Description copied from class:AdvancedInterpreterEngineRemove an existing match update event listener to this engine instance.- Specified by:
removeMatchUpdateListenerin classAdvancedInterpreterEngine- Parameters:
matcher- theInterpreterMatcherfor which this listener should not be active anymorelistener- theIMatchUpdateListenerthat should not receive the callbacks anymore
-
addModelUpdateListener
Description copied from class:AdvancedInterpreterEngineAdd an model update event listener to this engine instance (that fires its callbacks according to its notification level).- Specified by:
addModelUpdateListenerin classAdvancedInterpreterEngine- Parameters:
listener- theInterpreterModelUpdateListenerthat should listen to model update events from this engine.
-
removeModelUpdateListener
Description copied from class:AdvancedInterpreterEngineRemove an existing model update event listener to this engine instance.- Specified by:
removeModelUpdateListenerin classAdvancedInterpreterEngine- Parameters:
listener- theInterpreterModelUpdateListenerthat should not listen to model update events from this engine anymore
-
addLifecycleListener
Description copied from class:AdvancedInterpreterEngineAdd an engine lifecycle listener to this engine instance.- Specified by:
addLifecycleListenerin classAdvancedInterpreterEngine- Parameters:
listener- theInterpreterEngineLifecycleListenerthat should listen to lifecycle events from this engine
-
removeLifecycleListener
Description copied from class:AdvancedInterpreterEngineRemove an existing lifecycle listener from this engine instance.- Specified by:
removeLifecycleListenerin classAdvancedInterpreterEngine- Parameters:
listener- theInterpreterEngineLifecycleListenerthat should not listen to lifecycle events from this engine anymore
-
getResultProvider
Returns an internal interface towards the query backend to feed the matcher with results.- Parameters:
query- the pattern for which the result provider should be delivered- Throws:
InterpreterRuntimeException
-
getResultProvider
public IQueryResultProvider getResultProvider(IQuerySpecification<?> query, QueryEvaluationHint hint) Returns an internal interface towards the query backend to feed the matcher with results.- Parameters:
query- the pattern for which the result provider should be delivered- Throws:
InterpreterRuntimeException
-
isResultCached
Description copied from interface:IQueryCacheContextChecks if there already is a caching result provider for the given query.Returns false if called while the caching result provider of the given query is being constructed in the first place.
- Specified by:
isResultCachedin interfaceIQueryCacheContext
-
getCachingResultProvider
Description copied from interface:IQueryCacheContextReturns a caching result provider for the given query; it must be constructed if it does not exist yet.Caution: behavior undefined if called while the caching result provider of the given query is being constructed. Beware of infinite loops.
Postcondition:
IQueryBackend.isCaching()returns true for theof the returned providerinvalid reference
#getQueryBackend()- Specified by:
getCachingResultProviderin interfaceIQueryCacheContext
-
getQueryEvaluationHint
Description copied from interface:IQueryBackendHintProviderSuggests query evaluation hints regarding a query. The returned hints reflects the default hints of the query engine merged with the hints provided by the pattern itself. These can be overridden via specific advanced API of the engine.- Specified by:
getQueryEvaluationHintin interfaceIQueryBackendHintProvider
-
prepareGroup
Description copied from class:AdvancedInterpreterEngineInitializes matchers for a group of patterns as one step (optionally overriding some of the default query evaluation hints). If some of the pattern matchers are already constructed in the engine, no task is performed for them.This preparation step has the advantage that it prepares pattern matchers for an arbitrary number of patterns in a single-pass traversal of the model. This is typically more efficient than traversing the model each time an individual pattern matcher is initialized on demand. The performance benefit only manifests itself if the engine is not in wildcard mode.
- Specified by:
prepareGroupin classAdvancedInterpreterEngine- Parameters:
queryGroup- aIQueryGroupidentifying a set of Refinery interpreter queriesoptionalEvaluationHints- additional / overriding options on query evaluation; passing null means default options associated with each query
-
getScope
- Specified by:
getScopein classInterpreterEngine- Returns:
- the scope of query evaluation; the definition of the set of model elements that this engine is operates on.
-
getEngineOptions
Description copied from class:AdvancedInterpreterEngineReturns the immutableInterpreterEngineOptionsof the engine.- Specified by:
getEngineOptionsin classAdvancedInterpreterEngine- Returns:
- the engine options
-
getResultProviderOfMatcher
public IQueryResultProvider getResultProviderOfMatcher(InterpreterMatcher<? extends IPatternMatch> matcher) Description copied from class:AdvancedInterpreterEngineReturn the underlying result provider for the given matcher.- Specified by:
getResultProviderOfMatcherin classAdvancedInterpreterEngine
-
getResultProvider
Description copied from interface:IQueryResultProviderAccessGet a result provider for the givenPQuery, which conforms the capabilities requested by the givenQueryEvaluationHintobject.- Specified by:
getResultProviderin interfaceIQueryResultProviderAccess
-
isDisposed
public boolean isDisposed()Description copied from class:AdvancedInterpreterEngineReturns true if theAdvancedInterpreterEngine.dispose()method was called on this engine previously.- Specified by:
isDisposedin classAdvancedInterpreterEngine
-