Interface StatelessSession

All Superinterfaces:
Environment, EventBus, FluentEnvironment<StatelessSession>, FluentImports<StatelessSession>, MemoryStreaming, Named, RuleSession<StatelessSession>, RuleSet<RuntimeRule>, RuleSetContext<StatelessSession,RuntimeRule>, RuntimeContext<StatelessSession>, SessionOps

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()

      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());
       

      This method is only applicable if the provided FactStorage SPI implementation stores facts by reference (e.g. does not serialize/deserialize objects). The default implementation does.

      Specified by:
      fire in interface RuleSession<StatelessSession>
      Returns:
      an object representing the result of the rule session execution.
    • fire

      default 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

      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

      default void fire(Consumer<Object> consumer)

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

      Parameters:
      consumer - consumer for session memory
    • fire

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

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

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

      default <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)