Class ReteEngine
- java.lang.Object
-
- org.eclipse.viatra.query.runtime.rete.matcher.ReteEngine
-
- All Implemented Interfaces:
IQueryBackend
public class ReteEngine extends java.lang.Object implements IQueryBackend
-
-
Field Summary
Fields Modifier and Type Field Description protected ReteBoundaryboundaryprotected ReteRecipeCompilercompilerprotected booleandeleteAndRederiveEvaluationprotected java.util.Collection<Disconnectable>disconnectablesprotected java.util.Map<PQuery,RetePatternMatcher>matchersprotected booleanparallelExecutionEnabledprotected NetworkreteNetprotected intreteThreadsprotected IQueryRuntimeContextruntimeContextprotected TimelyConfigurationtimelyConfiguration
-
Constructor Summary
Constructors Constructor Description ReteEngine(IQueryBackendContext context, int reteThreads)ReteEngine(IQueryBackendContext context, int reteThreads, boolean deleteAndRederiveEvaluation, TimelyConfiguration timelyConfiguration)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RetePatternMatcheraccessMatcher(PQuery query)Accesses the patternmatcher for a given pattern, constructs one if a matcher is not available yet.voidaddDisconnectable(Disconnectable disc)voidbuildMatchersCoalesced(java.util.Collection<PQuery> specifications)Constructs RETE pattern matchers for a collection of patterns, if they are not available yet.<T> TconstructionWrapper(java.util.concurrent.Callable<T> payload)voiddispose()Disposes the query backend.voidexecuteDelayedCommands()voidflushUpdates()Propagates all pending updates in this query backend.IQueryBackendContextgetBackendContext()ReteBoundarygetBoundary()ReteRecipeCompilergetCompiler()IQueryBackendFactorygetFactory()IQueryBackendHintProvidergetHintConfiguration()org.apache.log4j.LoggergetLogger()IQueryResultProvidergetResultProvider(PQuery query)Returns a result provider for a given query.IQueryResultProvidergetResultProvider(PQuery query, QueryEvaluationHint hints)Returns a result provider for a given query.NetworkgetReteNet()IQueryRuntimeContextgetRuntimeContext()TimelyConfigurationgetTimelyConfiguration()booleanisCaching()booleanisDeleteAndRederiveEvaluation()booleanisDisposedOrUninitialized()booleanisParallelExecutionEnabled()voidkillEngine()Deconstructs the engine to get rid of it finallyIQueryResultProviderpeekExistingResultProvider(PQuery query)Returns an existing result provider for a given query, if it was previously constructed, returns null otherwise.voidreset()Resets the engine to an after-initialization phasevoidsetCompiler(ReteRecipeCompiler builder)voidsettle()Waits until the pattern matcher is in a steady state and output can be retrieved.voidsettle(java.lang.Runnable action)Waits until the pattern matcher is in a steady state and output can be retrieved.
-
-
-
Field Detail
-
reteNet
protected Network reteNet
-
reteThreads
protected final int reteThreads
-
boundary
protected ReteBoundary boundary
-
deleteAndRederiveEvaluation
protected final boolean deleteAndRederiveEvaluation
- Since:
- 2.2
-
timelyConfiguration
protected final TimelyConfiguration timelyConfiguration
- Since:
- 2.4
-
runtimeContext
protected IQueryRuntimeContext runtimeContext
-
disconnectables
protected java.util.Collection<Disconnectable> disconnectables
-
matchers
protected java.util.Map<PQuery,RetePatternMatcher> matchers
-
compiler
protected ReteRecipeCompiler compiler
-
parallelExecutionEnabled
protected final boolean parallelExecutionEnabled
-
-
Constructor Detail
-
ReteEngine
public ReteEngine(IQueryBackendContext context, int reteThreads)
- Parameters:
context- the context of the pattern matcher, conveying all information from the outside world.reteThreads- the number of threads to operate the RETE network with; 0 means single-threaded operation, 1 starts an asynchronous thread to operate the RETE net, >1 uses multiple RETE containers.
-
ReteEngine
public ReteEngine(IQueryBackendContext context, int reteThreads, boolean deleteAndRederiveEvaluation, TimelyConfiguration timelyConfiguration)
- Since:
- 2.4
-
-
Method Detail
-
getBackendContext
public IQueryBackendContext getBackendContext()
- Since:
- 1.6
-
isDeleteAndRederiveEvaluation
public boolean isDeleteAndRederiveEvaluation()
- Since:
- 2.2
-
getTimelyConfiguration
public TimelyConfiguration getTimelyConfiguration()
- Since:
- 2.4
-
flushUpdates
public void flushUpdates()
Description copied from interface:IQueryBackendPropagates all pending updates in this query backend. The implementation of this method is optional, and it can be ignored entirely if the backend does not delay updates.- Specified by:
flushUpdatesin interfaceIQueryBackend
-
killEngine
public void killEngine()
Deconstructs the engine to get rid of it finally
-
reset
public void reset()
Resets the engine to an after-initialization phase
-
accessMatcher
public RetePatternMatcher accessMatcher(PQuery query)
Accesses the patternmatcher for a given pattern, constructs one if a matcher is not available yet.- Parameters:
query- the pattern to be matched.- Returns:
- a patternmatcher object that can match occurences of the given pattern.
- Throws:
ViatraQueryRuntimeException- if construction fails.
-
buildMatchersCoalesced
public void buildMatchersCoalesced(java.util.Collection<PQuery> specifications)
Constructs RETE pattern matchers for a collection of patterns, if they are not available yet. Model traversal during the whole construction period is coalesced (which may have an effect on performance, depending on the matcher context).- Parameters:
specifications- the patterns to be matched.- Throws:
ViatraQueryRuntimeException- if construction fails.
-
constructionWrapper
public <T> T constructionWrapper(java.util.concurrent.Callable<T> payload)
- Since:
- 2.4
-
executeDelayedCommands
public void executeDelayedCommands()
- Since:
- 2.3
-
settle
public void settle()
Waits until the pattern matcher is in a steady state and output can be retrieved.
-
settle
public void settle(java.lang.Runnable action)
Waits until the pattern matcher is in a steady state and output can be retrieved. When steady state is reached, a retrieval action is executed before the steady state ceases.- Parameters:
action- the action to be run when reaching the steady-state.
-
getReteNet
public Network getReteNet()
- Returns:
- the reteNet
-
getBoundary
public ReteBoundary getBoundary()
- Returns:
- the boundary
-
setCompiler
public void setCompiler(ReteRecipeCompiler builder)
- Parameters:
builder- the pattern matcher builder to set
-
addDisconnectable
public void addDisconnectable(Disconnectable disc)
- Parameters:
disc- the new Disconnectable adapter.
-
isParallelExecutionEnabled
public boolean isParallelExecutionEnabled()
- Returns:
- the parallelExecutionEnabled
-
getLogger
public org.apache.log4j.Logger getLogger()
-
getRuntimeContext
public IQueryRuntimeContext getRuntimeContext()
-
getCompiler
public ReteRecipeCompiler getCompiler()
-
isDisposedOrUninitialized
public boolean isDisposedOrUninitialized()
- Since:
- 2.9
-
getResultProvider
public IQueryResultProvider getResultProvider(PQuery query)
Description copied from interface:IQueryBackendReturns a result provider for a given query. Repeated calls may return the same instance.- Specified by:
getResultProviderin interfaceIQueryBackend
-
getResultProvider
public IQueryResultProvider getResultProvider(PQuery query, QueryEvaluationHint hints)
Description copied from interface:IQueryBackendReturns a result provider for a given query. Repeated calls may return the same instance.- Specified by:
getResultProviderin interfaceIQueryBackend- Since:
- 1.4
-
peekExistingResultProvider
public IQueryResultProvider peekExistingResultProvider(PQuery query)
Description copied from interface:IQueryBackendReturns an existing result provider for a given query, if it was previously constructed, returns null otherwise. Will not construct and initialize new result providers.- Specified by:
peekExistingResultProviderin interfaceIQueryBackend
-
dispose
public void dispose()
Description copied from interface:IQueryBackendDisposes the query backend.- Specified by:
disposein interfaceIQueryBackend
-
isCaching
public boolean isCaching()
- Specified by:
isCachingin interfaceIQueryBackend- Returns:
- true iff this backend is incremental, i.e. it caches the results of queries for quick retrieval, and can provide update notifications on result set changes.
-
getHintConfiguration
public IQueryBackendHintProvider getHintConfiguration()
- Since:
- 1.5
- No Reference:
- Internal API, subject to change
-
getFactory
public IQueryBackendFactory getFactory()
- Specified by:
getFactoryin interfaceIQueryBackend- Returns:
- the factory that created this backend, if this functionality is supported
-
-