<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div apple-content-edited="true"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-size: 18px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-size: 18px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-size: 18px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div><div><div><div><div><div>Greetings:</div><div><br></div><div>Having just joined the developers list, one of the ten commandments back in the old days of using either Java or C or C++ was to avoid Global variables at all costs. &nbsp;From what I've been reading the past couple of days is that there are several global variables distributed throughout the Drools code, is that correct? &nbsp;I could be way off base but it did seem that someone was having trouble keeping a global in focus during function calls to a global Logger. &nbsp; Wouldn't a static Logger be a better solution?</div><div><br></div><div>SDG</div><div>jco</div><div>Senior Consultant / Architect</div><div>KnowledgeBased Systems Corporation</div><div><div><a href="http://www.kbsc.com">http://www.kbsc.com</a></div><div><div><div>Co-founder and Director of The October {Technical} Rules Fest&nbsp;-THE RuleBased Systems Conference Oct 22-24 Dallas, TX</div><div><a href="http://www.OctoberRulesFest.org">http://www.OctoberRulesFest.org</a></div></div></div></div><div>"This above all: to thine own self be true,<div>And it must follow, as the night the day,</div><div>Thou canst not then be false to any man."</div><div>Hamlet, Act 1, Scene III</div><div><a href="http://www-tech.mit.edu/Shakespeare/hamlet/hamlet.1.3.html">http://www-tech.mit.edu/Shakespeare/hamlet/hamlet.1.3.html</a></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div><div><br></div></div></span><br class="Apple-interchange-newline"></div></span><br class="Apple-interchange-newline"></div></span><br class="Apple-interchange-newline"> </div><br><div><div>On Oct 15, 2008, at 12:45 PM, Edson Tirelli wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr"><br>&nbsp;&nbsp; It may be invoked by a consequence, an eval, a predicate, or a return value constraint.<br><br>&nbsp;&nbsp; If you fix it for the consequence in JavaConsequenceBuilder, the others will work the same. You will have to change the java.g grammar as I mentioned in my previous e-mail to make it work.<br> <br>&nbsp;&nbsp; []s<br>&nbsp;&nbsp; Edson<br><br><div class="gmail_quote">2008/10/14 David Sinclair <span dir="ltr">&lt;<a href="mailto:dsinclair@chariotsolutions.com">dsinclair@chariotsolutions.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> <div dir="ltr"><p>Edson,</p> <div>Changing the builder shouldn't be too much of a problem. If I make the changes you suggested, how does the global actually get passed to the method? For example if something defined a function like</div> <div>&nbsp;</div> <div>void function doX(int abc) {</div> <div>&nbsp;&nbsp; ...</div> <div>&nbsp;&nbsp; global.doY(bcd);</div> <div>}<br></div> <div>and I rewrite it to be</div> <div>&nbsp;</div> <div>void function doX(int abc, GlobalType global) {</div> <div>&nbsp;&nbsp; ...</div> <div>}</div> <div>&nbsp;</div> <div>Who is the invoker of the method?</div> <div>&nbsp;</div> <div>thanks</div> <div>&nbsp;</div> <div>dave</div> <div>&nbsp;</div> <div><br>&nbsp;</div> <div class="gmail_quote"><div class="Ih2E3d">On Mon, Oct 13, 2008 at 3:24 PM, Edson Tirelli <span dir="ltr">&lt;<a href="mailto:tirelli@post.com" target="_blank">tirelli@post.com</a>></span> wrote:<br> </div><div><div></div><div class="Wj3C7c"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0px 0px 0px 0.8ex; padding-left: 1ex;"> <div dir="ltr"><br>&nbsp;&nbsp; Hi Dave,<br><br>&nbsp;&nbsp; Excellent!<br>&nbsp;&nbsp; I will try to explain the current situation and one possible solution, but you may have better ideas.<br><br>&nbsp;&nbsp; Functions in Drools are compiled as simple static methods in a generated java class. We use MVEL Templates to generate the code of the class and the static method.<br> <br>&nbsp;&nbsp; Take a look at JavaFunctionBuilder.java class for the code generation call and at javaFunction.mvel for the code template.<br><br>&nbsp;&nbsp; Now, the problem with globals is that they are scoped to sessions, not rulebases, so you can not resolve them until runtime. You can not for instance, make them a static reference of the generated class and set it at rulebase compilation time.<br> <br>&nbsp;&nbsp; So, my suggestion would be to:<br><br>1. at compile time, use JavaDialect.analyzeBlock() method to analyze and find out what are the globals that are used by the funcion method code.<br><br>2. modify the code generation to add parameters to that in the method call. So, if "log" is a global and if the function is declared like this:<br> <br>function void someFunction( String param ) {<br>&nbsp;&nbsp;&nbsp; // ... code ...<br>&nbsp;&nbsp;&nbsp; log.something(...);<br>&nbsp;&nbsp;&nbsp; // ... code ...<br>} <br><br>&nbsp;&nbsp; you detect the use of "log" and add it as a parameter of the generated method:<br> <br>...<br>public static void someFunction( Logger log, String Param ) {<br>&nbsp;&nbsp; ...<br>}<br>...<br><br>&nbsp;&nbsp; This way, at runtime we can inject the parameter into the call. You can look at JavaConsequenceBuilder.java and javaInvokers.mvel to see how we do kind-of the same thing for consequences.<br> <br>3. Now the most interesting part. :)&nbsp; We use an ANTLR grammar for parsing Java code blocks. You need to change the parser to rewrite any function call the user is doing in his code to inject the log parameter transparently. I did the very same thing for modify blocks:<br> <br>modify( $something ) {<br>&nbsp;&nbsp; ...<br>} <br><br>&nbsp;&nbsp; It is not hard once you get the hang of it. It is a bit of "hand work" though. Look at the JavaConsequenceBuilder.fixModifyBlocks() for what I did. Also, the ANTLR Java grammar is java.g. <br> <br>&nbsp;&nbsp; Let me know if you have questions or if you have a better idea, and welcome aboard!<br><br>&nbsp;&nbsp; Cheers,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Edson<br><br><br><br> <div class="gmail_quote">2008/10/13 David Sinclair <span dir="ltr">&lt;<a href="mailto:dsinclair@chariotsolutions.com" target="_blank">dsinclair@chariotsolutions.com</a>></span> <div> <div></div> <div><br> <blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> <div dir="ltr">Hi Edson,<br><br>My name is dave sinclair. I started using Drools in early August of this year, but have a lot of experience with rules engines. I have worked primarily with ArtEntrprise and some with PegaRules. I would love to help with this project and thought that this may be the area to jump in on.<br> <br>I have the M2 code, and was reading it over the weekend. Mostly the core and some of the compilier. If you want to point me in the right direction on the global/functions I'd be happy to have a look.<br><br>thanks<br> <br>dave <div> <div></div> <div><br><br> <div class="gmail_quote">On Mon, Oct 13, 2008 at 9:59 AM, Bagwell, Allen F <span dir="ltr">&lt;<a href="mailto:afbagwe@sandia.gov" target="_blank">afbagwe@sandia.gov</a>></span> wrote:<br> <blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> <div> <div dir="ltr" align="left"><span><font color="#0000ff" size="2" face="Arial">Edson,</font></span></div> <div dir="ltr" align="left"><span><font color="#0000ff" size="2" face="Arial"></font></span>&nbsp;</div> <div dir="ltr" align="left"><span><font color="#0000ff" size="2" face="Arial">Thanks for the tip. I figured I'd need to use a workaround like this.</font></span></div> <div dir="ltr" align="left"><span><font color="#0000ff" size="2" face="Arial"></font></span>&nbsp;</div> <div dir="ltr" align="left"><span><font color="#0000ff" size="2" face="Arial">Unfortunately I'm under a series of tight development and test deadlines all the way into early summer. Otherwise, I'd have a look. Hopefully someone else out there can assist.</font></span></div> <div dir="ltr" align="left"><span><font color="#0000ff" size="2" face="Arial"></font></span>&nbsp;</div> <div dir="ltr" align="left"><span><font color="#0000ff" size="2" face="Arial">Thanks,</font></span></div> <div dir="ltr" align="left"><span><font color="#0000ff" size="2" face="Arial">-A</font></span></div><br> <div dir="ltr" align="left" lang="en-us"> <hr> <font size="2" face="Tahoma"><b>From:</b> <a href="mailto:rules-users-bounces@lists.jboss.org" target="_blank">rules-users-bounces@lists.jboss.org</a> [mailto:<a href="mailto:rules-users-bounces@lists.jboss.org" target="_blank">rules-users-bounces@lists.jboss.org</a>] <b>On Behalf Of </b>Edson Tirelli<br> <b>Sent:</b> Friday, October 10, 2008 5:46 AM<br><b>To:</b> Rules Users List<br><b>Subject:</b> Re: [rules-users] No globals in functions?<br></font><br></div> <div></div> <div dir="ltr"><br>&nbsp;&nbsp; Allen,<br><br>&nbsp;&nbsp; There is a technical explanation behind that and we never had the time to find a way to overcome this limitation. What you can do, although not ideal, is to send the global as a parameter:<br> <br>funcion void foo( Logger log, String cond ) <br>{<br>...<br>}<br><br>rule XYZ<br>when<br>then<br>&nbsp;&nbsp;&nbsp; foo( log, someString );<br>end<br><br>&nbsp;&nbsp; If you or anyone would like to help improving this, let us know and we can discuss ways into doing it. <br> <br>&nbsp;&nbsp; []s<br>&nbsp;&nbsp; Edson<br><br> <div class="gmail_quote">2008/10/9 Bagwell, Allen F <span dir="ltr">&lt;<a href="mailto:afbagwe@sandia.gov" target="_blank">afbagwe@sandia.gov</a>></span><br> <blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> <div><font size="3" face="Arial, sans-serif"> <div>&nbsp;</div> <div><font size="2">There's probably an easy explanation for this. I was wondering about why functions inside of rule files can't access globals?</font></div> <div><font size="2"></font>&nbsp;</div> <div><font size="2">For example, I have a log4j logger that I pass into my rule files via a global.&nbsp; The logger should never be a part of working memory. It's just there to capture valuable feedback.</font></div> <div><font size="2"></font>&nbsp;</div> <div><font size="2">But I can't do this:</font></div> <div><font size="2"></font>&nbsp;</div> <div><font size="2">global Logger log;</font></div> <div><font size="2"></font>&nbsp;</div> <div><font size="2">function void foo(String cond)</font></div> <div><font size="2">{</font></div> <div><font size="2">&nbsp;&nbsp; if (cond == "error")</font></div> <div><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; log.error("I saw an error");</font></div> <div><font size="2">}</font></div> <div><font size="2"></font>&nbsp;</div> <div><font size="2">Because the compiler says that in the function it can't resolve 'log'.</font></div> <div><font size="2"></font>&nbsp;</div> <div><font size="2">-A</font></div> <div><font size="2"></font>&nbsp;</div> <div><font color="#008080" size="2" face="Tahoma, sans-serif">Allen F. Bagwell</font></div> <div><font color="#008080" size="1" face="Tahoma, sans-serif">e-mail:&nbsp; <a href="mailto:afbagwe@sandia.gov" target="_blank">afbagwe@sandia.gov</a></font></div> <div><font color="#008080" size="1" face="Tahoma, sans-serif">phone:&nbsp; 505/284-4517</font></div> <div><font color="#008080" size="1" face="Tahoma, sans-serif">fax:&nbsp; 505/ 844-7886</font></div> <div><font color="#008080" size="1" face="Tahoma, sans-serif"></font>&nbsp;</div> <div style="margin-top: 5pt; margin-bottom: 5pt;"><font color="#008080" size="1" face="Tahoma, sans-serif">There is no monument dedicated to the memory of a committee. -- Lester J. Pourciau</font></div> <div><font size="1" face="Tahoma, sans-serif"></font>&nbsp;</div> <div><font size="1" face="Tahoma, sans-serif"></font>&nbsp;</div> <div><font size="2"></font>&nbsp;</div></font></div><br>_______________________________________________<br>rules-users mailing list<br><a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br> <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br><br></blockquote></div><br><br clear="all"><br>-- <br>&nbsp;Edson Tirelli<br>&nbsp;JBoss Drools Core Development<br> &nbsp;JBoss, a division of Red Hat @ <a href="http://www.jboss.com/" target="_blank">www.jboss.com</a><br></div></div><br>_______________________________________________<br>rules-users mailing list<br><a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br> <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br><br></blockquote></div><br></div></div></div></blockquote></div></div></div> <div> <div></div> <div><br><br clear="all"><br>-- <br>&nbsp;Edson Tirelli<br>&nbsp;JBoss Drools Core Development<br>&nbsp;JBoss, a division of Red Hat @ <a href="http://www.jboss.com/" target="_blank">www.jboss.com</a><br></div></div></div> </blockquote></div></div></div><br></div> </blockquote></div><br><br clear="all"><br>-- <br> &nbsp;Edson Tirelli<br> &nbsp;JBoss Drools Core Development<br> &nbsp;JBoss, a division of Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a><br> </div> _______________________________________________<br>rules-dev mailing list<br><a href="mailto:rules-dev@lists.jboss.org">rules-dev@lists.jboss.org</a><br>https://lists.jboss.org/mailman/listinfo/rules-dev<br></blockquote></div><br></body></html>