Hi Everyone,<br><br>I'm aware that in Drools you can use 'insert()' in the 'then' part of a rule to insert a new fact into the memory, meaning more rules may be fired based on the addition of this new fact. I wish to do a similar thing, but I wish to insert the fact into a specific entry point. My current rule code to do this is:<br>
<br><span style="color: rgb(51, 102, 255);">rule "Allow message buyBook"</span><br style="color: rgb(51, 102, 255);"><span style="color: rgb(51, 102, 255);">no-loop true</span><br style="color: rgb(51, 102, 255);">
<span style="color: rgb(51, 102, 255);"> when</span><br style="color: rgb(51, 102, 255);"><span style="color: rgb(51, 102, 255);"> $event : MessageRecievedEvent(operationName == "buyBook") from entry-point "t1 stream"</span><br style="color: rgb(51, 102, 255);">
<span style="color: rgb(51, 102, 255);"> then</span><br style="color: rgb(51, 102, 255);"><span style="color: rgb(51, 102, 255);"> MessageRecievedEvent mre = new MessageRecievedEvent();</span><br style="color: rgb(51, 102, 255);">
<span style="color: rgb(51, 102, 255);"> mre.setOperationName("sellBook");</span><br style="color: rgb(51, 102, 255);"><span style="color: rgb(51, 102, 255);"> StatefulKnowledgeSession session = kcontext.getKnowledgeRuntime().getKnowledgeBase().newStatefulKnowledgeSession();</span><br style="color: rgb(51, 102, 255);">
<span style="color: rgb(51, 102, 255);"> WorkingMemoryEntryPoint obStream = session.getWorkingMemoryEntryPoint("ob1 stream");</span><br style="color: rgb(51, 102, 255);"><span style="color: rgb(51, 102, 255);"> obStream.insert(mre);</span><br style="color: rgb(51, 102, 255);">
<span style="color: rgb(51, 102, 255);"> session.fireAllRules();</span><br style="color: rgb(51, 102, 255);"><span style="color: rgb(51, 102, 255);">end</span><br style="color: rgb(51, 102, 255);"><br style="color: rgb(51, 102, 255);">
<span style="color: rgb(51, 102, 255);">rule "ob1"</span><br style="color: rgb(51, 102, 255);"><span style="color: rgb(51, 102, 255);">no-loop true</span><br style="color: rgb(51, 102, 255);"><span style="color: rgb(51, 102, 255);"> when</span><br style="color: rgb(51, 102, 255);">
<span style="color: rgb(51, 102, 255);"> $event : MessageRecievedEvent(operationName == "sellBook") from entry-point "ob1 stream"</span><br style="color: rgb(51, 102, 255);"><span style="color: rgb(51, 102, 255);"> then</span><br style="color: rgb(51, 102, 255);">
<span style="color: rgb(51, 102, 255);"> System.out.println("executed");</span><br style="color: rgb(51, 102, 255);"><span style="color: rgb(51, 102, 255);">end</span><br><br>Which is pretty hideous, but it does work, causing the second rule to fire after the first one. What I would like is something like:<br>
<br><span style="color: rgb(51, 102, 255);">rule "Allow message buyBook"</span><br style="color: rgb(51, 102, 255);">
<span style="color: rgb(51, 102, 255);">no-loop true</span><br style="color: rgb(51, 102, 255);">
<span style="color: rgb(51, 102, 255);"> when</span><br style="color: rgb(51, 102, 255);">
<span style="color: rgb(51, 102, 255);"> $event : MessageRecievedEvent(operationName == "buyBook") from entry-point "t1 stream"</span><br style="color: rgb(51, 102, 255);">
<span style="color: rgb(51, 102, 255);"> then</span><br style="color: rgb(51, 102, 255);">
<span style="color: rgb(51, 102, 255);"> MessageRecievedEvent mre = new MessageRecievedEvent();</span><br style="color: rgb(51, 102, 255);">
<span style="color: rgb(51, 102, 255);"> mre.setOperationName("sellBook");</span><br style="color: rgb(51, 102, 255);">
<span style="color: rgb(51, 102, 255);"> <span style="color: rgb(255, 0, 0);">insert(mre, "ob1 stream")</span></span><br style="color: rgb(51, 102, 255);">
<span style="color: rgb(51, 102, 255);">end</span><br style="color: rgb(51, 102, 255);">
<br style="color: rgb(51, 102, 255);">
<span style="color: rgb(51, 102, 255);">rule "ob1"</span><br style="color: rgb(51, 102, 255);">
<span style="color: rgb(51, 102, 255);">no-loop true</span><br style="color: rgb(51, 102, 255);">
<span style="color: rgb(51, 102, 255);"> when</span><br style="color: rgb(51, 102, 255);">
<span style="color: rgb(51, 102, 255);"> $event : MessageRecievedEvent(operationName == "sellBook") from entry-point "ob1 stream"</span><br style="color: rgb(51, 102, 255);">
<span style="color: rgb(51, 102, 255);"> then</span><br style="color: rgb(51, 102, 255);">
<span style="color: rgb(51, 102, 255);"> System.out.println("executed");</span><br style="color: rgb(51, 102, 255);">
<span style="color: rgb(51, 102, 255);">end</span><br><br><font color="#000000">Is something like this possible or will I have to write a function to do it? I'm also a bit concerned about the performance hit of creating a whole new StatefulKnowledgeSession to fire the second rule, I'd like to just use the current one.<br>
<br>Thanks,<br><br>Justin<br></font>