[rules-users] Timer does not return!

Ajay.Gautam at rbs.com Ajay.Gautam at rbs.com
Mon Jun 8 14:47:16 EDT 2009


Thanks for the sample code Kris. It seems that the problem is not with the Timer itself, but with WorkItemHadler !

(Complete code - extended version of your code - is attached). Adding a "Log" work item between START and the first Action breaks the code. If I remove the Log item, the flow works as expected. Here is the code that runs in executeWorkItem:

    logger.info("=== message from flow ===>> "+ workItem.getParameter("Message"));
    manager.completeWorkItem(workItem.getId(), null);
    logger.info("Work item completed!");

the 2nd log message is not displayed!

Any ideas what am I doing wrong?



Second issue: The process does not end! - I took Kris's code and ran it. Even after the work flow completed, the process was still alive! (End Node's Terminate Property *is* set to "true").


Thanks

Ajay


-----Original Message-----
From: Kris Verlaenen [mailto:Kris.Verlaenen at cs.kuleuven.be] 
Sent: Friday, June 05, 2009 5:08 PM
To: Rules Users List; Gautam, Ajay, GBM
Cc: rules-users at lists.jboss.org
Subject: Re: [rules-users] Timer does not return!

It's difficult to figure out what's going on without looking at the
process itself, but your code seems to be fine.  If you run the engine
in reactive mode (using fireUntilHalt), it should automatically fire the
action associated with the timer once it goes off.  Note that, if you
are not running in reactive mode, the timer is also triggered (it
doesn't just run through), but it'll wait to execute the associated
action until fireAllRules is called.

For example, this simple process is a timer followed by an action
writing out when the timer is being triggered.

<?xml version="1.0" encoding="UTF-8"?> 
<process xmlns="http://drools.org/drools-5.0/process"
         xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
         xs:schemaLocation="http://drools.org/drools-5.0/process
drools-processes-5.0.xsd"
         type="RuleFlow" name="ruleflow" id="com.sample.ruleflow"
package-name="com.sample" >

  <header>
  </header>

  <nodes>
    <start id="1" name="Start" x="16" y="16" width="80" height="40" />
    <timerNode id="4" name="Timer" x="128" y="16" width="80" height="40"
delay="2000" />
    <actionNode id="2" name="Action" x="240" y="16" width="80" height="40" >
        <action type="expression" dialect="mvel"
>System.out.println("Executing");</action>
    </actionNode>
    <end id="3" name="End" x="352" y="16" width="80" height="40" />
  </nodes>

  <connections>
    <connection from="1" to="4" />
    <connection from="4" to="2" />
    <connection from="2" to="3" />
  </connections>

</process>

By using the following code, the action is written out immediately when
the timer triggers (after 2 seconds):

public static final void main(String[] args) {
  try {
    // load up the knowledge base
    KnowledgeBase kbase = readKnowledgeBase();
    final StatefulKnowledgeSession ksession =
kbase.newStatefulKnowledgeSession();
    new Thread(new Runnable() {
      public void run() {
        ksession.fireUntilHalt();
      }
    }).start();
    // start a new process instance
    ksession.startProcess("com.sample.ruleflow");
  } catch (Throwable t) {
    t.printStackTrace();
  }
}

The following code doesn't use reactive mode, so the action associated
with the timer is only triggered during the next fireAllRules (after 4
seconds).

public static final void main(String[] args) {
  try {
    // load up the knowledge base
    KnowledgeBase kbase = readKnowledgeBase();
    final StatefulKnowledgeSession ksession =
kbase.newStatefulKnowledgeSession();
    // start a new process instance
    ksession.startProcess("com.sample.ruleflow");
    Thread.sleep(4000);
    ksession.fireAllRules();
  } catch (Throwable t) {
    t.printStackTrace();
  }
}

Hope this clears up the situation a little more.  If you still have
problems integrating timers in your process, could you send a standalone
example (containing both the process xml and the Java code)?

Thx,
Kris

Quoting Ajay.Gautam at rbs.com:

> I have a timer in my code that does not return. It just hangs the
> process (with no CPU activity).
> 
> Any idea what may be causing this?
> 
> The timer delay is 2000 ms. Based on the docs, here are code
> snippets:
> 
> 
> .......
> 	ksession = kbase.newStatefulKnowledgeSession();
> 	new Thread(new Runnable() {
> 	    public void run() {
> 	      ksession.fireUntilHalt();
> 	    }
> 	  }).start();
> ........
> 	final RFQRequest req = createRequest();
> 	parameters.put("rfqIn", req);
> 	ksession.setGlobal("reqTag", req.getTag());
> 	ksession.startProcess("com.rbs.gbm.pm.RFQ-WorkFlow", parameters);
> ........
> 
> If I remove the fireUntilHalt thread, the timer is not triggered at
> all. The flow just passes through it lilke its not even there.
> 
> Any help / info / pointers will be appreciated.
> 
> Thanks
> 
> Ajay
> 
> *****Please note that my email address may have changed. For all
> future correspondence, please use this address*****
> 
> 
> ********************************************************************This
> message (including any attachments) is confidential and/or
> privileged. It is to be used by the intended recipients only. If
> you have received it by mistake please notify the sender by return
> e-mail and delete this message from your system. Any unauthorized
> use or dissemination of this message in whole or in part is
> strictly prohibited. Please note that e-mails are inherently
> insecure and susceptible to change. The Royal Bank of Scotland
> Group, plc ("RBS") and its US subsidiaries, and affiliates and
> subsidiary undertakings, including but not limited to, RBS plc New
> York and Connecticut Branches, RBS Securities Inc., ABN AMRO Bank
> N.V. New York and Chicago Branches and, ABN AMRO Incorporated,
> Citizens Financial Group, Inc. and RBS Citizens, N.A., shall not be
> liable for the improper or incomplete transmission of the
> information contained in this communication or Attachment nor for
> any delay in its receipt or damage to your system. RBS does not
> guarantee that the integrity of this communication has been
> maintained nor that this communication is free of viruses,
> interceptions or interference. RBS and its subsidiaries and
> affiliates do not guarantee the accuracy of any email or
> attachment, that an email will be received or that RBS or its
> affiliates and subsidiaries will respond to an email.
> 
> RBS makes no representations that any information contained in this
> message (including any attachments) are appropriate for use in all
> locations or that transactions, securities, products, instruments
> or services discussed herein are available or appropriate for sale
> or use in all jurisdictions, or by all investors or counterparties.
> Those who utilize this information do so on their own initiative
> and are responsible for compliance with applicable local laws or
>
regulations.********************************************************************
> 
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
> 




Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: MyTimerTest.java
Type: application/octet-stream
Size: 2709 bytes
Desc: MyTimerTest.java
Url : http://lists.jboss.org/pipermail/rules-users/attachments/20090608/04180c96/attachment.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: my-timer.rf
Type: application/octet-stream
Size: 1569 bytes
Desc: my-timer.rf
Url : http://lists.jboss.org/pipermail/rules-users/attachments/20090608/04180c96/attachment-0001.obj 


More information about the rules-users mailing list