<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Hey Laird,&nbsp;</div><div><br></div><div>right now I work on a new Java WebService (with Spring) that uses Drools to accomplish complex event processing on sensor values (=events).</div><div><br></div><div>As I am relatively new to this, I can definitely not call it "best practice" or anything the like. But so far it seems to work ;)</div><div><br></div><div>- I create and delete sessions (basically a wrapper that contains some more meta-information and the knowledgeSession) as required by the service user</div><div>- Every session is identified by an integer ID and "lives" in a static list in one singleton bean. (kinda yuck, but what can you do about that?*)</div><div>- When the server is shut down, I serialize all sessions and store them in a database</div><div>- When the server is started, I recover all sessions stored in my database.&nbsp;</div><div><br></div><div>When new events occur, they are:</div><div>1) received (REST interface)</div><div>2) session is identified</div><div>3) fact (event!) is inserted (with @timestamp)</div><div>4) fireAllRules() is called &nbsp; [I never got "fireUntilHalt" to work as expected...)</div><div><br></div><div>* -&gt; As I do a lot of temporal reasoning, I can not just fireAllRules() and then serialize/stop the session. Some rules fire minutes or hours after certain events if no other events occur afterwards. Therefore my knowledgeSessions live in memory eternally.</div><div><br></div><div><br></div><div>About the rule adding/changing:</div><div>- In my application, every client has his own session/kbase that is parameterized ( I do this with template, although its not really what templates were meant for in the first place I suppose...)</div><div>- I do recreate the whole knowledge base when the rules &nbsp;are changed and restart the session (otherwise, it leads to funny behaviour)</div><div>- I have read at different points that one can add single rules to the kbase of a running stateful session, but I also read that it may cause problems and might be unstable (so you'd have to test it somehow)</div><div><br></div><div>I wouldn't mind to share more thoughts so if you got questions, don't hesitate to write directly.</div><div><br></div><div>- Alex</div><div><br></div><br><div><div>On 07.10.2013, at 21:01, Laird Nelson &lt;<a href="mailto:ljnelson@gmail.com">ljnelson@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">I have several questions about using Drools in a stateless Java EE application.<div><br></div><div>(I've actually used it for years, but have always felt an impedance mismatch and finally have a moment to ask about it. &nbsp;:-))</div>
<div><br></div><div>Like (I suspect) many people, I have a stateless session bean responsible for some business logic with Drools in the mix. &nbsp;I'm looking to implement its—say—doWork() method with a knowledge session under the covers.</div>
<div><br></div><div>What I'm curious about is: in a rules engine, facts are sort of expected to stick around for a while (that's state; I know there are stateless sessions, but those are kind of ephemeral). You grab a bunch of facts, and over time they get inserted into the knowledge session, which sticks around in some manner. &nbsp;Then, periodically, you fire all rules, and deal with the consequences. &nbsp;Along comes another processing situation; you fire all rules, and deal with the consequences again. &nbsp;And so on. &nbsp;The fact maintenance seems stateful here while the rule processing is stateless. &nbsp;How do people deploy stateless systems with this stateful concept at their core? &nbsp;Which of the many possibilities is most commonly used? &nbsp;Serialize/deserialize the session on each request (yuck)? &nbsp;Singleton beans (yuck, I think)? &nbsp;Outboard drools server with RPC (also yuck, I think)?</div>
<div><br></div><div>Next, in a dynamic business application, it's often the case that single rules need to be added to the knowledge base. &nbsp;Someone wants to add in, for example, a new way of calculating fees. &nbsp;They don't—at a human level—want to open up the catalog of 47,000 rules, add one, and then re-install/re-deploy the thus-changed catalog of rules. &nbsp;They just—again, at a human level—want to add a new rule. &nbsp;Is redeploying the catalog the only way to go here, or is there a way that I've missed to incrementally and programmatically add a rule to a KnowledgeBase?</div>
<div><br></div><div>More generally: in a stateless app, where do these concepts live? &nbsp;Where do they <i>best</i>&nbsp;live, I should say?</div><div><br></div><div>(For completeness, I'm the author of the <a href="https://code.google.com/p/drools-jca/">drools-jca</a> project, which attempts to make Drools 5.x Java EE compatible by offloading its filesystem and threading operations into a JCA resource adapter. &nbsp;I'm not convinced that's the best place for it and with Drools 6 doing different things with threads and with Java EE 7 relaxing its restrictions on filesystem access I'm looking for better patterns.)<br>
</div><div><br></div><div>Thanks very much for reading; looking forward to the replies.</div><div><br></div><div>Best,</div><div>Laird</div><div><br></div><div>-- <br><a href="http://about.me/lairdnelson" target="_blank">http://about.me/lairdnelson</a><br>

</div></div>
_______________________________________________<br>rules-users mailing list<br><a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>https://lists.jboss.org/mailman/listinfo/rules-users</blockquote></div><br></body></html>