<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
The work is now committed and extensively unit tested here, which
should how to use it. Notice the test at the end, so you can reason
on the number of active and inactive activations:<br>
<a class="moz-txt-link-freetext" href="https://github.com/droolsjbpm/drools/blob/master/drools-compiler/src/test/java/org/drools/integrationtests/DeclarativeAgendaTest.java">https://github.com/droolsjbpm/drools/blob/master/drools-compiler/src/test/java/org/drools/integrationtests/DeclarativeAgendaTest.java</a><br>
<br>
I'm just doing the N&N update and then we should be good to
beta1<br>
<br>
Mark<br>
On 07/08/2011 23:15, Mauricio Salatino wrote:
<blockquote
cite="mid:CANzbnyWrNoN-HVLQZS6PCeFbnj5pLRZ_3WcUL1bjt8iFfmBhtg@mail.gmail.com"
type="cite">Hi man, I didn't have the time to review the code of
this feature but I'm really interested to understand how you are
achieving this:
<div>"<span class="Apple-style-span" style="color: rgb(51, 51,
51); font-family: arial, sans-serif; font-size: medium; ">
<table class="Bs nH iY" style="background-image: initial;
background-attachment: initial; background-origin: initial;
background-clip: initial; background-color: rgb(255, 255,
255); width: 1031px; position: relative;
-webkit-border-horizontal-spacing: 0px;
-webkit-border-vertical-spacing: 0px; padding-top: 0px;
padding-right: 0px; padding-bottom: 0px; padding-left: 0px;
border-collapse: collapse; border-top-width: 1px;
border-top-style: solid; border-top-color: rgb(228, 228,
228); margin-top: 10px; background-position: initial
initial; background-repeat: initial initial; "
cellpadding="0">
<tbody>
<tr>
<td class="Bu" style="margin-top: 0px; margin-right:
0px; margin-bottom: 0px; margin-left: 0px;
font-family: arial, sans-serif; vertical-align: top;
padding-top: 0px; padding-right: 0px; padding-bottom:
0px; padding-left: 0px; ">
<div class="nH if" style="padding-top: 0px;
padding-right: 0px; padding-bottom: 1px;
padding-left: 0px; ">
<div class="nH">
<div class="nH hx" style="color: rgb(51, 51, 51);
padding-top: 4px; padding-right: 8px;
padding-bottom: 4px; padding-left: 0px; ">
<div class="nH">
<div class="h7 ie nH oy8Mbf"
style="padding-bottom: 0px; clear: both; ">
<div class="Bk" style="position: relative;
margin-bottom: 10px; border-right-width:
1px; border-bottom-width: 1px;
border-left-width: 1px; border-top-style:
solid; border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
border-top-color: rgb(239, 239, 239);
border-right-color: rgb(239, 239, 239);
border-left-color: rgb(239, 239, 239);
border-bottom-color: rgb(226, 226, 226);
border-top-width: 0px;
border-top-left-radius: 2px 2px;
border-top-right-radius: 2px 2px;
border-bottom-right-radius: 2px 2px;
border-bottom-left-radius: 2px 2px; width:
790px; ">
<div class="G3 G2" style="padding-top:
3px; background-color: rgb(255, 255,
255); border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
border-right-color: rgb(207, 207, 207);
border-bottom-color: rgb(207, 207, 207);
border-left-color: rgb(207, 207, 207);
border-top-width: 1px; border-top-style:
solid; border-top-color: rgb(207, 207,
207); border-top-left-radius: 2px 2px;
border-top-right-radius: 2px 2px;
border-bottom-right-radius: 2px 2px;
border-bottom-left-radius: 2px 2px; ">
<div>
<div id=":11p">
<div class="HprMsc">
<div class="gs">
<div id=":11r" class="ii gt"
style="font-size: 13px;
margin-top: 5px; margin-right:
15px; margin-bottom: 5px;
margin-left: 15px;
padding-bottom: 20px;
position: relative; z-index:
2; ">
<div id=":11q">-All matched
rule's Activations are
inserted into WorkingMemory
as<br>
facts. </div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</span>"</div>
<div>
How are you getting the newly created activation and inserting
it inside the working memory? Are you wrapping the real
Activation Object or creating a new representation of it? I
want to understand how you are managing the information and if
you create a hook to do that to be able to copy the same
mechanism and apply it for processes.</div>
<div><br>
</div>
<div>Cheers.</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
<div class="gmail_quote">On Sun, Aug 7, 2011 at 6:29 AM, Mark
Proctor <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:mproctor@codehaus.org">mproctor@codehaus.org</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex;">I just
got a first cut working for "declarative agenda". The idea
here<br>
is rules can control which rule can or cannot fire. Because
this is<br>
highly experimental it is off by default and users must
explicitely<br>
enable it, it will stay this way until we are happy with the
solution.<br>
My hope is that it will provide a more declarative approach
to execution<br>
control; which will enable more readable and maintainable
rules compared<br>
to using magic salience values and in some circumstances
control objects..<br>
<br>
KnowledgeBaseConfiguration kconf =<br>
KnowledgeBaseFactory.newKnowledgeBaseConfiguration();<br>
kconf.setOption( DeclarativeAgendaOption.ENABLED );<br>
KnowledgeBase kbase =
KnowledgeBaseFactory.newKnowledgeBase(<br>
kconf );<br>
<br>
The basic idea is:<br>
-All matched rule's Activations are inserted into
WorkingMemory as<br>
facts. So you can now match against an Activation the rules
metadata and<br>
declarations are available as -fields on the Activation
object.<br>
-You can use the kcontext.block( $a ) for the current rule
to block the<br>
selected activation. Only when that rule becomes false will
the<br>
activation be elegible for firing. If it is already elebible
for firing<br>
and is later blocked, it will be removed from the agenda
until it is<br>
unblocked.<br>
-An activation may have multiple blockers, all blockers must
became<br>
false, so they are removed to enable the activation to fire<br>
-kcontext.unblockAll( $a ) is an over-ride rule that will
remove all<br>
blockers regardless<br>
-@activationListener('direct') allows a rule to fire as soon
as it's<br>
matched, this is to be used for rules that block/unblock
activations, it<br>
is not desirable for these rules to have side effects that
impact else<br>
where. The name may change later, this is actually part of
the pluggable<br>
terminal node handlers I made, which is an "internal"
feature for the<br>
moment.<br>
<br>
I should be committing this later today, and will send a
follow up email<br>
once it hits HEAD, but here is a unit test. It uses a
control role to<br>
stop all rules with metadata declaring the rules to be in
the "sales"<br>
department. Only when that control rule becomes false can
they fire.<br>
<br>
package org.domain.test<br>
import org.drools.runtime.rule.Activation<br>
global java.util.List list<br>
dialect 'mvel'<br>
<br>
rule rule1 @department('sales')<br>
when<br>
$s : String( this == 'go1' )<br>
then<br>
list.add( <a moz-do-not-send="true"
href="http://kcontext.rule.name" target="_blank">kcontext.rule.name</a>
+ ':' + $s );<br>
end<br>
rule rule2 @department('sales')<br>
when<br>
$s : String( this == 'go1' )<br>
then<br>
list.add( <a moz-do-not-send="true"
href="http://kcontext.rule.name" target="_blank">kcontext.rule.name</a>
+ ':' + $s );<br>
end<br>
rule rule3 @department('sales')<br>
when<br>
$s : String( this == 'go1' )<br>
then<br>
list.add( <a moz-do-not-send="true"
href="http://kcontext.rule.name" target="_blank">kcontext.rule.name</a>
+ ':' + $s );<br>
end<br>
rule blockerAllSalesRules @activationListener('direct')<br>
when<br>
$s : String( this == 'go2' )<br>
$i : Activation( department == 'sales' )<br>
then<br>
list.add( $<a moz-do-not-send="true"
href="http://i.rule.name" target="_blank">i.rule.name</a>
+ ':' + $s );<br>
kcontext.block( $i );<br>
end<br>
<br>
KnowledgeBaseConfiguration kconf =<br>
KnowledgeBaseFactory.newKnowledgeBaseConfiguration();<br>
kconf.setOption( DeclarativeAgendaOption.ENABLED );<br>
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(
kconf );<br>
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages()
);<br>
StatefulKnowledgeSession ksession =
kbase.newStatefulKnowledgeSession();<br>
List list = new ArrayList();<br>
ksession.setGlobal( "list", list);<br>
ksession.insert( "go1" );<br>
FactHandle go2 = ksession.insert( "go2" );<br>
ksession.fireAllRules();<br>
assertEquals( 3, list.size() ); // none of the rules 1-3
fire, as they<br>
are blocked.<br>
assertTrue( list.contains( "rule1:go2" ));<br>
assertTrue( list.contains( "rule2:go2" ));<br>
assertTrue( list.contains( "rule3:go2" ));<br>
<br>
list.clear();<br>
<br>
ksession.retract( go2 ); // the blocker rule is nolonger
true, so rules<br>
1-3 can now fire.<br>
ksession.fireAllRules();<br>
<br>
assertEquals( 3, list.size() );<br>
assertTrue( list.contains( "rule1:go1" ));<br>
assertTrue( list.contains( "rule2:go1" ));<br>
assertTrue( list.contains( "rule3:go1" ));<br>
<br>
ksession.dispose();<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
rules-dev mailing list<br>
<a moz-do-not-send="true"
href="mailto:rules-dev@lists.jboss.org">rules-dev@lists.jboss.org</a><br>
<a moz-do-not-send="true"
href="https://lists.jboss.org/mailman/listinfo/rules-dev"
target="_blank">https://lists.jboss.org/mailman/listinfo/rules-dev</a><br>
</blockquote>
</div>
<br>
<br clear="all">
<br>
-- <br>
- CTO @ <a moz-do-not-send="true"
href="http://www.plugtree.com">http://www.plugtree.com</a> <br>
- MyJourney @ <a moz-do-not-send="true"
href="http://salaboy.wordpress.com">http://salaboy.wordpress.com</a><br>
- Co-Founder @ <a moz-do-not-send="true"
href="http://www.jbug.com.ar">http://www.jbug.com.ar</a><br>
<br>
- Salatino "Salaboy" Mauricio -<br>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
rules-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-dev@lists.jboss.org">rules-dev@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-dev">https://lists.jboss.org/mailman/listinfo/rules-dev</a>
</pre>
</blockquote>
<br>
</body>
</html>