Class RuleSystem


  • public class RuleSystem
    extends java.lang.Object
    The rule system is the main entry point. It contains the rulebase with all rules and knows about the observed objects.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.lang.Object context
      The context for rule action execution.
      protected java.util.logging.Logger logger
      The logger for rule warnings.
      protected PropertyChangeManager pcman
      The PropertyChangeManager to add/remove handlers and manage events
      protected boolean processall
      Flag to check if currently in processAllEvents (hack?).
      protected boolean queueevents
      The execution mode (direct vs queue).
      protected IRulebase rulebase
      The rulebase.
      protected java.util.IdentityHashMap<java.lang.Object,​Tuple2<java.lang.Object,​IRule<?>[]>> rules
      The rules generated for an object.
    • Constructor Summary

      Constructors 
      Constructor Description
      RuleSystem​(java.lang.Object context)
      Create a new rule system.
      RuleSystem​(java.lang.Object context, java.util.logging.Logger logger, boolean queueevents)
      Create a new rule system.
    • Field Detail

      • rulebase

        protected IRulebase rulebase
        The rulebase.
      • rules

        protected java.util.IdentityHashMap<java.lang.Object,​Tuple2<java.lang.Object,​IRule<?>[]>> rules
        The rules generated for an object.
      • context

        protected java.lang.Object context
        The context for rule action execution.
      • logger

        protected java.util.logging.Logger logger
        The logger for rule warnings.
      • pcman

        protected PropertyChangeManager pcman
        The PropertyChangeManager to add/remove handlers and manage events
      • queueevents

        protected boolean queueevents
        The execution mode (direct vs queue).
      • processall

        protected boolean processall
        Flag to check if currently in processAllEvents (hack?). Required to avoid nested processAllEvents() call in addEvent()
    • Constructor Detail

      • RuleSystem

        public RuleSystem​(java.lang.Object context)
        Create a new rule system.
      • RuleSystem

        public RuleSystem​(java.lang.Object context,
                          java.util.logging.Logger logger,
                          boolean queueevents)
        Create a new rule system.
    • Method Detail

      • getRulebase

        public IRulebase getRulebase()
        Get the rulebase.
        Returns:
        The rule base.
      • processEvent

        public IIntermediateFuture<RuleEvent> processEvent()
        Process the next event by - finding rules that are sensible to the event type - evaluate the conditions of these conditions - fire actions of triggered rules.
      • processAllEvents

        public IFuture<java.lang.Void> processAllEvents()
        Process events until the event queue is empty or max events have been processed.
      • addEvent

        public IFuture<java.lang.Void> addEvent​(IEvent event)
        Add an event.
      • isEventAvailable

        public boolean isEventAvailable()
        Test if at least one event is available.
      • isQueueEvents

        public boolean isQueueEvents()
        Get the queueevents.
        Returns:
        The queueevents
      • setQueueEvents

        public void setQueueEvents​(boolean queueevents)
        The queueevents to set.
        Parameters:
        queueevents - The queueevents to set
      • observeObject

        public java.lang.Object observeObject​(java.lang.Object object,
                                              boolean bean,
                                              boolean hasrules,
                                              IResultCommand<IFuture<java.lang.Void>,​PropertyChangeEvent> eventadder)
        Monitor an object to the rule engine. - Extracts conditions - Extracts actions - Creates rules from condition/action pairs and adds them to the rulebase. - Subscribes for events
      • analyzeMethod

        protected void analyzeMethod​(java.lang.reflect.Method method,
                                     java.lang.Object object,
                                     java.util.Map<java.lang.reflect.Method,​IResultCommand<?,​?>> eventcreators,
                                     java.util.Map<java.lang.String,​Rule<?>> rules)
        Inspects a method for - condition annotation - action annotation