Interface StatelessSession

All Superinterfaces:
Environment, EvaluationListeners, EvaluatorsContext, FluentEnvironment<StatelessSession>, FluentImports<StatelessSession>, RuleSession<StatelessSession>, RuleSet<RuntimeRule>, RuntimeContext<StatelessSession>

public interface StatelessSession extends RuleSession<StatelessSession>

Unlike stateful sessions, stateless sessions are designed to be short-living instances that can be fired only once, returning the resulting working memory snapshot. Generally, every StatelessSession can be considered as a StatefulSession that automatically calls StatefulSession.close() after StatefulSession.fire().

  • Method Details

    • fire

      void fire(BiConsumer<FactHandle,Object> consumer)

      Fires the session and calls the consumer for each memory object and its fact handle.

      Parameters:
      consumer - consumer for session memory
    • fire

      Void fire()

      Fires the session and performs no memory scan. This method might be useful if developer is holding references to fact variables and only interested in changes of those facts:

      
       Customer c = new Customer();
       session.insert(c);
       session.fire();
       System.out.println(c.getSomeUpdatedProperty());
       

      While this method is the fastest among the other fire(..) methods, it is only applicable if the provided FactStorage SPI implementation stores facts by reference (e.g. does not serialize/deserialize objects)

      Specified by:
      fire in interface RuleSession<StatelessSession>
    • fire

      default void fire(Predicate<Object> filter, Consumer<Object> consumer)

      Fires the session and calls the consumer for each memory object that satisfies given filter

      Parameters:
      consumer - consumer for session memory
      filter - filtering predicate
    • fire

      void fire(Consumer<Object> consumer)

      Fires the session and calls the consumer for each memory object.

      Parameters:
      consumer - consumer for session memory
    • fire

      <T> void fire(String type, Consumer<T> consumer)

      A convenience method to retrieve facts of a specific type name.

      Parameters:
      consumer - consumer for session memory
    • fire

      default <T> void fire(String type, Predicate<T> filter, Consumer<T> consumer)

      A convenience method to retrieve facts of a specific type name and matching given predicate

      Parameters:
      consumer - consumer for session memory
      filter - filtering predicate
    • fire

      <T> void fire(Class<T> type, Consumer<T> consumer)

      A convenience method to retrieve the resulting instances of a specific Java class.

      Parameters:
      consumer - consumer for session memory
    • fire

      default <T> void fire(Class<T> type, Predicate<T> filter, Consumer<T> consumer)

      A convenience method to retrieve facts of a specific Java type and matching given predicate

      Parameters:
      consumer - consumer for session memory
      filter - filtering predicate
    • insertAndFire

      default void insertAndFire(Object... objects)
    • insertAndFire

      default void insertAndFire(Iterable<Object> objects)