[rules-users] duration attribute & other rule language features issue
Wolfgang Laun
wolfgang.laun at gmail.com
Tue Nov 29 08:06:12 EST 2011
I see you are using a pseudo-clock. Do you advance the clock using the
appropriate API call?
Updating and retracting a fact inserted through an entry point should
be done with methods called on this object.
-W
On 29 November 2011 13:56, prashant.badhe <prashant.badhe at gmail.com> wrote:
> Hi,
>
> Tried your rule with the code below, but no luck.
>
> I am using only one rule, so the fact remains in drools session for
> sufficient time (> 5 s). Even if I uncomment the /thread.sleep(60000)/ line
> below, the rule does not trigger.
>
> ~~~~~~~~~~~~~~~~~~
> public class DroolsTest {
>
> static StatefulKnowledgeSession ksession = null;
> static KnowledgeRuntimeLogger logger = null;
>
> public static final void main(String[] args) {
> try {
> initSession();
> testTimerAttribute();
> } catch (Throwable t) {
> t.printStackTrace();
> }
> }
>
> private static void testTimerAttribute() {
>
> Alert alert = new Alert();
> alert.setId(12345L);
> alert.setType("TYPE");
> alert.setComponentId("XXX");
> WorkingMemoryEntryPoint entryPoint =
> ksession.getWorkingMemoryEntryPoint("EventStream");
> entryPoint.insert(alert);
>
> System.out.println("inserted...Count: " + entryPoint.getFactCount());
> //Count returned = 1
>
> try {
> //Thread.sleep(60000);
> } catch (Exception ex) {
> System.out.println("Exception...");
> }
>
> Alert alert1 = new Alert();
> alert1.setId(99991L);
> alert1.setType("LINK_UP");
> alert1.setComponentId("ZZZ");
> entry.insert(alert1);
> System.out.println("inserted again...Count: " + entry.getFactCount());
> //Count returned = 2
>
> logger.close();
>
> }
>
> private static void initSession() {
>
> new Thread(new Runnable() {
> public void run() {
> try {
> System.out.println("Inside initSession()...");
> KnowledgeBase kbase = readKnowledgeBase();
> KnowledgeSessionConfiguration conf =
> KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
> conf.setOption( ClockTypeOption.get( "pseudo" ) );
> ksession = kbase.newStatefulKnowledgeSession(conf, null);
> logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession,
> "test");
> ksession.fireUntilHalt();
> } catch (Exception t) {
> System.out.println("Inside thread init() error..." +
> t.getMessage() + "#########" + t.getStackTrace());
> }
> }
> }).start();
>
> }
>
> }
>
>
> And the rule is:
>
> rule "check timer attribute"
> agenda-group "enrichment"
> auto-focus true
> no-loop
> salience 140
> //timer (int: 5s 1s)
>
> when
> $alertObj : Object( eval($alertObj instanceof Alert)) from entry-point
> "EventStream"
> $alert : Alert( componentId == "XXX" ) from entry-point "EventStream"
> then
> try {
> System.out.println("[enrichment] nullify empty component id [alert=" +
> ((Alert)$alertObj).getId() + "] [Time: " +
> (Calendar.getInstance().getTimeInMillis()));
> //$alert.setType("test type");
> //$alert.setComponentId("YYY");
> //update($alert);
> } catch (Throwable e) {
> System.out.println("[enrichment] ############## ERROR: nullify empty
> component id [alertId="); // + $alert.getId() + "][error=" + e.toString() +
> "]");
> }
> end
>
>
> ~~~~~~~~~~~~~~~~~~
>
> Please suggest us some solution on timer() issue .
>
> One more thing I observed today is (without timer() off course), when I put
> following 3 lines in RHS of rule:
> /$alert.setType("test type");
> $alert.setComponentId("YYY");
> update($alert);/
>
> then sometimes I get following exception at /update($alert)/:
> *java.lang.ClassCastException: org.drools.common.DefaultFactHandle cannot be
> cast to org.drools.common.EventFactHandle*
> org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:201)
> org.drools.reteoo.EntryPointNode.assertObject(EntryPointNode.java:145)
> org.drools.common.NamedEntryPoint.update(NamedEntryPoint.java:251)
> org.drools.base.DefaultKnowledgeHelper.update(DefaultKnowledgeHelper.java:183)
> org.drools.base.DefaultKnowledgeHelper.update(DefaultKnowledgeHelper.java:196)
> abc.xyz.alertProcessor.Rule_check_timer_attribute_0.defaultConsequence(Rule_check_timer_attribute_0.java:27)
> abc.xyz.alertProcessor.Rule_check_timer_attribute_0DefaultConsequenceInvoker.evaluate(Rule_check_timer_attribute_0DefaultConsequenceInvoker.java:35)
> org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:917)
> org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:856)
> org.drools.common.DefaultAgenda.fireUntilHalt(DefaultAgenda.java:1049)
> org.drools.common.AbstractWorkingMemory.fireUntilHalt(AbstractWorkingMemory.java:829)
> org.drools.common.AbstractWorkingMemory.fireUntilHalt(AbstractWorkingMemory.java:805)
> org.drools.impl.StatefulKnowledgeSessionImpl.fireUntilHalt(StatefulKnowledgeSessionImpl.java:230)
>
> Does this mean, modifying value of fact members in RHS is not expected? , &
> if modified then drools may not find that object in its pool for update() &
> retract() (based on the EventFactHandle)?
>
> - Prashant
>
> --
> View this message in context: http://drools.46999.n3.nabble.com/rules-users-duration-attribute-other-rule-language-features-issue-tp3536857p3545080.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
More information about the rules-users
mailing list