Class RuleEngine

  • Direct Known Subclasses:
    ExecutionSchema

    public class RuleEngine
    extends java.lang.Object
    A rule engine is a facade for accessing the EVM, it allows the retrieval of all activations and filtered access by state, specification or both. It also allows the addition or removal of rules.
    Since:
    2.0
    • Constructor Detail

      • RuleEngine

        protected RuleEngine​(RuleBase ruleBase)
        Creates a rule engine for the given ruleBase
        Parameters:
        ruleBase -
    • Method Detail

      • create

        public static RuleEngine create​(RuleBase ruleBase)
        Creates a rule engine for the given ruleBase
        Parameters:
        ruleBase -
        Returns:
        the created facade
      • setConflictResolver

        public void setConflictResolver​(ConflictResolver conflictResolver)
      • addRule

        public <EventAtom> boolean addRule​(RuleSpecification<EventAtom> specification)
        Adds a rule specification to the RuleBase. If the rule already exists, no change occurs in the set of rules.
        Parameters:
        specification -
        Returns:
        true if the rule was added, false if it already existed
      • addRule

        public <EventAtom> boolean addRule​(RuleSpecification<EventAtom> specification,
                                           EventFilter<? super EventAtom> filter)
        Adds a rule specification to the RuleBase with the given filter. If the rule already exists, no change occurs in the set of rules.
        Parameters:
        specification -
        filter - the partial match to be used as a filter for activations
        Returns:
        true if the rule was added, false if it already existed
      • containsRule

        public <EventAtom> boolean containsRule​(RuleSpecification<EventAtom> specification)
        Decides whether a rule specification is already added to the RuleBase without filter.
      • containsRule

        public <EventAtom> boolean containsRule​(RuleSpecification<EventAtom> specification,
                                                EventFilter<? super EventAtom> filter)
        Decides whether a rule specification is already added to the RuleBase with the specified filter.
      • getActivations

        public java.util.Map<ActivationState,​java.util.Set<Activation<?>>> getActivations()
        Returns:
        a copy of the multimap containing all activations
        Since:
        2.0
      • getNextActivation

        public Activation<?> getNextActivation()
        Returns:
        the next enabled activation if exists, selected by the conflict resolver
      • getConflictingActivations

        public java.util.Set<Activation<?>> getConflictingActivations()
        Returns:
        an immutable set of conflicting activations
      • getActivations

        public java.util.Set<Activation<?>> getActivations​(ActivationState state)
        Parameters:
        state -
        Returns:
        an immutable set of the activations in the given state
      • getActivations

        public <EventAtom> java.util.Set<Activation<EventAtom>> getActivations​(RuleSpecification<EventAtom> specification)
        Parameters:
        specification -
        Returns:
        the immutable set of activations of the given specification
      • getActivations

        public <EventAtom> java.util.Set<Activation<EventAtom>> getActivations​(RuleSpecification<EventAtom> specification,
                                                                               EventFilter<? super EventAtom> filter)
        Parameters:
        specification -
        filter -
        Returns:
        the immutable set of activations of the given filtered specification
      • getActivations

        public <EventAtom> java.util.Set<Activation<EventAtom>> getActivations​(RuleSpecification<EventAtom> specification,
                                                                               ActivationState state)
        Parameters:
        specification -
        state -
        Returns:
        the immutable set of activations of the given specification with the given state
      • getActivations

        public <EventAtom> java.util.Set<Activation<EventAtom>> getActivations​(RuleSpecification<EventAtom> specification,
                                                                               EventFilter<? super EventAtom> filter,
                                                                               ActivationState state)
        Parameters:
        specification -
        filter -
        state -
        Returns:
        the immutable set of activations of the given specification with the given state
      • getRuleSpecificationMultimap

        public java.util.Map<RuleSpecification<?>,​java.util.Set<EventFilter<?>>> getRuleSpecificationMultimap()
        Returns:
        the immutable set of rules in the EVM
        Since:
        2.0
      • removeRule

        public <EventAtom> boolean removeRule​(RuleSpecification<EventAtom> specification)
        Removes the given not-filtered rule from the EVM.
        Parameters:
        specification -
        Returns:
        true, if the rule existed
      • removeRule

        public <EventAtom> boolean removeRule​(RuleSpecification<EventAtom> specification,
                                              EventFilter<? super EventAtom> filter)
        Removes the given filtered rule from the EVM.
        Parameters:
        specification -
        filter - the partial match used as a filter
        Returns:
        true, if the rule existed
      • getRuleBase

        protected RuleBase getRuleBase()
      • getEventRealm

        public EventRealm getEventRealm()
        Returns:
        the event realm of the rule base
      • getLogger

        public org.apache.log4j.Logger getLogger()
      • dispose

        public void dispose()
        Disposes of the rule base.