Class AbstractSessionWrapper<S extends RuleSession<S>>
- Type Parameters:
S- the type of theRuleSessiondelegate object
- All Implemented Interfaces:
Environment,EvaluationListeners,EvaluatorsContext,FluentEnvironment<S>,FluentImports<S>,RuleSession<S>,RuleSet<RuntimeRule>,RuleSetContext<S,,RuntimeRule> RuntimeContext<S>
-
Field Summary
FieldsFields inherited from interface org.evrete.api.RuntimeContext
SALIENCE_COMPARATOR -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddEvaluator(Evaluator evaluator, double complexity) Registers new condition evaluator and returns its handle.addEventListener(SessionLifecycleListener listener) Adds a session lifecycle listener to receive session lifecycle events.Adds an import statement using its string representation.voidaddListener(EvaluationListener listener) Adds a listener to be notified of evaluation events.A convenience method that returns an instance ofCollectorfor inserting streams of facts.builder()Returns an instance ofRuleSetBuilderfor building and appending rules to the current context.compile(Collection<LiteralExpression> expressions) A convenience method for compiling literal expressions.configureTypes(Consumer<TypeResolver> action) Configures theTypeResolverby applying the given action.<T> TRetrieves the value of a property by its name.Retrieves the activation manager associated with this session.Class<? extends ActivationManager>Returns the Activation Manager factory class for this RuntimeContext.Retrieves the ClassLoader used by the current context.Retrieves the Configuration object associated with this RuntimeContext.getEvaluator(EvaluatorHandle handle) Returns evaluator by its handle.Retrieves the expression resolver for parsing string expressions.Retrieves the current set of import statements.Retrieves the parent context of this session instance.Retrieves a collection of all property names in the environment.final RuntimeRuleRetrieves a rule based on its name.Retrieves the comparator used for ordering rules.final List<RuntimeRule>getRules()Method returns a list of rules created so far.Returns theKnowledgeServiceinstance.Creates and returns a new instance ofJavaSourceCompiler.Retrieves the TypeResolver instance associated with this RuntimeContext.Inserts a fact in working memory and returns a serializable fact handle.Inserts a fact and explicitly specifies itsTypename.newRule()Deprecated.Deprecated.removeEventListener(SessionLifecycleListener listener) Removes aSessionLifecycleListenerfrom the session.voidremoveListener(EvaluationListener listener) Removes a previously added listener.voidreplaceEvaluator(EvaluatorHandle handle, Evaluator newEvaluator) Replaces existing condition with a new one.voidreplaceEvaluator(EvaluatorHandle handle, ValuesPredicate predicate) Replaces existing condition with a new one.final FieldReference[]resolveFieldReferences(String[] args, NamedType.Resolver typeMapper) protected Sself()Sets the specified property to the given value.setActivationManager(ActivationManager activationManager) Sets the activation manager for the session.<A extends ActivationManager>
voidsetActivationManagerFactory(Class<A> managerClass) Sets the Activation Manager factory class for this RuntimeContext.voidsetActivationManagerFactory(String managerClass) Sets the Activation Manager factory class name for this RuntimeContext.setActivationMode(ActivationMode activationMode) Sets the activation mode for the session.voidsetClassLoader(ClassLoader classLoader) Sets new parent classloader for this context's internal classloader.setExecutionPredicate(BooleanSupplier criteria) Session call's the supplier'sBooleanSupplier.getAsBoolean()method prior to each activation cycle.voidsetRuleComparator(Comparator<Rule> comparator) Sets the comparator used for ordering rules.voidwrapTypeResolver(TypeResolverWrapper wrapper) Deprecated.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.evrete.api.Environment
get, get, getPropertyNamesMethods inherited from interface org.evrete.api.EvaluationListeners
addListener, removeListenerMethods inherited from interface org.evrete.api.EvaluatorsContext
addEvaluator, addEvaluator, getEvaluator, replaceEvaluator, replaceEvaluatorMethods inherited from interface org.evrete.api.FluentEnvironment
setMethods inherited from interface org.evrete.api.FluentImports
addImport, addImport, getImports, getJavaImportsMethods inherited from interface org.evrete.api.RuleSession
fire, insert, insert, insert, insertAs, insertAs, insertAsMethods inherited from interface org.evrete.api.RuleSet
getRule, getRule, getRules, resolveFieldReferences, ruleExists, setRuleBuilderExceptionHandlerMethods inherited from interface org.evrete.api.RuntimeContext
builder, compile, compile, configureTypes, getActivationManagerFactory, getClassLoader, getConfiguration, getExpressionResolver, getRuleComparator, getService, getSourceCompiler, getTypeResolver, newRule, newRule, setActivationManagerFactory, setActivationManagerFactory, setActivationMode, setClassLoader, setRuleComparator, wrapTypeResolver
-
Field Details
-
delegate
-
-
Constructor Details
-
AbstractSessionWrapper
-
-
Method Details
-
getActivationManager
Description copied from interface:RuleSessionRetrieves the activation manager associated with this session.- Specified by:
getActivationManagerin interfaceRuleSession<S extends RuleSession<S>>- Returns:
- the activation manager for this session
-
asCollector
Description copied from interface:RuleSessionA convenience method that returns an instance of
Collectorfor inserting streams of facts.- Specified by:
asCollectorin interfaceRuleSession<S extends RuleSession<S>>- Type Parameters:
T- the type of input elements to the reduction operation- Returns:
- collector
-
setActivationManager
Description copied from interface:RuleSessionSets the activation manager for the session.- Specified by:
setActivationManagerin interfaceRuleSession<S extends RuleSession<S>>- Parameters:
activationManager- the activation manager to set- Returns:
- the current session instance
-
setExecutionPredicate
Description copied from interface:RuleSessionSession call's the supplier's
BooleanSupplier.getAsBoolean()method prior to each activation cycle. If the provided value isfalsethen the cycle gets interrupted and session exits its fire(...) method.Along with the
ActivationManager, this method can be used to debug rules, to avoid infinite activation loops, or to prevent excessive consumption of computer resources.- Specified by:
setExecutionPredicatein interfaceRuleSession<S extends RuleSession<S>>- Parameters:
criteria- - boolean value supplier- Returns:
- this session
-
addEventListener
Description copied from interface:RuleSessionAdds a session lifecycle listener to receive session lifecycle events.- Specified by:
addEventListenerin interfaceRuleSession<S extends RuleSession<S>>- Parameters:
listener- the session lifecycle listener to add- Returns:
- the current instance of the session
-
removeEventListener
Description copied from interface:RuleSessionRemoves aSessionLifecycleListenerfrom the session.- Specified by:
removeEventListenerin interfaceRuleSession<S extends RuleSession<S>>- Parameters:
listener- theSessionLifecycleListenerto be removed- Returns:
- the current instance of the session
-
getParentContext
Description copied from interface:RuleSessionRetrieves the parent context of this session instance.- Specified by:
getParentContextin interfaceRuleSession<S extends RuleSession<S>>- Returns:
- the parent context of this Knowledge instance
-
insert0
Description copied from interface:RuleSessionInserts a fact in working memory and returns a serializable fact handle. When
resolveCollectionsis set to true, and the fact is anIterableor an Array, the engine will instead insert its components and return a nullFactHandle.Together with the
RuleSession.insert0(String, Object, boolean)method, this operation constitutes the core insert operations that are actually implemented by the engine. The other insert methods are just convenience wrappers of the two.- Specified by:
insert0in interfaceRuleSession<S extends RuleSession<S>>- Parameters:
fact- object to insertresolveCollections- collection/array inspection flag- Returns:
- fact handle assigned to the fact, or
nullif multiple facts were inserted - See Also:
-
insert0
Description copied from interface:RuleSessionInserts a fact and explicitly specifies its
Typename. WhenresolveCollectionsis set to true, and the fact is anIterableor an Array, the engine will instead insert its components, and return a nullFactHandle.Together with the
RuleSession.insert0(Object, boolean)method, this operation constitutes the core insert operations that are actually implemented by the engine. The other insert methods are just convenience wrappers of the two.- Specified by:
insert0in interfaceRuleSession<S extends RuleSession<S>>- Parameters:
type- type namefact- object to insertresolveCollections- collection/array inspection flag- Returns:
- fact handle assigned to the fact, or
nullif multiple facts were inserted - See Also:
-
get
Description copied from interface:EnvironmentRetrieves the value of a property by its name.- Specified by:
getin interfaceEnvironment- Type Parameters:
T- The expected type of the property value.- Parameters:
property- The name of the property to retrieve.- Returns:
- The value of the property as type T, or
nullif it does not exist.
-
getPropertyNames
Description copied from interface:EnvironmentRetrieves a collection of all property names in the environment.- Specified by:
getPropertyNamesin interfaceEnvironment- Returns:
- A collection of strings representing all property names in the environment.
-
addListener
Description copied from interface:EvaluationListenersAdds a listener to be notified of evaluation events. If the listener is already added, behavior depends on the implementation.- Specified by:
addListenerin interfaceEvaluationListeners- Parameters:
listener- the listener to add, notnull.
-
removeListener
Description copied from interface:EvaluationListenersRemoves a previously added listener. If the listener is not registered, this method has no effect.- Specified by:
removeListenerin interfaceEvaluationListeners- Parameters:
listener- the listener to remove, notnull.
-
compile
public Collection<LiteralEvaluator> compile(Collection<LiteralExpression> expressions) throws CompilationException Description copied from interface:RuntimeContextA convenience method for compiling literal expressions.
- Specified by:
compilein interfaceRuntimeContext<D extends RuleSetContext<C,R>> - Parameters:
expressions- literal conditions and their context- Returns:
- compiled literal conditions
- Throws:
CompilationException- if the expression failed to compile
-
resolveFieldReferences
- Specified by:
resolveFieldReferencesin interfaceRuleSet<D extends RuleSetContext<C,R>>
-
getRule
Description copied from interface:RuleSetRetrieves a rule based on its name.- Specified by:
getRulein interfaceRuleSet<D extends RuleSetContext<C,R>> - Parameters:
name- the name of the rule to retrieve- Returns:
- the rule with the specified name, or null if no rule with that name exists
-
set
Description copied from interface:FluentEnvironmentSets the specified property to the given value.- Specified by:
setin interfaceEnvironment- Specified by:
setin interfaceFluentEnvironment<D extends RuleSetContext<C,R>> - Parameters:
property- the name of the property to set; should not benull.value- the new value for the property; the actual type is determined by the implementation and the property being set.- Returns:
- the current instance of
Xto allow for method chaining.
-
configureTypes
Description copied from interface:RuntimeContextConfigures theTypeResolverby applying the given action.- Specified by:
configureTypesin interfaceRuntimeContext<D extends RuleSetContext<C,R>> - Parameters:
action- the action to configure the TypeResolver- Returns:
- this context
-
setClassLoader
Description copied from interface:RuntimeContextSets new parent classloader for this context's internal classloader.
- Specified by:
setClassLoaderin interfaceRuntimeContext<D extends RuleSetContext<C,R>> - Parameters:
classLoader- this context's new parent classloader
-
self
-
addImport
Description copied from interface:FluentImportsAdds an import statement using its string representation.- Specified by:
addImportin interfaceFluentImports<D extends RuleSetContext<C,R>> - Parameters:
imp- the full canonical name of the class or package to be imported- Returns:
- this instance to allow for method chaining
-
getRules
Description copied from interface:RuleSetMethod returns a list of rules created so far.
- Specified by:
getRulesin interfaceRuleSet<D extends RuleSetContext<C,R>> - Returns:
- list of currently known rules
-
getImports
Description copied from interface:FluentImportsRetrieves the current set of import statements.- Specified by:
getImportsin interfaceFluentImports<D extends RuleSetContext<C,R>> - Returns:
- an
Importsobject containing the current set of import statements
-
getRuleComparator
Description copied from interface:RuntimeContextRetrieves the comparator used for ordering rules.- Specified by:
getRuleComparatorin interfaceRuntimeContext<D extends RuleSetContext<C,R>> - Returns:
- the comparator for Rule objects.
-
setRuleComparator
Description copied from interface:RuntimeContextSets the comparator used for ordering rules.- Specified by:
setRuleComparatorin interfaceRuntimeContext<D extends RuleSetContext<C,R>> - Parameters:
comparator- the comparator for Rule objects.
-
newRule
Deprecated.Description copied from interface:RuntimeContextCreates a new rule with the provided name.- Specified by:
newRulein interfaceRuntimeContext<D extends RuleSetContext<C,R>> - Parameters:
name- rule name- Returns:
- a new rule builder
-
newRule
Deprecated.Description copied from interface:RuntimeContextCreates a new unnamed rule.- Specified by:
newRulein interfaceRuntimeContext<D extends RuleSetContext<C,R>> - Returns:
- a new rule builder
-
builder
Description copied from interface:RuntimeContextReturns an instance of
RuleSetBuilderfor building and appending rules to the current context.Builder MUST be terminated with the
RuleSetBuilder.build()call for changes to take effect.Usage BEFORE 3.1.00:
Usage AFTER 3.1.00:service .newKnowledge() .newRule() .forEach("$a", A.class) .where("$a.active") .execute();service .newKnowledge() .builder() // !! important .newRule() .forEach("$a", A.class) .where("$a.active") .execute() .build(); // !! important- Specified by:
builderin interfaceRuntimeContext<D extends RuleSetContext<C,R>> - Returns:
- new instance of RuleSetBuilder.
-
wrapTypeResolver
Deprecated.Description copied from interface:RuntimeContextWraps the provided TypeResolver with a TypeResolverWrapper instance.- Specified by:
wrapTypeResolverin interfaceRuntimeContext<D extends RuleSetContext<C,R>> - Parameters:
wrapper- the TypeResolverWrapper instance used to wrap the TypeResolver
-
setActivationMode
Description copied from interface:RuntimeContextSets the activation mode for the session.- Specified by:
setActivationModein interfaceRuntimeContext<D extends RuleSetContext<C,R>> - Parameters:
activationMode- the activation mode to set- Returns:
- the updated instance of the class
-
addEvaluator
Description copied from interface:EvaluatorsContextRegisters new condition evaluator and returns its handle. If an existing
Evaluatormatches the argument (Evaluator.compare(Evaluator)returnsEvaluator.RELATION_EQUALS), the existing evaluator handle will be returned instead and no changes will be made in the context.- Specified by:
addEvaluatorin interfaceEvaluatorsContext- Parameters:
evaluator- condition to addcomplexity- condition's relative complexity- Returns:
- new
EvaluatorHandleor the one of an existing condition.
-
replaceEvaluator
Description copied from interface:EvaluatorsContextReplaces existing condition with a new one. New condition must have the same
Evaluator.descriptor(), otherwiseIllegalArgumentExceptionwill be thrown.- Specified by:
replaceEvaluatorin interfaceEvaluatorsContext- Parameters:
handle- handle of an existing conditionnewEvaluator- new condition
-
getEvaluator
Description copied from interface:EvaluatorsContextReturns evaluator by its handle.
- Specified by:
getEvaluatorin interfaceEvaluatorsContext- Parameters:
handle- evaluator handle- Returns:
- existing condition evaluator or null if such condition does not exist
-
replaceEvaluator
Description copied from interface:EvaluatorsContextReplaces existing condition with a new one.
- Specified by:
replaceEvaluatorin interfaceEvaluatorsContext- Parameters:
handle- handle of an existing conditionpredicate- new condition in a form ifValuesPredicate
-
getExpressionResolver
Description copied from interface:RuntimeContextRetrieves the expression resolver for parsing string expressions.- Specified by:
getExpressionResolverin interfaceRuntimeContext<D extends RuleSetContext<C,R>> - Returns:
- the expression resolver
-
getClassLoader
Description copied from interface:RuntimeContextRetrieves the ClassLoader used by the current context.- Specified by:
getClassLoaderin interfaceRuntimeContext<D extends RuleSetContext<C,R>> - Returns:
- the ClassLoader used by the object.
-
getService
Description copied from interface:RuntimeContextReturns theKnowledgeServiceinstance.- Specified by:
getServicein interfaceRuntimeContext<D extends RuleSetContext<C,R>> - Returns:
- the
KnowledgeServiceinstance
-
getActivationManagerFactory
Description copied from interface:RuntimeContextReturns the Activation Manager factory class for this RuntimeContext.- Specified by:
getActivationManagerFactoryin interfaceRuntimeContext<D extends RuleSetContext<C,R>> - Returns:
- the Activation Manager factory class
-
setActivationManagerFactory
Description copied from interface:RuntimeContextSets the Activation Manager factory class for this RuntimeContext.- Specified by:
setActivationManagerFactoryin interfaceRuntimeContext<D extends RuleSetContext<C,R>> - Type Parameters:
A- the type of Activation Manager- Parameters:
managerClass- the Activation Manager factory class
-
setActivationManagerFactory
Description copied from interface:RuntimeContextSets the Activation Manager factory class name for this RuntimeContext.- Specified by:
setActivationManagerFactoryin interfaceRuntimeContext<D extends RuleSetContext<C,R>> - Parameters:
managerClass- the Activation Manager factory class name
-
getTypeResolver
Description copied from interface:RuntimeContextRetrieves the TypeResolver instance associated with this RuntimeContext.- Specified by:
getTypeResolverin interfaceRuntimeContext<D extends RuleSetContext<C,R>> - Returns:
- the TypeResolver instance
-
getConfiguration
Description copied from interface:RuntimeContextRetrieves the Configuration object associated with this RuntimeContext.- Specified by:
getConfigurationin interfaceRuntimeContext<D extends RuleSetContext<C,R>> - Returns:
- the Configuration object
-
getSourceCompiler
Description copied from interface:RuntimeContextCreates and returns a new instance ofJavaSourceCompiler.- Specified by:
getSourceCompilerin interfaceRuntimeContext<D extends RuleSetContext<C,R>> - Returns:
- A new
JavaSourceCompilerinstance.
-