<br><font size=2 face="sans-serif">Kris,</font>
<br>
<br><font size=2 face="sans-serif">Many thanks for your continued help.
I updated to the latest trunk, and replaced my milestone node with a state
node as suggested, and the process instance completed as required.</font>
<br>
<br><font size=2 face="sans-serif">Two things I noticed:</font>
<br>
<br><font size=2 face="sans-serif">1. The state node isn't currently available
in the palette of the Eclipse plug-in graphical editor - presumably it
will be in the final release of 5.1?</font>
<br>
<br><font size=2 face="sans-serif">2. If the ID of my process definition
contains a hyphen, then the process does not complete. If you change the
id in ruleflow.rf in the test case I sent you from "com.test.ruleflow"
to "com.test.ruleflow-x" (and change the argument to ksession.startProcess()
in PersistenceTest.java), you'll see that the process doesn't complete.
Any ideas as to why this is happening?<br>
</font>
<br><font size=2 face="sans-serif">Anyway, thank you again.</font>
<br>
<br><font size=2 face="sans-serif">Regards,</font>
<br>
<br><font size=2 face="sans-serif">Alan</font>
<p>
<br>
<br>
<br>
<table width=100%>
<tr valign=top>
<td width=40%><font size=1 face="sans-serif"><b>Kris Verlaenen <kris.verlaenen@cs.kuleuven.be></b>
</font>
<p><font size=1 face="sans-serif">07/11/2009 01:40</font>
<td width=59%>
<table width=100%>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">To</font></div>
<td><font size=1 face="sans-serif">Alan.Gairey@tessella.com</font>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">cc</font></div>
<td><font size=1 face="sans-serif">rules-users@lists.jboss.org</font>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">Subject</font></div>
<td><font size=1 face="sans-serif">Re: [rules-users] [droolsflow] Code-based
constraints for EventWait nodes - is this possible?</font></table>
<br>
<table>
<tr valign=top>
<td>
<td></table>
<br></table>
<br>
<br>
<br><tt><font size=2>Alan,<br>
<br>
The problem you are seeing is caused by the fact that you are retrieving<br>
the process instance in the work item manager. There's nothing wrong<br>
with that, but there is an issue that the process instance that is being<br>
executed was not yet registered, so the process instance will be<br>
retrieved from db, but this is the old version.<br>
<br>
Also note that you should try the new state node instead of the old<br>
milestone node (aka event wait node), as the new state node is more<br>
powerful but also offers the same features as the milestone node. For<br>
example, your milestone node would be the same as:<br>
<state id="10" name="Retry?" x="382"
y="164" width="80" height="40" ><br>
<constraints><br>
<constraint toNodeId="9" name="retry"
priority="1"<br>
>SimpleFact(retry == true)</constraint><br>
</constraints><br>
</state><br>
<br>
Updating to the latest trunk and using the state node should fix your issue.<br>
<br>
Kris<br>
<br>
Quoting Alan.Gairey@tessella.com:<br>
<br>
> Kris,<br>
> <br>
> Thanks yes - the null check fixes the NPE I was seeing.<br>
> <br>
> Unfortunately, I now have a more difficult problem. In my work item
<br>
> handler, I use the following code to get the ID of a work item in
the<br>
> rule <br>
> flow (i.e. the .rf file itself) given a <br>
> org.drools.runtime.process.WorkItem instance:<br>
> <br>
> private long getCurrentNodeId(WorkItem workItem) {<br>
> ProcessInstance processInstance = <br>
> ksession.getProcessInstance(workItem.getProcessInstanceId());<br>
> if (processInstance instanceof WorkflowProcessInstanceImpl)<br>
> {<br>
> Collection<NodeInstance>
nodeInstances = <br>
> ((WorkflowProcessInstanceImpl) processInstance).getNodeInstances();<br>
> for (NodeInstance nodeInstance
: nodeInstances) {<br>
> System.out.println(String.format("Node
instance: %s",<br>
> <br>
> nodeInstance));<br>
> if (nodeInstance
instanceof WorkItemNodeInstance) {<br>
>
WorkItemNodeInstance workItemNodeInstance = <br>
> (WorkItemNodeInstance) nodeInstance;<br>
>
if (workItemNodeInstance.getWorkItem() ==<br>
> workItem) {<br>
>
return workItemNodeInstance.getNodeId();<br>
>
}<br>
> }<br>
> }<br>
> }<br>
> throw new RuntimeException(String.format("Error
determining<br>
> node <br>
> ID for work item: %s", workItem.toString()));<br>
> }<br>
> The work item in the attached test case, the first time it executes<br>
> sets a <br>
> property on a fact in memory that causes a subsequent Split node to<br>
> send <br>
> the flow to an Event Wait. The code in the overall main() method (in<br>
> <br>
> PersistenceTest.java) then updates the fact in memory so that the<br>
> Event <br>
> Wait's constraint is satisfied, and the work item node is executed<br>
> again. <br>
> The second time around, it sets the property on the fact in memory
so<br>
> that <br>
> the subsequent Split node sends the flow to its end. (I hope this<br>
> makes <br>
> sense; looking at the rule flow in the test case should show you what<br>
> I'm <br>
> trying to do.)<br>
> <br>
> If I execute the test case with my session created using the code:<br>
> StatefulKnowledgeSession ksession =<br>
> kbase.newStatefulKnowledgeSession();<br>
> everything works as I would expect, and the output from the <br>
> System.out.println() statement in my getCurrentNodeId() method above<br>
> is:<br>
> Node instance: <br>
> org.drools.workflow.instance.node.WorkItemNodeInstance@125d568<br>
> Node instance: <br>
> org.drools.workflow.instance.node.WorkItemNodeInstance@37a04c<br>
> <br>
> However, if I use JPA persistence:<br>
> StatefulKnowledgeSession ksession = <br>
> JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);<br>
> then the RuntimeException in getCurrentNodeId() is thrown, and the<br>
> output <br>
> is:<br>
> Node instance: <br>
> org.drools.workflow.instance.node.WorkItemNodeInstance@2209db<br>
> Node instance: <br>
> org.drools.workflow.instance.node.MilestoneNodeInstance@d8fd1a<br>
> Somehow it seems as though the node instance isn't quite synchronised<br>
> with <br>
> the overall state when using JPA persistence.<br>
> Any help you could give me here would be very much appreciated.<br>
> Regards,<br>
> Alan<br>
> <br>
> <br>
> <br>
> <br>
> Kris Verlaenen <kris.verlaenen@cs.kuleuven.be> <br>
> 30/10/2009 20:10<br>
> <br>
> To<br>
> Alan.Gairey@tessella.com<br>
> cc<br>
> <br>
> Subject<br>
> Re: [rules-users] [droolsflow] Code-based constraints for EventWait<br>
> nodes <br>
> - is this possible?<br>
> <br>
> <br>
> <br>
> <br>
> <br>
> <br>
> Alan, <br>
> <br>
> Thanks, this indeed seems to be the issue. I have changed this
on<br>
> trunk. Does adding this null check solve your issue?<br>
> <br>
> Thx,<br>
> Kris<br>
> <br>
> Quoting Alan.Gairey@tessella.com:<br>
> <br>
> > Kris,<br>
> > <br>
> > Some more information: the NullPointerException from<br>
> GetObjectCommand<br>
> > is <br>
> > thrown by the line:<br>
> > <br>
> > <br>
> ><br>
><br>
((StatefulKnowledgeSessionImpl)ksession).session.getExecutionResult().getResults().put(<br>
> > <br>
> > this.outIdentifier,<br>
> >
object );<br>
> > <br>
> > Method getExecutionResult() is returning null. Debugging my test<br>
> > case, I <br>
> > also notice that this.outIdentifier is also null.<br>
> > <br>
> > I then had a look at the GetObjectsCommand class; in its execute<br>
> > method, <br>
> > there is a line similar to that above. However, it is contained<br>
> > within an <br>
> > if block that checks this.outIdentifier is not null:<br>
> > <br>
> > if ( this.outIdentifier != null )
{<br>
> > List objects = new
ArrayList( col );<br>
> > <br>
> > <br>
> ><br>
><br>
((StatefulKnowledgeSessionImpl)ksession).session.getExecutionResult().getResults().put(<br>
> > <br>
> > this.outIdentifier, objects );<br>
> > }<br>
> > <br>
> > If something similar was done in GetObjectCommand, presumably
this<br>
> > would <br>
> > fix my problem?<br>
> > <br>
> > Hope this is of some use - regards,<br>
> > <br>
> > Alan<br>
> > <br>
> > <br>
> > <br>
> > <br>
> > Alan.Gairey@tessella.com <br>
> > Sent by: rules-users-bounces@lists.jboss.org<br>
> > 29/10/2009 17:35<br>
> > Please respond to<br>
> > Rules Users List <rules-users@lists.jboss.org><br>
> > <br>
> > <br>
> > To<br>
> > Kris Verlaenen <kris.verlaenen@cs.kuleuven.be><br>
> > cc<br>
> > Rules Users List <rules-users@lists.jboss.org><br>
> > Subject<br>
> > Re: [rules-users] [droolsflow] Code-based constraints for<br>
> EventWait<br>
> > nodes <br>
> > - is this possible?<br>
> > <br>
> > <br>
> > <br>
> > <br>
> > <br>
> > <br>
> > <br>
> > Kris,<br>
> > <br>
> > Thanks - making the class SimpleFact serializable fixed that
error.<br>
> <br>
> > <br>
> > However, I now have a new problem: I have a rule flow containing
a<br>
> > work <br>
> > item - the handler attempts to update the SimpleFact instance
in<br>
> > memory <br>
> > before completing the task. The code in the executeWorkItem method<br>
> is<br>
> > as <br>
> > follows: <br>
> > <br>
> > Collection<FactHandle> factHandles
=<br>
> > ksession.getFactHandles(new <br>
> > ObjectFilter() { <br>
> > public boolean accept(Object
object) { <br>
> > return
(object instanceof SimpleFact); <br>
> > } <br>
> > }); <br>
> > for (Iterator<FactHandle> iterator
=<br>
> factHandles.iterator();<br>
> > <br>
> > iterator.hasNext(); ) { <br>
> > FactHandle factHandle
= iterator.next(); <br>
> > SimpleFact fact = (SimpleFact)<br>
> > ksession.getObject(factHandle); <br>
> > <br>
> > fact.setStatus("Error");
<br>
> > ksession.update(factHandle,
fact); <br>
> > } <br>
> > <br>
> > workItemManager.completeWorkItem(workItem.getId(),
null); <br>
> > <br>
> > The call to getObject() causes the following exception to be<br>
> thrown:<br>
> > <br>
> > <br>
> > java.lang.NullPointerException <br>
> > at <br>
> ><br>
><br>
org.drools.command.runtime.rule.GetObjectCommand.execute(GetObjectCommand.java:35)<br>
> > <br>
> > <br>
> > at <br>
> ><br>
><br>
org.drools.persistence.session.SingleSessionCommandService.execute(SingleSessionCommandService.java:254)<br>
> > <br>
> > <br>
> > at <br>
> ><br>
><br>
org.drools.command.impl.CommandBasedStatefulKnowledgeSession.getObject(CommandBasedStatefulKnowledgeSession.java:369)<br>
> > <br>
> > <br>
> > at <br>
> ><br>
><br>
com.test.StatusChangeWorkItemHandler.executeWorkItem(StatusChangeWorkItemHandler.java:37)<br>
> > <br>
> > <br>
> > ... <br>
> > <br>
> > I've attached another test case to illustrate the problem. <br>
> > <br>
> > <br>
> > <br>
> > Once again, my sincere thanks for helping me with this. <br>
> > <br>
> > Regards, <br>
> > <br>
> > Alan <br>
> > <br>
> > <br>
> > <br>
> > Kris Verlaenen <kris.verlaenen@cs.kuleuven.be> <br>
> > 29/10/2009 12:00 <br>
> > <br>
> > <br>
> > To<br>
> > Alan.Gairey@tessella.com <br>
> > cc<br>
> > Rules Users List <rules-users@lists.jboss.org> <br>
> > Subject<br>
> > Re: [rules-users] [droolsflow] Code-based constraints for<br>
> EventWait<br>
> > nodes <br>
> > - is this possible?<br>
> > <br>
> > <br>
> > <br>
> > <br>
> > <br>
> > <br>
> > <br>
> > <br>
> > Alan,<br>
> > <br>
> > The cause of the rollback of the transaction is this:<br>
> > Caused by: java.io.NotSerializableException: com.test.SimpleFact<br>
> > <br>
> > The reason is that, if you use persistence for your session,
the<br>
> > persister will try to save all runtime state of the engine. This<br>
> > does<br>
> > not only include process instances, but also rule-related state.
<br>
> By<br>
> > default, this also includes the data inserted in the memory.
We<br>
> > support<br>
> > two strategies for storing this data: serialization of the data<br>
> > (default) or JPA-based storage of entities (by reference). In<br>
> this<br>
> > case, the persister is trying to serialize the test object you<br>
> > inserted<br>
> > and fails. Making it serializable should fix this.<br>
> > <br>
> > Kris<br>
> > <br>
> > Quoting Alan.Gairey@tessella.com:<br>
> > <br>
> > > Kris,<br>
> > > <br>
> > > I've attached a simple test case (transaction manager, data<br>
> > source,<br>
> > > etc. <br>
> > > are configured via Spring). The error is thrown on line:<br>
> > > <br>
> > > ksession.insert(new SimpleFact());<br>
> > > <br>
> > > If this line is commented out, the rule flow executes without<br>
> > error.<br>
> > > <br>
> > > <br>
> > > <br>
> > > Many thanks for looking at this.<br>
> > > <br>
> > > Regards,<br>
> > > <br>
> > > Alan<br>
> > > <br>
> > > <br>
> > > <br>
> > > <br>
> > > Kris Verlaenen <kris.verlaenen@cs.kuleuven.be> <br>
> > > 28/10/2009 10:40<br>
> > > <br>
> > > To<br>
> > > Alan.Gairey@tessella.com<br>
> > > cc<br>
> > > Rules Users List <rules-users@lists.jboss.org><br>
> > > Subject<br>
> > > Re: [rules-users] [droolsflow] Code-based constraints for<br>
> > EventWait<br>
> > > nodes <br>
> > > - is this possible?<br>
> > > <br>
> > > <br>
> > > <br>
> > > <br>
> > > <br>
> > > <br>
> > > Alan,<br>
> > > <br>
> > > Could you send me the entire output / stack trace (as the<br>
> rollback<br>
> > > of<br>
> > > the transaction is usually caused by another exception)?<br>
> > > <br>
> > > Or a simple test case that shows the error, so I can take
a<br>
> look?<br>
> > > <br>
> > > Thx,<br>
> > > Kris<br>
> > > <br>
> > > Quoting Alan.Gairey@tessella.com:<br>
> > > <br>
> > > > Kris,<br>
> > > > <br>
> > > > After posting my last question, I quickly came to the
same<br>
> > > conclusion<br>
> > > > as <br>
> > > > you, so I'm now using a rule-based constraint in my
EventWait<br>
> > > node.<br>
> > > > <br>
> > > > This however has presented a different problem. If
I create my<br>
> > > > session <br>
> > > > from JPAKnowledgeService, then when I try to insert
my fact<br>
> into<br>
> > > the<br>
> > > > <br>
> > > > session, I get the following error:<br>
> > > > <br>
> > > > bitronix.tm.internal.BitronixRollbackException: transaction<br>
> was<br>
> > > > marked as <br>
> > > > rollback only and has been rolled back<br>
> > > > at <br>
> > > ><br>
> > ><br>
> ><br>
> bitronix.tm.BitronixTransaction.commit(BitronixTransaction.java:153)<br>
> > > > at <br>
> > > ><br>
> > ><br>
> ><br>
><br>
bitronix.tm.BitronixTransactionManager.commit(BitronixTransactionManager.java:96)<br>
> > > > at <br>
> > > ><br>
> > ><br>
> ><br>
><br>
org.drools.persistence.session.SingleSessionCommandService.execute(SingleSessionCommandService.java:258)<br>
> > > > at <br>
> > > ><br>
> > ><br>
> ><br>
><br>
org.drools.command.impl.CommandBasedStatefulKnowledgeSession.insert(CommandBasedStatefulKnowledgeSession.java:305)<br>
> > > > (Everything works fine if I create my session from
the<br>
> knowledge<br>
> > > base<br>
> > > > - <br>
> > > > i.e. with no state persistence.)<br>
> > > > Prior to using a rule-based constraint (with no call
to <br>
> > > > CommandBasedStatefulKnowledgeSession.insert), the session<br>
> > created<br>
> > > > from <br>
> > > > JPAKnowledgeService worked OK.<br>
> > > > I'm using the default JPA configuration from the Drools<br>
> > > documentation<br>
> > > > <br>
> > > > (persisting to H2 database, etc.).<br>
> > > > Any ideas what might be causing the problem?<br>
> > > > Many thanks,<br>
> > > > Alan<br>
> > > > <br>
> > > > <br>
> > > > <br>
> > > > <br>
> > > > Kris Verlaenen <kris.verlaenen@cs.kuleuven.be>
<br>
> > > > 23/10/2009 03:00<br>
> > > > <br>
> > > > To<br>
> > > > Rules Users List <rules-users@lists.jboss.org>,<br>
> > > > Alan.Gairey@tessella.com<br>
> > > > cc<br>
> > > > Rules Users List <rules-users@lists.jboss.org><br>
> > > > Subject<br>
> > > > Re: [rules-users] [droolsflow] Code-based constraints
for<br>
> > > EventWait<br>
> > > > nodes <br>
> > > > - is this possible?<br>
> > > > <br>
> > > > <br>
> > > > <br>
> > > > <br>
> > > > <br>
> > > > <br>
> > > > No, the constraint of an EventWait node (or the State
node in<br>
> > > Drools<br>
> > > > 5.1) can only be rule-based. The reason for this
is that the<br>
> > rule<br>
> > > > engine knows when to re-evaluates rules (based on the<br>
> evailable<br>
> > > > input).<br>
> > > > If you would use a code-based constraint, the
engine would<br>
> have<br>
> > > no<br>
> > > > idea<br>
> > > > when this code constraint might become true (if it
was false<br>
> at<br>
> > > the<br>
> > > > start). Only constant re-evaluation of the code
constraint<br>
> > could<br>
> > > > achieve this (which would be tremendously inefficient).
Could<br>
> > you<br>
> > > > explain why you would like to have this behaviour?
Maybe<br>
> there<br>
> > is<br>
> > > > an<br>
> > > > alternative way to model this.<br>
> > > > <br>
> > > > To change the value of a variable from inside the process<br>
> (using<br>
> > > an<br>
> > > > action), simply use kcontext.setVariable(name, value).
We do<br>
> > not<br>
> > > > recommend manually changing the value of a process
variable<br>
> from<br>
> > > > outside<br>
> > > > the engine. Again, could you explain why you
would like to<br>
> have<br>
> > > > this<br>
> > > > functionality?<br>
> > > > <br>
> > > > Kris<br>
> > > > <br>
> > > > Quoting Alan.Gairey@tessella.com:<br>
> > > > <br>
> > > > > Can the constraint for an EventWait node in a
flow be<br>
> > code-based<br>
> > > > > (rather <br>
> > > > > than rule-based)? The Eclipse plug-in (v 5.0.1)
doesn't<br>
> allow<br>
> > > this<br>
> > > > to<br>
> > > > > be <br>
> > > > > specified, unlike say for a Split node, although
the<br>
> relevant<br>
> > > XML<br>
> > > > can<br>
> > > > > of <br>
> > > > > course be edited.<br>
> > > > > Trying to load such a process flow results in
a<br>
> > > > NullPointerException,<br>
> > > > > <br>
> > > > > because the constraint is always interpreted as
a rule.<br>
> > > > > <br>
> > > > > Ideally what I'd like to do is have an EventWait
node where<br>
> > the<br>
> > > > > constraint <br>
> > > > > tests the value of a process variable. This then
leads me to<br>
> > > > another<br>
> > > > > <br>
> > > > > question; is there a way of setting the value
of a process<br>
> > > > variable<br>
> > > > > via <br>
> > > > > the Drools Flow API?<br>
> > > > > <br>
> > > > > Thanks in advance for any help,<br>
> > > > > <br>
> > > > > Alan<br>
> > > > > Tessella plc<br>
> > > > > 26 The Quadrant, Abingdon Science Park, Abingdon,<br>
> Oxfordshire,<br>
> > > > OX14<br>
> > > > > 3YS<br>
> > > > > E: Alan.Gairey@tessella.com, T: +44 (0)1235 555511,
F: +44<br>
> > > (0)1235<br>
> > > > > 553301<br>
> > > > > www.tessella.com Registered in England
No. 1466429<br>
> > > > > <br>
> > > > > This message is commercial in confidence and may
be<br>
> > privileged.<br>
> > > It<br>
> > > > is<br>
> > > > > <br>
> > > > > intended for the addressee(s) only. Access to
this message<br>
> by<br>
> > > > anyone<br>
> > > > > else <br>
> > > > > is unauthorized and strictly prohibited. If you
have<br>
> received<br>
> > > this<br>
> > > > > message <br>
> > > > > in error, please inform the sender immediately.
Please note<br>
> > that<br>
> > > > > messages <br>
> > > > > sent or received by the Tessella e-mail system
may be<br>
> > monitored<br>
> > > > and<br>
> > > > > stored <br>
> > > > > in an information retrieval system.<br>
> > > > > <br>
> > > > <br>
> > > > <br>
> > > > <br>
> > > > <br>
> > > > Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm<br>
> > > > <br>
> > > > <br>
> > > <br>
> > > <br>
> > > <br>
> > > <br>
> > > Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm<br>
> > > <br>
> > > <br>
> > <br>
> > <br>
> > <br>
> > <br>
> > Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm<br>
> > [attachment "drools-persistence-test.zip" deleted by
Alan<br>
> > Gairey/Tessella] <br>
> > _______________________________________________<br>
> > rules-users mailing list<br>
> > rules-users@lists.jboss.org<br>
> > https://lists.jboss.org/mailman/listinfo/rules-users<br>
> > <br>
> > </font></tt>
<br><tt><font size=2>> <br>
> <br>
> <br>
> <br>
> Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm<br>
> <br>
> <br>
<br>
<br>
<br>
<br>
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm<br>
</font></tt>
<br>