Class AbstractSessionWrapper<S extends RuleSession<S>>

java.lang.Object
org.evrete.util.AbstractSessionWrapper<S>
Type Parameters:
S - the type of the RuleSession delegate object
All Implemented Interfaces:
Environment, EventBus, FluentEnvironment<S>, FluentImports<S>, MemoryStreaming, Named, RuleSession<S>, RuleSet<RuntimeRule>, RuleSetContext<S,RuntimeRule>, RuntimeContext<S>, SessionOps

public abstract class AbstractSessionWrapper<S extends RuleSession<S>> extends Object implements RuleSession<S>
This class provides an abstract implementation of the RuleSession interface, delegating the session's methods to a provided delegate object.
  • Field Details

  • Constructor Details

    • AbstractSessionWrapper

      protected AbstractSessionWrapper(S delegate)
  • Method Details

    • getActivationManager

      public ActivationManager getActivationManager()
      Description copied from interface: RuleSession
      Retrieves the activation manager associated with this session.
      Specified by:
      getActivationManager in interface RuleSession<S extends RuleSession<S>>
      Returns:
      the activation manager for this session
    • asCollector

      public <T> Collector<T,?,S> asCollector()
      Description copied from interface: RuleSession
      A convenience method that returns an instance of Collector for inserting streams of facts.
      Specified by:
      asCollector in interface RuleSession<S extends RuleSession<S>>
      Type Parameters:
      T - the type of input elements to the reduction operation
      Returns:
      collector
    • setActivationManager

      public S setActivationManager(ActivationManager activationManager)
      Description copied from interface: RuleSession
      Sets the activation manager for the session.
      Specified by:
      setActivationManager in interface RuleSession<S extends RuleSession<S>>
      Parameters:
      activationManager - the activation manager to set
      Returns:
      the current session instance
    • getParentContext

      public Knowledge getParentContext()
      Description copied from interface: RuleSession
      Retrieves the parent context of this session instance.
      Specified by:
      getParentContext in interface RuleSession<S extends RuleSession<S>>
      Returns:
      the parent context of this Knowledge instance
    • insert0

      public FactHandle insert0(Object fact, boolean resolveCollections)
      Description copied from interface: SessionOps

      Inserts a fact in working memory and returns a serializable fact handle. When resolveCollections is set to true, and the fact is an Iterable or an Array, the engine will instead insert its components and return a null FactHandle. The engine will derive logical type of the fact(s) from their Java class names.

      Together with the SessionOps.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:
      insert0 in interface SessionOps
      Parameters:
      fact - object to insert
      resolveCollections - collection/array inspection flag
      Returns:
      fact handle assigned to the fact, or null if multiple facts were inserted
      See Also:
    • insert0

      public FactHandle insert0(String type, Object fact, boolean resolveCollections)
      Description copied from interface: SessionOps

      Inserts a fact and explicitly specifies its Type name. When resolveCollections is set to true, and the fact is an Iterable or an Array, the engine will instead insert its components, and return a null FactHandle.

      Together with the SessionOps.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:
      insert0 in interface SessionOps
      Parameters:
      type - explicit logical type of the inserted fact(s)
      fact - object to insert
      resolveCollections - collection/array inspection flag
      Returns:
      fact handle assigned to the fact, or null if multiple facts were inserted
      See Also:
    • streamFactEntries

      public Stream<Map.Entry<FactHandle,Object>> streamFactEntries()
      Description copied from interface: MemoryStreaming
      Streams all fact entries as a Stream of Map.Entry objects.
      Specified by:
      streamFactEntries in interface MemoryStreaming
      Returns:
      a stream of all fact entries and their fact handles
    • streamFactEntries

      public <T> Stream<Map.Entry<FactHandle,T>> streamFactEntries(String type)
      Description copied from interface: MemoryStreaming
      Streams all fact entries of a specific type as a Stream of Map.Entry objects.
      Specified by:
      streamFactEntries in interface MemoryStreaming
      Type Parameters:
      T - the type of facts to stream
      Parameters:
      type - the logical type of the facts
      Returns:
      a stream of fact entries of the specified logical type
      See Also:
    • streamFactEntries

      public <T> Stream<Map.Entry<FactHandle,T>> streamFactEntries(Class<T> type)
      Description copied from interface: MemoryStreaming
      Streams all fact entries of a specific Java type as a Stream of Map.Entry objects.
      Specified by:
      streamFactEntries in interface MemoryStreaming
      Type Parameters:
      T - the type of facts to stream
      Parameters:
      type - the Java type of the facts
      Returns:
      a stream of fact entries of the specified logical type
    • getFact

      public <T> T getFact(FactHandle handle)
      Description copied from interface: RuleSession
      Returns fact by its handle.
      Specified by:
      getFact in interface RuleSession<S extends RuleSession<S>>
      Type Parameters:
      T - type of the fact (use Object or wildcard if type is unknown)
      Parameters:
      handle - fact handle
      Returns:
      fact or null if fact is not found
    • delete

      public void delete(FactHandle handle)
      Description copied from interface: SessionOps
      Deletes a fact from the working memory.
      Specified by:
      delete in interface SessionOps
      Parameters:
      handle - The FactHandle associated with the fact to be deleted.
    • update

      public void update(FactHandle handle, Object newValue)
      Description copied from interface: SessionOps
      Updates a fact that already exists in the working memory
      Specified by:
      update in interface SessionOps
      Parameters:
      handle - fact handle, previously assigned to original fact
      newValue - an updated version of the fact
    • get

      public <T> T get(String property)
      Description copied from interface: Environment
      Retrieves the value of a property by its name.
      Specified by:
      get in interface Environment
      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 null if it does not exist.
    • getPropertyNames

      public Collection<String> getPropertyNames()
      Description copied from interface: Environment
      Retrieves a collection of all property names in the environment.
      Specified by:
      getPropertyNames in interface Environment
      Returns:
      A collection of strings representing all property names in the environment.
    • getName

      public String getName()
      Description copied from interface: Named
      Returns the name of the object.
      Specified by:
      getName in interface Named
      Returns:
      the name of the object as a String
    • getRule

      public final RuntimeRule getRule(String name)
      Description copied from interface: RuleSet
      Retrieves a rule based on its name.
      Specified by:
      getRule in interface RuleSet<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

      public S set(String property, Object value)
      Description copied from interface: FluentEnvironment
      Sets the specified property to the given value.
      Specified by:
      set in interface Environment
      Specified by:
      set in interface FluentEnvironment<D extends RuleSetContext<C,R>>
      Parameters:
      property - the name of the property to set; should not be null.
      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 X to allow for method chaining.
    • getPublisher

      public <E extends ContextEvent> Events.Publisher<E> getPublisher(Class<E> eventClass)
      Description copied from interface: EventBus
      Returns a publisher for a specific event class type.
      Specified by:
      getPublisher in interface EventBus
      Type Parameters:
      E - the type of the event to publish
      Parameters:
      eventClass - the class object of the event type
      Returns:
      an Events.Publisher for the specified event class type
      See Also:
    • configureTypes

      public S configureTypes(Consumer<TypeResolver> action)
      Description copied from interface: RuntimeContext
      Configures the TypeResolver by applying the given action.
      Specified by:
      configureTypes in interface RuntimeContext<D extends RuleSetContext<C,R>>
      Parameters:
      action - the action to configure the TypeResolver
      Returns:
      this context
    • self

      protected S self()
    • addImport

      public S addImport(String imp)
      Description copied from interface: FluentImports
      Adds an import statement using its string representation.
      Specified by:
      addImport in interface FluentImports<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

      public final List<RuntimeRule> getRules()
      Description copied from interface: RuleSet

      Method returns a list of rules created so far.

      Specified by:
      getRules in interface RuleSet<D extends RuleSetContext<C,R>>
      Returns:
      list of currently known rules
    • getImports

      public Imports getImports()
      Description copied from interface: FluentImports
      Retrieves the current set of import statements.
      Specified by:
      getImports in interface FluentImports<D extends RuleSetContext<C,R>>
      Returns:
      an Imports object containing the current set of import statements
    • getRuleComparator

      public Comparator<Rule> getRuleComparator()
      Description copied from interface: RuntimeContext
      Retrieves the comparator used for ordering rules.
      Specified by:
      getRuleComparator in interface RuntimeContext<D extends RuleSetContext<C,R>>
      Returns:
      the comparator for Rule objects.
    • setRuleComparator

      public void setRuleComparator(Comparator<Rule> comparator)
      Description copied from interface: RuntimeContext
      Sets the comparator used for ordering rules.
      Specified by:
      setRuleComparator in interface RuntimeContext<D extends RuleSetContext<C,R>>
      Parameters:
      comparator - the comparator for Rule objects.
    • builder

      public RuleSetBuilder<S> builder(ClassLoader classLoader)
      Description copied from interface: RuntimeContext

      Returns an instance of RuleSetBuilder for 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:

       
       service
            .newKnowledge()
            .newRule()
            .forEach("$a", A.class)
            .where("$a.active")
            .execute();
       
       
      Usage AFTER 3.1.00:
       
       service
            .newKnowledge()
            .builder()       // !! important
            .newRule()
            .forEach("$a", A.class)
            .where("$a.active")
            .execute()
            .build();        // !! important
       
       
      Specified by:
      builder in interface RuntimeContext<D extends RuleSetContext<C,R>>
      Parameters:
      classLoader - the classloader to use.
      Returns:
      new instance of RuleSetBuilder.
    • setActivationMode

      public S setActivationMode(ActivationMode activationMode)
      Description copied from interface: RuntimeContext
      Sets the activation mode for the session.
      Specified by:
      setActivationMode in interface RuntimeContext<D extends RuleSetContext<C,R>>
      Parameters:
      activationMode - the activation mode to set
      Returns:
      the updated instance of the class
    • getEvaluatorsContext

      public EvaluatorsContext getEvaluatorsContext()
      Description copied from interface: RuntimeContext
      Return the condition manager associated with this context.
      Specified by:
      getEvaluatorsContext in interface RuntimeContext<D extends RuleSetContext<C,R>>
      Returns:
      the evaluator context
    • getClassLoader

      public ClassLoader getClassLoader()
      Description copied from interface: RuntimeContext
      Retrieves the ClassLoader used by the current context.
      Specified by:
      getClassLoader in interface RuntimeContext<D extends RuleSetContext<C,R>>
      Returns:
      the ClassLoader used by the object.
    • getService

      public KnowledgeService getService()
      Description copied from interface: RuntimeContext
      Returns the KnowledgeService instance.
      Specified by:
      getService in interface RuntimeContext<D extends RuleSetContext<C,R>>
      Returns:
      the KnowledgeService instance
    • getActivationManagerFactory

      public Class<? extends ActivationManager> getActivationManagerFactory()
      Description copied from interface: RuntimeContext
      Returns the Activation Manager factory class for this RuntimeContext.
      Specified by:
      getActivationManagerFactory in interface RuntimeContext<D extends RuleSetContext<C,R>>
      Returns:
      the Activation Manager factory class
    • setActivationManagerFactory

      public <A extends ActivationManager> void setActivationManagerFactory(Class<A> managerClass)
      Description copied from interface: RuntimeContext
      Sets the Activation Manager factory class for this RuntimeContext.
      Specified by:
      setActivationManagerFactory in interface RuntimeContext<D extends RuleSetContext<C,R>>
      Type Parameters:
      A - the type of Activation Manager
      Parameters:
      managerClass - the Activation Manager factory class
    • setActivationManagerFactory

      public void setActivationManagerFactory(String managerClass)
      Description copied from interface: RuntimeContext
      Sets the Activation Manager factory class name for this RuntimeContext.
      Specified by:
      setActivationManagerFactory in interface RuntimeContext<D extends RuleSetContext<C,R>>
      Parameters:
      managerClass - the Activation Manager factory class name
    • getTypeResolver

      public TypeResolver getTypeResolver()
      Description copied from interface: RuntimeContext
      Retrieves the TypeResolver instance associated with this RuntimeContext.
      Specified by:
      getTypeResolver in interface RuntimeContext<D extends RuleSetContext<C,R>>
      Returns:
      the TypeResolver instance
    • getConfiguration

      public Configuration getConfiguration()
      Description copied from interface: RuntimeContext
      Retrieves the Configuration object associated with this RuntimeContext.
      Specified by:
      getConfiguration in interface RuntimeContext<D extends RuleSetContext<C,R>>
      Returns:
      the Configuration object