org.universAAL.drools.engine
Class RulesEngine

Package class diagram package RulesEngine
java.lang.Object
  extended by org.universAAL.drools.engine.RulesEngine

public final class RulesEngine
extends Object

Rules engine based on Drools technology. Provides the funcionalities of the rules engine and the access to the working memory where is stored the knowledge.

Author:
Miguel Llorente (mllorente)

Method Summary
 void disableTestMode()
          Deactivates the test mode for avoiding using special configuration related to the OSGi environment.
 void enableTestMode()
          Activates the test mode for avoiding using special configuration related to the OSGi environment.
static Collection<org.drools.FactHandle> getElementsInWorkingMemory()
           
static RulesEngine getInstance()
          Instance of the rules engine for using it in non-osgi environments.
static RulesEngine getInstance(org.osgi.framework.BundleContext context)
          Gets an instance of the rules engine for using it in universAAL.
static long getNumberOfElementsInWorkingMemory()
           
static UUID getUUID()
          Returns an UUID of the rules engine.
 void insertContextEvent(Object event)
          Sends a context events to the rules engine and fire the rules to check if any rule in the working memory fits with the new conditions.
 void insertRule(String ruleIn)
          Inserts a rule from a string.
 void insertRuleList(List<RuleModel> rules)
          Inserts a list of rules.
 boolean isWellFormed()
          Check if the rules engine was created correctly.
static void publishConsequence(String uri, String[] keys, String[] values)
          Publishes a consequence in the ContextBus.
 void removeRule(String name)
          Removes a rule from the default package.
 void removeRule(String name, String pckg)
          Removes a rule from a a specified package.
 void restartRulesEngine()
           
 void setBundleContext(org.osgi.framework.BundleContext bc)
          Setter for the bundle context.
 void shutdown()
           
static void startRulesEngine()
           
static void stopRulesEngine()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static RulesEngine getInstance(org.osgi.framework.BundleContext context)
Gets an instance of the rules engine for using it in universAAL. It allows the interaction with the rules engine: insertion an retraction of facts, rules and evens; extraction of information related to the runtime session for monitoring proposals and consequences publication.

Parameters:
context - The bundle context.
Returns:
Instance of the rules engine.

getInstance

public static RulesEngine getInstance()
Instance of the rules engine for using it in non-osgi environments. It must not be used in a typical universAAL platform exectuion. (Method created for debugging and auto-testing purposes).

Returns:
An instance of the RulesEngine ready to be used out of the OSGI runtime. This instance is not valid over universAAL and OSGi.

getUUID

public static UUID getUUID()
Returns an UUID of the rules engine. Useful for validating the singleton condition of this class.

Returns:

insertContextEvent

public void insertContextEvent(Object event)
Sends a context events to the rules engine and fire the rules to check if any rule in the working memory fits with the new conditions.

Parameters:
event - ContextEvent to be inserted.

isWellFormed

public boolean isWellFormed()
Check if the rules engine was created correctly. TODO Must be improved to offer richer information if the response is negative.

Returns:
true if the rules engine was correctly created; false if not.

setBundleContext

public void setBundleContext(org.osgi.framework.BundleContext bc)
Setter for the bundle context.

Parameters:
bc - The new bundle context.

enableTestMode

public void enableTestMode()
Activates the test mode for avoiding using special configuration related to the OSGi environment. Used to perform JUnit tests.


disableTestMode

public void disableTestMode()
Deactivates the test mode for avoiding using special configuration related to the OSGi environment. Used to perform JUnit tests.


publishConsequence

public static void publishConsequence(String uri,
                                      String[] keys,
                                      String[] values)
                               throws Exception
Publishes a consequence in the ContextBus. This method must be called from the consequence part of the rules (the part started by "THEN" statement in the DRL language).

Parameters:
uri - URI for the new consequence
keys - Array containing all the keys of the properties. Each key must have a value associated. According to this, keys.lenght() and values.lenght() must equivalent.
values - Array containing all the values of the properties.
Throws:
Exception

getNumberOfElementsInWorkingMemory

public static long getNumberOfElementsInWorkingMemory()

getElementsInWorkingMemory

public static Collection<org.drools.FactHandle> getElementsInWorkingMemory()

startRulesEngine

public static void startRulesEngine()

stopRulesEngine

public static void stopRulesEngine()

restartRulesEngine

public void restartRulesEngine()

insertRule

public void insertRule(String ruleIn)
Inserts a rule from a string.

Parameters:
ruleIn - The rule codification.
Throws:
Exception

insertRuleList

public void insertRuleList(List<RuleModel> rules)
Inserts a list of rules. In any rule fails,

Parameters:
rules - ArrayList
Throws:
DroolsException - drools exception.

removeRule

public void removeRule(String name,
                       String pckg)
Removes a rule from a a specified package.

Parameters:
name - Name of the rule
pckg - Package of the rule

removeRule

public void removeRule(String name)
Removes a rule from the default package.

Parameters:
name - Name of the rule

shutdown

public void shutdown()


Copyright © 2014 universAAL Consortium. All Rights Reserved.