Interface EventBus

All Known Subinterfaces:
Knowledge, RuleSession<S>, RuleSetContext<C,R>, RuntimeContext<C>, StatefulSession, StatelessSession
All Known Implementing Classes:
org.evrete.runtime.AbstractKnowledgeService, AbstractSessionWrapper, KnowledgeService, KnowledgeWrapper

public interface EventBus
Interface representing an Event Bus for subscribing to events.
  • Method Details

    • subscribe

      default <E extends ContextEvent> Events.Subscription subscribe(Class<E> eventClass, boolean async, Consumer<E> consumer)
      Subscribes an even consumer to a specific event class type.

      When an event of the specified type is published, the consumer will be invoked.

      The consumer can be notified asynchronously based on the async parameter.

      Type Parameters:
      E - the type of the event to listen for
      Parameters:
      eventClass - the class object of the event type
      async - if true, the consumer will be invoked asynchronously using the AbstractKnowledgeService.getExecutor(); if false, it will be invoked synchronously
      consumer - the consumer that will handle events of the specified type
      Returns:
      a Events.Subscription that can be used to unsubscribe the consumer from the event type
      Throws:
      IllegalArgumentException - if the provided event class is not supported
      See Also:
    • getPublisher

      <E extends ContextEvent> Events.Publisher<E> getPublisher(Class<E> eventClass)
      Returns a publisher for a specific event class type.
      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
      Throws:
      IllegalArgumentException - if the provided event class is not supported
      See Also:
    • subscribe

      default <E extends ContextEvent> Events.Subscription subscribe(Class<E> eventClass, Consumer<E> consumer)
    • subscribeAsync

      default <E extends ContextEvent> Events.Subscription subscribeAsync(Class<E> eventClass, Consumer<E> consumer)