public class DroolsBasedEngine extends Reasoner
Reasoner implementation is based on the JBoss Drools rule engine by using several classes of
org.drools. It provides the compilation of author defined XML-Code to drools code by
WorkingMemoryRuleGenerator and is able to handle active
user feedback from user interface. Internal sensor data will be added to the KnowledgeBase together with the
compiled rule set. The rules then will set the current reachability map of this class which will be published onto
the ActiveMQ result topic.| Modifier and Type | Field and Description |
|---|---|
private long |
accessKey
The access key which is generated randomly on class creation.
|
private java.util.Map<ReasonerDimension,org.drools.runtime.rule.FactHandle> |
factHandles
All handles to facts actual known to Drools working memory.
|
private org.drools.KnowledgeBase |
kbase
The Drools knowledge base.
|
private java.util.Map<ReachabilityGroup,java.lang.Long> |
lastFeedback
The time of the last given user feedback.
|
private org.drools.runtime.StatefulKnowledgeSession |
memory
The Drools working memory.
|
private java.util.Map<ReachabilityGroup,ReachabilityStatus> |
memoryStatus
The current status in memory.
|
private static java.lang.String |
MIND_FEEDBACK_KEY
The name of the property which contains the time for how long active feedback shall be minded.
|
private static java.lang.String |
PHENOTYPE_FILE_PROPERTY_KEY
The name of the property which contains the name of the current rule-set file.
|
private java.util.Properties |
reasonerProps
Basic (user-defined) properties.
|
private long |
startingAt
Starting time of the reasoner.
|
private java.util.Map<ReachabilityGroup,ReachabilityStatus> |
userFeedback
Current given user feedback.
|
PROPERTY_FILE_SOURCE_KEY| Constructor and Description |
|---|
DroolsBasedEngine()
Create a new rule based reasoning engine (Using Jess Rule Engine).
|
| Modifier and Type | Method and Description |
|---|---|
void |
cleanUp()
Cleans up by freeing all resources.
|
void |
dump()
If this method is called, the reasoner dumps its current internal state using the
OutputUtil.info(String) method. |
java.util.Map<ReachabilityGroup,ReachabilityStatus> |
getEstimatedReachability()
Returns the current estimated state of reachability of all registered groups as hash map.
|
ReachabilityStatus |
getEstimatedReachability(ReachabilityGroup group)
Returns the current estimated state of reachability for a certain group from the reasoner.
|
java.util.Map<java.lang.String,java.lang.String> |
getValuesForProperty(java.lang.String property)
It may occur that a property is defined as
DisplayType.AGENT_DEFINED, which means that the value range is
dynamically defined at runtime. |
private boolean |
globalExists(java.lang.String name)
Checks if a global is defined within the
StatefulKnowledgeSession or not. |
void |
handleFeedback(ReachabilityGroup group,
ReachabilityStatus status)
Observes the input topic and handles feedback delivered on this topic.
|
java.util.Properties |
loadCurrentProperties(ConfigType type)
The
PropertyService requests the actual properties of a certain ConfigType from its creator. |
private void |
loadKBase()
Load default or cached knowledge base for drools CEP.
|
static void |
main(java.lang.String[] args)
Main procedure to start and run this reasoning engine as
ReasonerAgent. |
private void |
setGlobal(java.lang.String name,
java.lang.Object value)
Sets a global variable of the
StatefulKnowledgeSession to a certain value. |
void |
setReachabilityStatus(ReachabilityGroup group,
ReachabilityStatus status,
long accessKeyIn)
This method will the the
ReachabilityStatus of a certain ReachabilityGroup. |
void |
setSensorData(JsonReachabilitySensorData sensorData)
Adds a new
SensorData object to the StatefulKnowledgeSession or replaces the last known
SensorData of this dimension. |
void |
updateProperties(java.util.Properties newProps,
java.util.Properties changedProps,
ConfigType type)
The
PropertyService informs its creator, that there was a change of properties and that the creator
should update his properties according to the new ones. |
getID, getVersion, isActive, isSilent, pushProperties, run, setSilent, shutDown, stoppedactiveCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yieldequals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitstartprivate static final java.lang.String PHENOTYPE_FILE_PROPERTY_KEY
private static final java.lang.String MIND_FEEDBACK_KEY
private java.util.Properties reasonerProps
private org.drools.KnowledgeBase kbase
private org.drools.runtime.StatefulKnowledgeSession memory
private long startingAt
private java.util.Map<ReasonerDimension,org.drools.runtime.rule.FactHandle> factHandles
private java.util.Map<ReachabilityGroup,ReachabilityStatus> userFeedback
private java.util.Map<ReachabilityGroup,ReachabilityStatus> memoryStatus
updateProperties(Properties, Properties, ConfigType).private java.util.Map<ReachabilityGroup,java.lang.Long> lastFeedback
private long accessKey
setReachabilityStatus(ReachabilityGroup, ReachabilityStatus, long).public DroolsBasedEngine()
private void loadKBase()
private void setGlobal(java.lang.String name,
java.lang.Object value)
StatefulKnowledgeSession to a certain value.name - The name of the global variable within the StatefulKnowledgeSession as
String.value - The new value of the global as Object.private boolean globalExists(java.lang.String name)
StatefulKnowledgeSession or not.name - The name of the global variable as String.true if the global is defined, otherwise false.public final void cleanUp()
ReasonercleanUp in class ReasonerStopableObject.shutDown()public final void setSensorData(JsonReachabilitySensorData sensorData)
SensorData object to the StatefulKnowledgeSession or replaces the last known
SensorData of this dimension. The ReasonerDimension and the SensorData will be extracted
from the JsonReachabilitySensorData object.setSensorData in class ReasonersensorData - The JsonReachabilitySensorData which has been measured.public final void setReachabilityStatus(ReachabilityGroup group, ReachabilityStatus status, long accessKeyIn)
ReachabilityStatus of a certain ReachabilityGroup. It will only work,
if the correct accessKey is supplied. For this reason, the method can only be called by an internal method or the
drools rule base.group - A ReachabilityGroup.status - A ReachabilityStatus.accessKeyIn - The previously shared access key.public final void updateProperties(java.util.Properties newProps,
java.util.Properties changedProps,
ConfigType type)
PropertyServiceNotifiablePropertyService informs its creator, that there was a change of properties and that the creator
should update his properties according to the new ones.newProps - The actual defined and correct Properties set.changedProps - The changed Properties set.type - The properties type which shall be updated as ConfigType.PropertyServiceNotifiable.updateProperties(Properties, Properties, ConfigType)public final java.util.Properties loadCurrentProperties(ConfigType type)
PropertyServiceNotifiablePropertyService requests the actual properties of a certain ConfigType from its creator. The
creator should reload its local property set and return them to the PropertyService.type - Loads the current configuration of a certain type defined as ConfigType.Properties object.PropertyServiceNotifiable.loadCurrentProperties(ConfigType)public final java.util.Map<java.lang.String,java.lang.String> getValuesForProperty(java.lang.String property)
PropertyServiceNotifiableDisplayType.AGENT_DEFINED, which means that the value range is
dynamically defined at runtime. In this case, the PropertyService asks its creator about the current
value range of this property by using this method.property - The requested property as String.Map of String to String.PropertyServiceNotifiable.getValuesForProperty(String)public final java.util.Map<ReachabilityGroup,ReachabilityStatus> getEstimatedReachability()
ReasoningEngineMap of estimated ReachabilityStatus.ReasoningEngine.getEstimatedReachability()public final ReachabilityStatus getEstimatedReachability(ReachabilityGroup group)
ReasoningEnginegroup - The ReachabilityGroup for which the estimated ReachabilityStatus shall be
returned.ReachabilityStatus related to the requested ReachabilityGroup.ReasoningEngine.getEstimatedReachability(ReachabilityGroup)public final void handleFeedback(ReachabilityGroup group, ReachabilityStatus status)
group - The ReachabilityGroup for which the feedback has been given.status - The user expected ReachabilityStatus to this
ReachabilityGroup.public final void dump()
ReasoningEngineOutputUtil.info(String) method.ReasoningEngine.dump()public static void main(java.lang.String[] args)
ReasonerAgent.args - The system supplied start arguments as array of String.