<br><font size=2 face="sans-serif">Kris,</font>
<br>
<br><font size=2 face="sans-serif">Some more information: the NullPointerException
from GetObjectCommand is thrown by the line:</font>
<br>
<br><tt><font size=2>&nbsp; &nbsp; &nbsp; &nbsp; ((StatefulKnowledgeSessionImpl)ksession).session.getExecutionResult().getResults().put(
this.outIdentifier,<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; object );<br>
</font></tt><font size=2 face="sans-serif"><br>
Method getExecutionResult() is returning null. Debugging my test case,
I also notice that this.outIdentifier is also null.</font>
<br>
<br><font size=2 face="sans-serif">I then had a look at the GetObjectsCommand
class; in its execute method, there is a line similar to that above. However,
it is contained within an if block that checks this.outIdentifier is not
null:</font>
<br>
<br><tt><font size=2>&nbsp; &nbsp; &nbsp; &nbsp; if ( this.outIdentifier
!= null ) {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;List objects = new ArrayList(
col );<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;((StatefulKnowledgeSessionImpl)ksession).session.getExecutionResult().getResults().put(
this.outIdentifier, objects );<br>
 &nbsp; &nbsp; &nbsp; &nbsp;}<br>
</font></tt>
<br><font size=2 face="sans-serif">If something similar was done in GetObjectCommand,
presumably this would fix my problem?</font>
<br>
<br><font size=2 face="sans-serif">Hope this is of some use - 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>Alan.Gairey@tessella.com</b>
</font>
<br><font size=1 face="sans-serif">Sent by: rules-users-bounces@lists.jboss.org</font>
<p><font size=1 face="sans-serif">29/10/2009 17:35</font>
<table border>
<tr valign=top>
<td bgcolor=white>
<div align=center><font size=1 face="sans-serif">Please respond to<br>
Rules Users List &lt;rules-users@lists.jboss.org&gt;</font></div></table>
<br>
<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">Kris Verlaenen &lt;kris.verlaenen@cs.kuleuven.be&gt;</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 List &lt;rules-users@lists.jboss.org&gt;</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><font size=2 face="sans-serif"><br>
Kris,</font><font size=3><br>
</font><font size=2 face="sans-serif"><br>
Thanks - making the class SimpleFact serializable fixed that error.</font><font size=3>
<br>
</font><font size=2 face="sans-serif"><br>
However, I now have a new problem: I have a rule flow containing a work
item - the handler attempts to update the SimpleFact instance in memory
before completing the task. The code in the executeWorkItem method is as
follows:</font><font size=3> <br>
</font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp; &nbsp; &nbsp;Collection&lt;FactHandle&gt; factHandles =
ksession.getFactHandles(new ObjectFilter() {</font><font size=3> </font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;public boolean accept(Object
object) {</font><font size=3> </font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return (object
instanceof SimpleFact);</font><font size=3> </font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</font><font size=3> </font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp; &nbsp; &nbsp;});</font><font size=3> </font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp; &nbsp; &nbsp;for (Iterator&lt;FactHandle&gt; iterator =
factHandles.iterator(); iterator.hasNext(); ) {</font><font size=3> </font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FactHandle factHandle = iterator.next();</font><font size=3>
</font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SimpleFact fact = (SimpleFact)
ksession.getObject(factHandle);</font><font size=3> </font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fact.setStatus(&quot;Error&quot;);</font><font size=3>
</font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ksession.update(factHandle, fact);</font><font size=3>
</font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp; &nbsp; &nbsp;}</font><font size=3> <br>
</font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp; &nbsp; &nbsp;workItemManager.completeWorkItem(workItem.getId(),
null);</font><font size=3> <br>
</font><font size=2 face="sans-serif"><br>
The call to getObject() causes the following exception to be thrown:</font><font size=3>
<br>
</font><font size=2 face="sans-serif"><br>
java.lang.NullPointerException</font><font size=3> </font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp; &nbsp; &nbsp;at org.drools.command.runtime.rule.GetObjectCommand.execute(GetObjectCommand.java:35)</font><font size=3>
</font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp; &nbsp; &nbsp;at org.drools.persistence.session.SingleSessionCommandService.execute(SingleSessionCommandService.java:254)</font><font size=3>
</font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp; &nbsp; &nbsp;at org.drools.command.impl.CommandBasedStatefulKnowledgeSession.getObject(CommandBasedStatefulKnowledgeSession.java:369)</font><font size=3>
</font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp; &nbsp; &nbsp;at com.test.StatusChangeWorkItemHandler.executeWorkItem(StatusChangeWorkItemHandler.java:37)</font><font size=3>
</font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp; &nbsp; &nbsp;...</font><font size=3> <br>
</font><font size=2 face="sans-serif"><br>
I've attached another test case to illustrate the problem.</font><font size=3>
<br>
<br>
<br>
</font><font size=2 face="sans-serif"><br>
Once again, my sincere thanks for helping me with this.</font><font size=3>
<br>
</font><font size=2 face="sans-serif"><br>
Regards,</font><font size=3> <br>
</font><font size=2 face="sans-serif"><br>
Alan</font><font size=3> </font>
<p><font size=3><br>
<br>
</font>
<table width=100%>
<tr valign=top>
<td width=37%><font size=1 face="sans-serif"><b>Kris Verlaenen &lt;kris.verlaenen@cs.kuleuven.be&gt;</b>
</font>
<p><font size=1 face="sans-serif">29/10/2009 12:00</font><font size=3>
</font>
<td width=62%>
<br>
<table width=100%>
<tr valign=top>
<td width=8%>
<div align=right><font size=1 face="sans-serif">To</font></div>
<td width=91%><font size=1 face="sans-serif">Alan.Gairey@tessella.com</font><font size=3>
</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 List &lt;rules-users@lists.jboss.org&gt;</font><font size=3>
</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>
<br>
<table>
<tr valign=top>
<td>
<td></table>
<br></table>
<br><font size=3><br>
<br>
</font><tt><font size=2><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. &nbsp;This
does<br>
not only include process instances, but also rule-related state. &nbsp;By<br>
default, this also includes the data inserted in the memory. &nbsp;We support<br>
two strategies for storing this data: serialization of the data<br>
(default) or JPA-based storage of entities (by reference). &nbsp;In this<br>
case, the persister is trying to serialize the test object you inserted<br>
and fails. &nbsp;Making it serializable should fix this.<br>
<br>
Kris<br>
<br>
Quoting Alan.Gairey@tessella.com:<br>
<br>
&gt; Kris,<br>
&gt; <br>
&gt; I've attached a simple test case (transaction manager, data source,<br>
&gt; etc. <br>
&gt; are configured via Spring). The error is thrown on line:<br>
&gt; <br>
&gt; ksession.insert(new SimpleFact());<br>
&gt; <br>
&gt; If this line is commented out, the rule flow executes without error.<br>
&gt; <br>
&gt; <br>
&gt; <br>
&gt; Many thanks for looking at this.<br>
&gt; <br>
&gt; Regards,<br>
&gt; <br>
&gt; Alan<br>
&gt; <br>
&gt; <br>
&gt; <br>
&gt; <br>
&gt; Kris Verlaenen &lt;kris.verlaenen@cs.kuleuven.be&gt; <br>
&gt; 28/10/2009 10:40<br>
&gt; <br>
&gt; To<br>
&gt; Alan.Gairey@tessella.com<br>
&gt; cc<br>
&gt; Rules Users List &lt;rules-users@lists.jboss.org&gt;<br>
&gt; Subject<br>
&gt; Re: [rules-users] [droolsflow] Code-based constraints for EventWait<br>
&gt; nodes <br>
&gt; - is this possible?<br>
&gt; <br>
&gt; <br>
&gt; <br>
&gt; <br>
&gt; <br>
&gt; <br>
&gt; Alan,<br>
&gt; <br>
&gt; Could you send me the entire output / stack trace (as the rollback<br>
&gt; of<br>
&gt; the transaction is usually caused by another exception)?<br>
&gt; <br>
&gt; Or a simple test case that shows the error, so I can take a look?<br>
&gt; <br>
&gt; Thx,<br>
&gt; Kris<br>
&gt; <br>
&gt; Quoting Alan.Gairey@tessella.com:<br>
&gt; <br>
&gt; &gt; Kris,<br>
&gt; &gt; <br>
&gt; &gt; After posting my last question, I quickly came to the same<br>
&gt; conclusion<br>
&gt; &gt; as <br>
&gt; &gt; you, so I'm now using a rule-based constraint in my EventWait<br>
&gt; node.<br>
&gt; &gt; <br>
&gt; &gt; This however has presented a different problem. If I create my<br>
&gt; &gt; session <br>
&gt; &gt; from JPAKnowledgeService, then when I try to insert my fact into<br>
&gt; the<br>
&gt; &gt; <br>
&gt; &gt; session, I get the following error:<br>
&gt; &gt; <br>
&gt; &gt; bitronix.tm.internal.BitronixRollbackException: transaction was<br>
&gt; &gt; marked as <br>
&gt; &gt; rollback only and has been rolled back<br>
&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp; at <br>
&gt; &gt;<br>
&gt; bitronix.tm.BitronixTransaction.commit(BitronixTransaction.java:153)<br>
&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp; at <br>
&gt; &gt;<br>
&gt;<br>
bitronix.tm.BitronixTransactionManager.commit(BitronixTransactionManager.java:96)<br>
&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp; at <br>
&gt; &gt;<br>
&gt;<br>
org.drools.persistence.session.SingleSessionCommandService.execute(SingleSessionCommandService.java:258)<br>
&gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp; at <br>
&gt; &gt;<br>
&gt;<br>
org.drools.command.impl.CommandBasedStatefulKnowledgeSession.insert(CommandBasedStatefulKnowledgeSession.java:305)<br>
&gt; &gt; (Everything works fine if I create my session from the knowledge<br>
&gt; base<br>
&gt; &gt; - <br>
&gt; &gt; i.e. with no state persistence.)<br>
&gt; &gt; Prior to using a rule-based constraint (with no call to <br>
&gt; &gt; CommandBasedStatefulKnowledgeSession.insert), the session created<br>
&gt; &gt; from <br>
&gt; &gt; JPAKnowledgeService worked OK.<br>
&gt; &gt; I'm using the default JPA configuration from the Drools<br>
&gt; documentation<br>
&gt; &gt; <br>
&gt; &gt; (persisting to H2 database, etc.).<br>
&gt; &gt; Any ideas what might be causing the problem?<br>
&gt; &gt; Many thanks,<br>
&gt; &gt; Alan<br>
&gt; &gt; <br>
&gt; &gt; <br>
&gt; &gt; <br>
&gt; &gt; <br>
&gt; &gt; Kris Verlaenen &lt;kris.verlaenen@cs.kuleuven.be&gt; <br>
&gt; &gt; 23/10/2009 03:00<br>
&gt; &gt; <br>
&gt; &gt; To<br>
&gt; &gt; Rules Users List &lt;rules-users@lists.jboss.org&gt;,<br>
&gt; &gt; Alan.Gairey@tessella.com<br>
&gt; &gt; cc<br>
&gt; &gt; Rules Users List &lt;rules-users@lists.jboss.org&gt;<br>
&gt; &gt; Subject<br>
&gt; &gt; Re: [rules-users] [droolsflow] Code-based constraints for<br>
&gt; EventWait<br>
&gt; &gt; nodes <br>
&gt; &gt; - is this possible?<br>
&gt; &gt; <br>
&gt; &gt; <br>
&gt; &gt; <br>
&gt; &gt; <br>
&gt; &gt; <br>
&gt; &gt; <br>
&gt; &gt; No, the constraint of an EventWait node (or the State node in<br>
&gt; Drools<br>
&gt; &gt; 5.1) can only be rule-based. &nbsp;The reason for this is that
the rule<br>
&gt; &gt; engine knows when to re-evaluates rules (based on the evailable<br>
&gt; &gt; input).<br>
&gt; &gt; &nbsp;If you would use a code-based constraint, the engine would
have<br>
&gt; no<br>
&gt; &gt; idea<br>
&gt; &gt; when this code constraint might become true (if it was false
at<br>
&gt; the<br>
&gt; &gt; start). &nbsp;Only constant re-evaluation of the code constraint
could<br>
&gt; &gt; achieve this (which would be tremendously inefficient). &nbsp;Could
you<br>
&gt; &gt; explain why you would like to have this behaviour? &nbsp;Maybe
there is<br>
&gt; &gt; an<br>
&gt; &gt; alternative way to model this.<br>
&gt; &gt; <br>
&gt; &gt; To change the value of a variable from inside the process (using<br>
&gt; an<br>
&gt; &gt; action), simply use kcontext.setVariable(name, value). &nbsp;We
do not<br>
&gt; &gt; recommend manually changing the value of a process variable from<br>
&gt; &gt; outside<br>
&gt; &gt; the engine. &nbsp;Again, could you explain why you would like
to have<br>
&gt; &gt; this<br>
&gt; &gt; functionality?<br>
&gt; &gt; <br>
&gt; &gt; Kris<br>
&gt; &gt; <br>
&gt; &gt; Quoting Alan.Gairey@tessella.com:<br>
&gt; &gt; <br>
&gt; &gt; &gt; Can the constraint for an EventWait node in a flow be code-based<br>
&gt; &gt; &gt; (rather <br>
&gt; &gt; &gt; than rule-based)? The Eclipse plug-in (v 5.0.1) doesn't
allow<br>
&gt; this<br>
&gt; &gt; to<br>
&gt; &gt; &gt; be <br>
&gt; &gt; &gt; specified, unlike say for a Split node, although the relevant<br>
&gt; XML<br>
&gt; &gt; can<br>
&gt; &gt; &gt; of <br>
&gt; &gt; &gt; course be edited.<br>
&gt; &gt; &gt; Trying to load such a process flow results in a<br>
&gt; &gt; NullPointerException,<br>
&gt; &gt; &gt; <br>
&gt; &gt; &gt; because the constraint is always interpreted as a rule.<br>
&gt; &gt; &gt; <br>
&gt; &gt; &gt; Ideally what I'd like to do is have an EventWait node where
the<br>
&gt; &gt; &gt; constraint <br>
&gt; &gt; &gt; tests the value of a process variable. This then leads me
to<br>
&gt; &gt; another<br>
&gt; &gt; &gt; <br>
&gt; &gt; &gt; question; is there a way of setting the value of a process<br>
&gt; &gt; variable<br>
&gt; &gt; &gt; via <br>
&gt; &gt; &gt; the Drools Flow API?<br>
&gt; &gt; &gt; <br>
&gt; &gt; &gt; Thanks in advance for any help,<br>
&gt; &gt; &gt; <br>
&gt; &gt; &gt; Alan<br>
&gt; &gt; &gt; Tessella plc<br>
&gt; &gt; &gt; 26 The Quadrant, Abingdon Science Park, Abingdon, Oxfordshire,<br>
&gt; &gt; OX14<br>
&gt; &gt; &gt; 3YS<br>
&gt; &gt; &gt; E: Alan.Gairey@tessella.com, T: +44 (0)1235 555511, F: +44<br>
&gt; (0)1235<br>
&gt; &gt; &gt; 553301<br>
&gt; &gt; &gt; www.tessella.com &nbsp; &nbsp;Registered in England No.
1466429<br>
&gt; &gt; &gt; <br>
&gt; &gt; &gt; This message is commercial in confidence and may be privileged.<br>
&gt; It<br>
&gt; &gt; is<br>
&gt; &gt; &gt; <br>
&gt; &gt; &gt; intended for the addressee(s) only. Access to this message
by<br>
&gt; &gt; anyone<br>
&gt; &gt; &gt; else <br>
&gt; &gt; &gt; is unauthorized and strictly prohibited. If you have received<br>
&gt; this<br>
&gt; &gt; &gt; message <br>
&gt; &gt; &gt; in error, please inform the sender immediately. Please note
that<br>
&gt; &gt; &gt; messages <br>
&gt; &gt; &gt; sent or received by the Tessella e-mail system may be monitored<br>
&gt; &gt; and<br>
&gt; &gt; &gt; stored <br>
&gt; &gt; &gt; in an information retrieval system.<br>
&gt; &gt; &gt; <br>
&gt; &gt; <br>
&gt; &gt; <br>
&gt; &gt; <br>
&gt; &gt; <br>
&gt; &gt; Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm<br>
&gt; &gt; <br>
&gt; &gt; <br>
&gt; <br>
&gt; <br>
&gt; <br>
&gt; <br>
&gt; Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm<br>
&gt; <br>
&gt; <br>
<br>
<br>
<br>
<br>
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm</font></tt><font size=3><br>
[attachment &quot;drools-persistence-test.zip&quot; deleted by Alan Gairey/Tessella]
</font><tt><font size=2>_______________________________________________<br>
rules-users mailing list<br>
rules-users@lists.jboss.org<br>
https://lists.jboss.org/mailman/listinfo/rules-users<br>
</font></tt>
<br>