[JBoss JIRA] Created: (JBRULES-2197) CLONE -Example source.
by Neil Wallace (JIRA)
CLONE -Example source.
----------------------
Key: JBRULES-2197
URL: https://jira.jboss.org/jira/browse/JBRULES-2197
Project: JBoss Drools
Issue Type: Bug
Security Level: Public (Everyone can see)
Components: drools-compiler
Affects Versions: 5.0.1.FINAL
Environment: Windows XP,eclipse
Reporter: Neil Wallace
Assignee: Mark Proctor
Fix For: 5.0.1.FINAL
Hi! We are studying Drools 5.0 in order to use..
But a curious problem has happened, while executeing an example in documentation.
It is 3.1.3. Defining Processes Using the Process API in drools-5.0-docs\drools-flow\html_single\index.html.
Actually, 3.1.3.1. Example 1 is working normally, but 3.1.3.2. Example 2 and 3.1.3.3. Example 3 occur error.
I 'll tell you what we grasp the reason for error, so far.
When it's working normal, <ActionNode> exists.
The other way, when it is not working normal, <ActionNode> doesn't exist.
For example, in case of 3.1.3.2. Example 2
RuleFlowProcessFactory factory =
RuleFlowProcessFactory.createProcess("org.drools.HelloWorldJoinSplit");
factory
// Header
.name("HelloWorldJoinSplit")
.version("1.0")
.packageName("org.drools")
// Nodes
.startNode(1).name("Start").done()
.splitNode(2).name("Split").type(Split.TYPE_AND).done()
.actionNode(3).name("Action 1")
.action("mvel", "System.out.println(\"Inside Action 1\")").done() < -here, NullPointerException occurs.
.actionNode(4).name("Action 2")
.action("mvel", "System.out.println(\"Inside Action 2\")").done()
.joinNode(5).type(Join.TYPE_AND).done()
.endNode(6).name("End").done()
// Connections
.connection(1, 2)
.connection(2, 3)
.connection(2, 4)
.connection(3, 5)
.connection(4, 5)
.connection(5, 6);
RuleFlowProcess process = factory.validate().getProcess();
Please, let me know entire source I can execute this example well.
Thank you for your consideration.
I am waiting for you answer.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
14 years, 10 months
[JBoss JIRA] Created: (JBRULES-2194) CLONE -StatelessKnowledgeSessions created by KnowledgeAgent causes NullPointerException when used in a pipeline
by Neil Wallace (JIRA)
CLONE -StatelessKnowledgeSessions created by KnowledgeAgent causes NullPointerException when used in a pipeline
---------------------------------------------------------------------------------------------------------------
Key: JBRULES-2194
URL: https://jira.jboss.org/jira/browse/JBRULES-2194
Project: JBoss Drools
Issue Type: Bug
Security Level: Public (Everyone can see)
Components: drools-compiler
Environment: 5.0.1.SNAPSHOT for May 12, 2009
Reporter: Neil Wallace
Assignee: Mark Proctor
Fix For: 5.0.1.FINAL
This issue is related to this thread on the user-list: http://www.mail-archive.com/rules-users@lists.jboss.org/msg08770.html
I'm getting a NullPointerException when I insert an object into
the pipeline using 5.0.1.SNAPSHOT from May 12, 2009:
java.lang.NullPointerException
at
org.drools.runtime.pipeline.impl.StatelessKnowledgeSessionPipelineImpl.insert(StatelessKnowledgeSessionPipelineImpl.java:24)
It looks like StatelessKnowledgeSession's ruleBase is null when created by the KnowledgeAgent, which poses a problem since StatelessKnowledgeSessionPipelineImpl invokes getRootClassLoader() on the session's ruleBase.
Here's what I'm doing:
StatelessKnowledgeSession ksession = kagent.newStatelessKnowledgeSession();
Pipeline pipeline =
PipelineFactory.newStatelessKnowledgeSessionPipeline(ksession);
pipeline.setReceiver(messageTransformer);
pipeline.insert(message); // NPE here
I'll attach a patch to KnowledgeAgentTest containing a failing test case.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
14 years, 10 months
[JBoss JIRA] Created: (JBRULES-2193) CLONE -Modify raises NPE when using "from"
by Neil Wallace (JIRA)
CLONE -Modify raises NPE when using "from"
------------------------------------------
Key: JBRULES-2193
URL: https://jira.jboss.org/jira/browse/JBRULES-2193
Project: JBoss Drools
Issue Type: Bug
Security Level: Public (Everyone can see)
Components: drools-core
Affects Versions: 5.0.0.CR1
Reporter: Neil Wallace
Assignee: Edson Tirelli
Fix For: 5.0.1.FINAL
The attached file should generate everyting into a subdirectory ./movie and compile and execute.
You'll have to modify the classpath, though.
Regards
-W
# Shell this file to create subdir movie with *.java, Movie.drl, database.xml
#
# you'll have to modify the classpath setting - see below
#
mkdir movie || true
cat <<'TheEnd' >movie/Main.java
package movie;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.util.Collection;
import javax.xml.bind.JAXBContext;
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseFactory;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderError;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.definition.KnowledgePackage;
import org.drools.io.ResourceFactory;
import org.drools.runtime.StatefulKnowledgeSession;
import javax.xml.bind.Unmarshaller;
public class Main {
private StatefulKnowledgeSession session;
public Main(){
}
public void init() throws Exception {
KnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kBuilder.add( ResourceFactory.newFileResource( "movie/Movie.drl" ),
ResourceType.DRL );
if( kBuilder.hasErrors() ){
for( KnowledgeBuilderError err: kBuilder.getErrors() ){
System.out.println( err.toString() );
}
throw new IllegalStateException( "DRL errors" );
}
kBase.addKnowledgePackages( kBuilder.getKnowledgePackages() );
File xml = new File( "database.xml" );
JAXBContext jc = JAXBContext.newInstance( Database.class );
Unmarshaller u = jc.createUnmarshaller();
InputStream inputStream = new FileInputStream( xml );
Database db = (Database)u.unmarshal( inputStream );
inputStream.close();
session = kBase.newStatefulKnowledgeSession();
for( Movie m: db.getMovie() ){
session.insert( m );
}
for( Actor a: db.getActor() ){
session.insert( a );
}
for( Role r: db.getRole() ){
session.insert( r );
}
session.fireAllRules();
}
public static void main( String[] args ) throws Exception {
Main rf = new Main();
rf.init();
}
}
TheEnd
cat <<'TheEnd' >movie/Role.java
package movie;
import javax.xml.bind.annotation.XmlAttribute;
public class Role implements Item {
private String actor;
private String movie;
public Role(){
}
@XmlAttribute
public String getActor() {
return actor;
}
public void setActor(String actor) {
this.actor = actor;
}
@XmlAttribute
public String getMovie() {
return movie;
}
public void setMovie(String movie) {
this.movie = movie;
}
@Override
public String toString(){
return actor + " plays in " + movie;
}
}
TheEnd
cat <<'TheEnd' >movie/Movie.java
package movie;
import java.util.HashSet;
import java.util.Set;
import javax.xml.bind.annotation.XmlAttribute;
public class Movie implements Item {
private String title;
private Set<Actor> cast;
public Movie(){
}
@XmlAttribute
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Set<Actor> getCast(){
if( cast == null ) cast = new HashSet<Actor>();
return cast;
}
@Override
public int hashCode(){
return title.hashCode();
}
@Override
public boolean equals( Object o ){
if( ! (o instanceof Movie ) ) return false;
return this.title.equals( ((Movie)o).getTitle() );
}
@Override
public String toString(){
StringBuilder sb = new StringBuilder();
sb.append( title ).append( "\n" );
for( Actor a: getCast() ){
sb.append( " " ).append( a.getName() ).append( "\n" );
}
return sb.toString();
}
}
TheEnd
cat <<'TheEnd' >movie/Item.java
package movie;
/**
* Marker interface for WMEs
* @author Wolfgang Laun
*/
public interface Item {
}
TheEnd
cat <<'TheEnd' >movie/Database.java
package movie;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
@XmlRootElement
@XmlType(propOrder={"movie", "actor" , "role" })
public class Database {
private List<Movie> movie;
private List<Actor> actor;
private List<Role> role;
public Database(){
}
@XmlElement
public List<Movie> getMovie() {
if( movie == null ) movie = new ArrayList<Movie>();
return movie;
}
@XmlElement
public List<Actor> getActor() {
if( actor == null ) actor = new ArrayList<Actor>();
return actor;
}
@XmlElement
public List<Role> getRole() {
if( role == null ) role = new ArrayList<Role>();
return role;
}
}
TheEnd
cat <<'TheEnd' >movie/Actor.java
package movie;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAttribute;
public class Actor implements Item {
private String name;
private List<Movie> movies;
public Actor(){
}
@XmlAttribute
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<Movie> getMovies(){
if( movies == null ) movies = new ArrayList<Movie>();
return movies;
}
@Override
public String toString(){
StringBuilder sb = new StringBuilder();
sb.append( name ).append( "\n" );
for( Movie m: getMovies() ){
sb.append( " " ).append( m.getTitle() ).append( "\n" );
}
return sb.toString();
}
@Override
public int hashCode(){
return name.hashCode();
}
@Override
public boolean equals( Object o ){
if( ! (o instanceof Actor ) ) return false;
return this.name.equals( ((Actor)o).getName() );
}
}
TheEnd
cat <<'TheEnd' >movie/Movie.drl
package movie;
/***
- List<?> as fact field type
- Set<?> as fact field type
- Match WMEs with elements from field with List<?> type: from
- inline eval() for determining membership in Collection()
- Write rules for a set of WME types using a "marker" interface.
*/
#
# Fill the Movies' cast lists with data from Role.
#
rule fillCast
salience 100
when
$r : Role( $actor : actor, $movie : movie )
$a : Actor( name == $actor )
$m : Movie( title == $movie )
then
modify( $m ){
getCast().add( $a );
}
retract( $r );
end
#
# Fill the Actors' list of movies with data from a Movie's cast list
#
rule fillMovies
salience 90
when
$m : Movie( $cast : cast )
$a : Actor() from $cast
then
System.out.println( "movie " + $m.getTitle() + " actor " + $a.getName() );
modify( $a ){
getMovies().add( $m );
}
end
#
# Find a movie where HB and LB are in together
#
rule findHBLB
when
$hb : Actor( name == "Humphrey Bogart" )
$lb : Actor( name == "Lauren Bacall" )
$m : Movie( $title : title, $cast : cast, eval( $cast.contains( $hb ) && $cast.contains( $lb ) ) )
then
System.out.println( "HB & LB together in " + $title );
end
#
# Display any WME
#
rule showItem
salience -100
when
$i : Item()
then
System.out.println( $i.toString() );
end
TheEnd
cat <<'TheEnd' >database.xml
<?xml version="1.0" encoding="UTF-8"?>
<database>
<movie title="Casablanca"/>
<movie title="Key Largo"/>
<movie title="To Have and Have Not"/>
<movie title="The African Queen"/>
<actor name="Humphrey Bogart"/>
<actor name="Katherine Hepburn"/>
<actor name="Ingrid Bergman"/>
<actor name="Lauren Bacall"/>
<role actor="Humphrey Bogart" movie="Casablanca"/>
<role actor="Ingrid Bergman" movie="Casablanca"/>
<role actor="Humphrey Bogart" movie="The African Queen"/>
<role actor="Humphrey Bogart" movie="Key Largo"/>
<role actor="Humphrey Bogart" movie="To Have and Have Not"/>
<role actor="Lauren Bacall" movie="To Have and Have Not"/>
<role actor="Lauren Bacall" movie="Key Largo"/>
<role actor="Katherine Hepburn" movie="The African Queen"/>
</database>
TheEnd
export CLASSPATH=.:/extra/Drools-5.0.1.SNAPSHOT/drools-core.jar:/extra/Drools-5.0.1.SNAPSHOT/drools-api.jar:/extra/Drools-5.0.1.SNAPSHOT/drools-compiler.jar:/extra/Drools-5.0.1.SNAPSHOT/drools-ant.jar:/extra/Drools-5.0.1.SNAPSHOT/antlr-runtime.jar:/usr/local/eclipse/plugins/org.eclipse.jdt.core_3.4.4.v_894_R34x.jar:/extra/Drools-5.0.0.CR1/bin/lib/mvel2-2.0.8pre1.jar
javac movie/*.java
java movie/Main
cat <<'TheEnd'
#
# This is what I get:
#
movie Casablanca actor Ingrid Bergman
Exception in thread "main" org.drools.runtime.rule.ConsequenceException: java.lang.NullPointerException
at org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:23)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:943)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:885)
at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1086)
at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:682)
at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:649)
at org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:183)
at movie.Main.init(Main.java:65)
at movie.Main.main(Main.java:70)
Caused by: java.lang.NullPointerException
at org.drools.base.DefaultKnowledgeHelper.modifyRetract(DefaultKnowledgeHelper.java:190)
at movie.Rule_fillMovies_0.consequence(Rule_fillMovies_0.java:8)
at movie.Rule_fillMovies_0ConsequenceInvoker.evaluate(Rule_fillMovies_0ConsequenceInvoker.java:28)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:934)
... 7 more
TheEnd
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
14 years, 10 months
[JBoss JIRA] Created: (JBRULES-2191) CLONE -update(fact) doesn't work in ruleflow
by Neil Wallace (JIRA)
CLONE -update(fact) doesn't work in ruleflow
--------------------------------------------
Key: JBRULES-2191
URL: https://jira.jboss.org/jira/browse/JBRULES-2191
Project: JBoss Drools
Issue Type: Bug
Security Level: Public (Everyone can see)
Components: drools-core (expert), drools-core (flow)
Affects Versions: 5.0.0.CR1
Reporter: Neil Wallace
Assignee: Kris Verlaenen
Priority: Critical
Fix For: 5.0.1.FINAL
Hi,
org.drools.base.DefaultKnowledgeHelper uses newly added identityMap to keep track of fact handles. It looks like this identityMap is updated before a rule's consequence is called. However it is not updated before a Drools Flow on-exit action. This means that calling update(someFact) in a on-exit ruleflow action causes exception ("org.drools.FactException: Update error: handle not found for object: XXXXX. Is it in the working memory?").
this was tested on drools-core-5.0.0.20090417.044049-485.jar
Thanking you in advance.
Best Regards,
Michal
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
14 years, 10 months