Interface StatelessSession

All Superinterfaces:
Environment, EvaluationListeners, EvaluatorsContext, FluentEnvironment<StatelessSession>, FluentImports<StatelessSession>, RuleSession<StatelessSession>, RuleSet<RuntimeRule>, RuleSetContext<StatelessSession,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();
       Log.info(c.getSomeUpdatedProperty());
       

      While this method is the easiest 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). The default implementation does not serialize or otherwise transform fact instances

      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.

      Type Parameters:
      T - the generic type of the objects consumed when the session is fired
      Parameters:
      type - the literal type of the objects
      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

      Type Parameters:
      T - the generic type of the objects consumed when the session is fired
      Parameters:
      consumer - consumer for session memory
      filter - filtering predicate
      type - string type of the objects to consume
    • fire

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

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

      Type Parameters:
      T - the generic type of the objects consumed when the session is fired
      Parameters:
      consumer - consumer for session memory
      type - the class of the objects consumed when the session is fired
    • 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

      Type Parameters:
      T - the generic type of the objects consumed when the session is fired
      Parameters:
      type - class of objects to retrieve upon fire
      consumer - consumer for session memory
      filter - filtering predicate
    • insertAndFire

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

      default void insertAndFire(Iterable<Object> objects)