Author: tsurdilovic
Date: 2009-09-23 14:51:07 -0400 (Wed, 23 Sep 2009)
New Revision: 11509
Added:
branches/community/Seam_2_2_Drools5/examples/drools/resources/numberguesscep.drl
branches/community/Seam_2_2_Drools5/examples/drools/src/org/jboss/seam/example/numberguess/GameStart.java
Modified:
branches/community/Seam_2_2_Drools5/examples/drools/resources/.gpd.pageflow.jpdl.xml
branches/community/Seam_2_2_Drools5/examples/drools/resources/WEB-INF/components.xml
branches/community/Seam_2_2_Drools5/examples/drools/resources/kbaseconfig.properties
branches/community/Seam_2_2_Drools5/examples/drools/resources/ksessionconfig.properties
branches/community/Seam_2_2_Drools5/examples/drools/resources/pageflow.jpdl.jpg
branches/community/Seam_2_2_Drools5/examples/drools/resources/pageflow.jpdl.xml
branches/community/Seam_2_2_Drools5/examples/drools/src/org/jboss/seam/example/numberguess/Game.java
branches/community/Seam_2_2_Drools5/examples/drools/src/org/jboss/seam/example/numberguess/Guess.java
branches/community/Seam_2_2_Drools5/examples/drools/view/lose.jsp
branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools-2.2.xsd
branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools/KnowledgeActionHandler.java
branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools/KnowledgeAssignmentHandler.java
branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools/KnowledgeBase.java
branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools/KnowledgeDecisionHandler.java
branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools/KnowledgeHandler.java
Log:
Drools5 Integration.
Modified:
branches/community/Seam_2_2_Drools5/examples/drools/resources/.gpd.pageflow.jpdl.xml
===================================================================
---
branches/community/Seam_2_2_Drools5/examples/drools/resources/.gpd.pageflow.jpdl.xml 2009-09-23
06:53:25 UTC (rev 11508)
+++
branches/community/Seam_2_2_Drools5/examples/drools/resources/.gpd.pageflow.jpdl.xml 2009-09-23
18:51:07 UTC (rev 11509)
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
-<root-container name="numberGuess" width="687"
height="408">
+<root-container name="numberGuess" width="870"
height="524">
<node name="displayGuess" x="157" y="35"
width="140" height="40">
<edge>
<label x="-44" y="-10"/>
@@ -10,15 +10,14 @@
<node name="drools" x="112" y="150"
width="236" height="40">
<edge>
<label x="5" y="-10"/>
- <bendpoint w1="53" h1="-52" w2="56"
h2="63"/>
</edge>
<edge>
- <label x="15" y="-13"/>
+ <label x="5" y="-10"/>
</edge>
<edge>
- <label x="-28" y="-17"/>
+ <label x="5" y="-10"/>
</edge>
</node>
- <node name="win" x="57" y="271" width="140"
height="40"/>
- <node name="lose" x="279" y="270"
width="140" height="40"/>
+ <node name="win" x="0" y="0" width="132"
height="36"/>
+ <node name="lose" x="0" y="0" width="132"
height="36"/>
</root-container>
Modified:
branches/community/Seam_2_2_Drools5/examples/drools/resources/WEB-INF/components.xml
===================================================================
---
branches/community/Seam_2_2_Drools5/examples/drools/resources/WEB-INF/components.xml 2009-09-23
06:53:25 UTC (rev 11508)
+++
branches/community/Seam_2_2_Drools5/examples/drools/resources/WEB-INF/components.xml 2009-09-23
18:51:07 UTC (rev 11509)
@@ -11,29 +11,38 @@
<drools:knowledge-base name="kbase"
knowledge-builder-config="kbuilderconfig.properties"
knowledge-base-config="kbaseconfig.properties">
<drools:rule-resources>
-
<value>classpath;numberguesstemplate.drl;DRL;numberGuessTemplateDataProvider</value>
+ <value>classpath;numberguesscep.drl;DRL</value>
</drools:rule-resources>
<drools:event-listeners>
<value>org.drools.event.knowledgebase.DefaultKnowledgeBaseEventListener</value>
</drools:event-listeners>
</drools:knowledge-base>
- <drools:knowledge-agent name="kagent" agent-name="myAgent"
scan-resources="true" scan-directories="false"
- monitor-change-set-events="true" scan-interval="30">
- <drools:change-sets>
- <value>classpath;numberguesschangeset.xml</value>
- </drools:change-sets>
- </drools:knowledge-agent>
-
<drools:stateful-knowledge-session name="ksession"
knowledge-base="#{kbase}"
knowledge-session-config="ksessionconfig.properties"
- audit-log="/home/tsurdilo/Desktop/ksession">
+ audit-log="/home/tsurdilo/Desktop/ksessionlogs/ksession">
<drools:event-listeners>
<value>org.drools.event.rule.DebugAgendaEventListener</value>
<value>org.drools.event.rule.DebugWorkingMemoryEventListener</value>
</drools:event-listeners>
</drools:stateful-knowledge-session>
+ <drools:working-memory-entry-point name="guessEntryPoint"
+ ksession="#{ksession}" entry-point-name="Guess Stream"/>
+
+
+
+
+
+
+
+ <drools:knowledge-agent name="kagent" agent-name="myAgent"
scan-resources="true" scan-directories="false"
+ monitor-change-set-events="true" scan-interval="30">
+ <drools:change-sets>
+ <value>classpath;numberguesschangeset.xml</value>
+ </drools:change-sets>
+ </drools:knowledge-agent>
+
<drools:knowledge-base name="kbase2"
knowledge-builder-config="kbuilderconfig.properties"
knowledge-base-config="kbaseconfig.properties">
<drools:rule-resources>
<value>classpath;test.drl;DRL</value>
Modified:
branches/community/Seam_2_2_Drools5/examples/drools/resources/kbaseconfig.properties
===================================================================
---
branches/community/Seam_2_2_Drools5/examples/drools/resources/kbaseconfig.properties 2009-09-23
06:53:25 UTC (rev 11508)
+++
branches/community/Seam_2_2_Drools5/examples/drools/resources/kbaseconfig.properties 2009-09-23
18:51:07 UTC (rev 11509)
@@ -0,0 +1 @@
+drools.eventProcessingMode = stream
\ No newline at end of file
Modified:
branches/community/Seam_2_2_Drools5/examples/drools/resources/ksessionconfig.properties
===================================================================
---
branches/community/Seam_2_2_Drools5/examples/drools/resources/ksessionconfig.properties 2009-09-23
06:53:25 UTC (rev 11508)
+++
branches/community/Seam_2_2_Drools5/examples/drools/resources/ksessionconfig.properties 2009-09-23
18:51:07 UTC (rev 11509)
@@ -0,0 +1 @@
+drools.clockType=realtime
\ No newline at end of file
Added: branches/community/Seam_2_2_Drools5/examples/drools/resources/numberguesscep.drl
===================================================================
--- branches/community/Seam_2_2_Drools5/examples/drools/resources/numberguesscep.drl
(rev 0)
+++
branches/community/Seam_2_2_Drools5/examples/drools/resources/numberguesscep.drl 2009-09-23
18:51:07 UTC (rev 11509)
@@ -0,0 +1,58 @@
+package org.jboss.seam.example.numberguess
+
+import org.jboss.seam.drools.Decision;
+import java.lang.Integer;
+
+global Decision decision
+global Integer randomNumber
+global Game game
+
+declare Guess
+ @role( event )
+ @timestamp( time )
+ @expires( 2m )
+end
+
+declare GameStart
+ @role( event )
+ @timestamp( time )
+ @expires( 2m )
+end
+
+rule GameCount
+ when
+ gameStart : GameStart() from entry-point "Guess Stream"
+ Guess( time after[1m,*] gameStart.time ) from entry-point "Guess Stream"
+ then
+ decision.setOutcome("lose");
+ game.setMessage("Game time of 1 minute exceeded.");
+end
+
+rule High
+ when
+ Guess(guess: value > randomNumber) from entry-point "Guess Stream"
+ then
+ game.setBiggest(guess - 1);
+end
+
+rule Low
+ when
+ Guess(guess: value < randomNumber) from entry-point "Guess Stream"
+ then
+ game.setSmallest(guess + 1);
+end
+
+rule Win
+ when
+ Guess(value == randomNumber) from entry-point "Guess Stream"
+ then
+ decision.setOutcome("win");
+end
+
+rule Increment
+ when
+ guess : Guess() from entry-point "Guess Stream"
+ gameStart : GameStart() from entry-point "Guess Stream"
+ then
+ game.incrementGuessCount();
+end
Modified: branches/community/Seam_2_2_Drools5/examples/drools/resources/pageflow.jpdl.jpg
===================================================================
(Binary files differ)
Modified: branches/community/Seam_2_2_Drools5/examples/drools/resources/pageflow.jpdl.xml
===================================================================
---
branches/community/Seam_2_2_Drools5/examples/drools/resources/pageflow.jpdl.xml 2009-09-23
06:53:25 UTC (rev 11508)
+++
branches/community/Seam_2_2_Drools5/examples/drools/resources/pageflow.jpdl.xml 2009-09-23
18:51:07 UTC (rev 11509)
@@ -20,10 +20,11 @@
<handler class="org.jboss.seam.drools.KnowledgeDecisionHandler">
<workingMemoryName>ksession</workingMemoryName>
+ <entryPointName>guessEntryPoint</entryPointName>
<!-- if a ruleflow was added, start a process -->
<!-- <startProcessId>numberguessid</startProcessId> -->
<assertObjects>
- <element>#{game}</element>
+ <element>#{gameStart}</element>
<element>#{guess}</element>
</assertObjects>
</handler>
Modified:
branches/community/Seam_2_2_Drools5/examples/drools/src/org/jboss/seam/example/numberguess/Game.java
===================================================================
---
branches/community/Seam_2_2_Drools5/examples/drools/src/org/jboss/seam/example/numberguess/Game.java 2009-09-23
06:53:25 UTC (rev 11508)
+++
branches/community/Seam_2_2_Drools5/examples/drools/src/org/jboss/seam/example/numberguess/Game.java 2009-09-23
18:51:07 UTC (rev 11509)
@@ -1,8 +1,10 @@
package org.jboss.seam.example.numberguess;
+import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Begin;
import org.jboss.seam.annotations.Create;
+import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
@@ -14,6 +16,7 @@
private int biggest;
private int smallest;
private int guessCount;
+ private String message = "";
@Create
@Begin(pageflow="numberGuess")
@@ -53,4 +56,14 @@
{
this.smallest = smallest;
}
+
+ public String getMessage()
+ {
+ return message;
+ }
+
+ public void setMessage(String message)
+ {
+ this.message = message;
+ }
}
Added:
branches/community/Seam_2_2_Drools5/examples/drools/src/org/jboss/seam/example/numberguess/GameStart.java
===================================================================
---
branches/community/Seam_2_2_Drools5/examples/drools/src/org/jboss/seam/example/numberguess/GameStart.java
(rev 0)
+++
branches/community/Seam_2_2_Drools5/examples/drools/src/org/jboss/seam/example/numberguess/GameStart.java 2009-09-23
18:51:07 UTC (rev 11509)
@@ -0,0 +1,33 @@
+package org.jboss.seam.example.numberguess;
+
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.AutoCreate;
+import org.jboss.seam.annotations.Create;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.intercept.BypassInterceptors;
+
+@Name("gameStart")
+(a)Scope(ScopeType.CONVERSATION)
+@AutoCreate
+@BypassInterceptors
+public class GameStart
+{
+ private long time;
+
+ @Create
+ public void begin() {
+ setTime(System.currentTimeMillis());
+ }
+
+ public long getTime()
+ {
+ return time;
+ }
+
+ public void setTime(long time)
+ {
+ System.out.println("**** IN GAMESTART SETTING TIME TO : " + time);
+ this.time = time;
+ }
+}
Modified:
branches/community/Seam_2_2_Drools5/examples/drools/src/org/jboss/seam/example/numberguess/Guess.java
===================================================================
---
branches/community/Seam_2_2_Drools5/examples/drools/src/org/jboss/seam/example/numberguess/Guess.java 2009-09-23
06:53:25 UTC (rev 11508)
+++
branches/community/Seam_2_2_Drools5/examples/drools/src/org/jboss/seam/example/numberguess/Guess.java 2009-09-23
18:51:07 UTC (rev 11509)
@@ -3,22 +3,36 @@
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.intercept.BypassInterceptors;
@Name("guess")
@Scope(ScopeType.CONVERSATION)
+@BypassInterceptors
public class Guess
{
-
+
private Integer value;
-
+ private long time;
+
public void setValue(Integer guess)
{
this.value = guess;
+ this.time = System.currentTimeMillis();
}
public Integer getValue()
{
return value;
}
-
+
+ public long getTime()
+ {
+ return time;
+ }
+
+ public void setTime(long time)
+ {
+ this.time = time;
+ }
+
}
Modified: branches/community/Seam_2_2_Drools5/examples/drools/view/lose.jsp
===================================================================
--- branches/community/Seam_2_2_Drools5/examples/drools/view/lose.jsp 2009-09-23 06:53:25
UTC (rev 11508)
+++ branches/community/Seam_2_2_Drools5/examples/drools/view/lose.jsp 2009-09-23 18:51:07
UTC (rev 11509)
@@ -5,8 +5,9 @@
<title>You lose.</title>
</head>
<body>
-<h1>You lose.</h1>
<f:view>
+<h1>You lose.</h1>
+<h:outputText id="reason" value="#{game.message}" />
We recommend the
<a
href="http://mathworld.wolfram.com/Bisection.html">bisection
algorithm</a>.
Would you like to <a href="numberGuess.seam">play again</a>?
Modified:
branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools/KnowledgeActionHandler.java
===================================================================
---
branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools/KnowledgeActionHandler.java 2009-09-23
06:53:25 UTC (rev 11508)
+++
branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools/KnowledgeActionHandler.java 2009-09-23
18:51:07 UTC (rev 11509)
@@ -19,10 +19,11 @@
public List<String> retractObjects;
public String workingMemoryName;
public String startProcessId;
+ public String entryPointName;
public void execute(ExecutionContext executionContext) throws Exception
{
- org.drools.runtime.StatefulKnowledgeSession ksession =
getKnowledgeSession(workingMemoryName, assertObjects, retractObjects, executionContext);
+ org.drools.runtime.StatefulKnowledgeSession ksession =
getKnowledgeSession(workingMemoryName, entryPointName, assertObjects, retractObjects,
executionContext);
if(startProcessId != null && startProcessId.trim().length() > 0 )
{
ksession.startProcess(startProcessId);
Modified:
branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools/KnowledgeAssignmentHandler.java
===================================================================
---
branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools/KnowledgeAssignmentHandler.java 2009-09-23
06:53:25 UTC (rev 11508)
+++
branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools/KnowledgeAssignmentHandler.java 2009-09-23
18:51:07 UTC (rev 11509)
@@ -18,10 +18,11 @@
public List<String> assertObjects;
public List<String> retractObjects;
public String startProcessId;
+ public String entryPointName;
public void assign(Assignable assignable, ExecutionContext executionContext) throws
Exception
{
- org.drools.runtime.StatefulKnowledgeSession ksession =
getKnowledgeSession(workingMemoryName, assertObjects, retractObjects, executionContext);
+ org.drools.runtime.StatefulKnowledgeSession ksession =
getKnowledgeSession(workingMemoryName, entryPointName, assertObjects, retractObjects,
executionContext);
ksession.setGlobal( "assignable", assignable );
if(startProcessId != null && startProcessId.trim().length() > 0 )
{
Modified:
branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools/KnowledgeBase.java
===================================================================
---
branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools/KnowledgeBase.java 2009-09-23
06:53:25 UTC (rev 11508)
+++
branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools/KnowledgeBase.java 2009-09-23
18:51:07 UTC (rev 11509)
@@ -16,6 +16,7 @@
import org.drools.builder.KnowledgeBuilderErrors;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
+import org.drools.conf.EventProcessingOption;
import org.drools.event.knowledgebase.KnowledgeBaseEventListener;
import org.drools.event.process.ProcessEventListener;
import org.drools.event.rule.AgendaEventListener;
Modified:
branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools/KnowledgeDecisionHandler.java
===================================================================
---
branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools/KnowledgeDecisionHandler.java 2009-09-23
06:53:25 UTC (rev 11508)
+++
branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools/KnowledgeDecisionHandler.java 2009-09-23
18:51:07 UTC (rev 11509)
@@ -19,10 +19,12 @@
public List<String> retractObjects;
public String workingMemoryName;
public String startProcessId;
+ public String entryPointName;
public String decide(ExecutionContext executionContext) throws Exception
{
- org.drools.runtime.StatefulKnowledgeSession ksession =
getKnowledgeSession(workingMemoryName, assertObjects, retractObjects, executionContext);
+ org.drools.runtime.StatefulKnowledgeSession ksession =
getKnowledgeSession(workingMemoryName, entryPointName, assertObjects, retractObjects,
executionContext);
+
ksession.setGlobal("decision", new Decision());
if(startProcessId != null && startProcessId.trim().length() > 0 )
{
Modified:
branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools/KnowledgeHandler.java
===================================================================
---
branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools/KnowledgeHandler.java 2009-09-23
06:53:25 UTC (rev 11508)
+++
branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools/KnowledgeHandler.java 2009-09-23
18:51:07 UTC (rev 11509)
@@ -17,10 +17,14 @@
*/
public class KnowledgeHandler
{
- protected org.drools.runtime.StatefulKnowledgeSession getKnowledgeSession(String
knowledgeSessionName, List<String> expressions, List<String> retractions,
ExecutionContext executionContext) throws ELException
+ protected org.drools.runtime.StatefulKnowledgeSession getKnowledgeSession(String
knowledgeSessionName, String entryPointName, List<String> expressions,
List<String> retractions, ExecutionContext executionContext) throws ELException
{
org.drools.runtime.StatefulKnowledgeSession ksession =
(org.drools.runtime.StatefulKnowledgeSession) Component.getInstance(knowledgeSessionName,
true);
-
+ org.drools.runtime.rule.WorkingMemoryEntryPoint entryPoint = null;
+ if(entryPointName != null) {
+ entryPoint = (org.drools.runtime.rule.WorkingMemoryEntryPoint)
Component.getInstance(entryPointName, true);
+ }
+
if(expressions != null && expressions.size() > 0)
{
for (String objectName: expressions)
@@ -32,12 +36,12 @@
{
for (Object element: (Iterable) object)
{
- assertObject(ksession, element);
+ assertObject(ksession, entryPoint, element);
}
}
else
{
- assertObject(ksession, object);
+ assertObject(ksession, entryPoint, object);
}
}
}
@@ -53,12 +57,12 @@
{
for (Object element: (Iterable) object)
{
- retractObject(ksession, element);
+ retractObject(ksession, entryPoint, element);
}
}
else
{
- retractObject(ksession, object);
+ retractObject(ksession, entryPoint, object);
}
}
}
@@ -68,25 +72,43 @@
return ksession;
}
- private void assertObject(org.drools.runtime.StatefulKnowledgeSession ksession, Object
element)
+ private void assertObject(org.drools.runtime.StatefulKnowledgeSession ksession,
org.drools.runtime.rule.WorkingMemoryEntryPoint entryPoint, Object element)
{
- FactHandle fact = ksession.getFactHandle(element);
+ FactHandle fact;
+ if(entryPoint != null) {
+ fact = entryPoint.getFactHandle(element);
+ } else {
+ fact = ksession.getFactHandle(element);
+ }
+
if (fact==null)
{
- ksession.insert(element);
+ if(entryPoint != null) {
+ entryPoint.insert(element);
+ } else {
+ ksession.insert(element);
+ }
}
else
{
- ksession.update(fact, element);
+ if(entryPoint != null) {
+ entryPoint.update(fact, element);
+ } else {
+ ksession.update(fact, element);
+ }
}
}
- private void retractObject(org.drools.runtime.StatefulKnowledgeSession ksession,
Object element)
+ private void retractObject(org.drools.runtime.StatefulKnowledgeSession ksession,
org.drools.runtime.rule.WorkingMemoryEntryPoint entryPoint, Object element)
{
FactHandle fact = ksession.getFactHandle(element);
if (fact != null)
{
- ksession.retract(fact);
+ if(entryPoint != null) {
+ entryPoint.retract(fact);
+ } else {
+ ksession.retract(fact);
+ }
}
}
}
Modified: branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools-2.2.xsd
===================================================================
--- branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools-2.2.xsd 2009-09-23
06:53:25 UTC (rev 11508)
+++ branches/community/Seam_2_2_Drools5/src/main/org/jboss/seam/drools-2.2.xsd 2009-09-23
18:51:07 UTC (rev 11509)
@@ -154,7 +154,7 @@
</xs:attributeGroup>
<xs:element name="change-sets"
type="components:multiValuedProperty" />
- <xs:element name="Working-memory-entry-point">
+ <xs:element name="working-memory-entry-point">
<xs:annotation>
<xs:documentation>WorkingMemory Entry Point Component</xs:documentation>
</xs:annotation>