[JBoss JIRA] Created: (JBRULES-2211) StatefulKnowledgeSession leaves threads running
by Edson Tirelli (JIRA)
StatefulKnowledgeSession leaves threads running
-----------------------------------------------
Key: JBRULES-2211
URL: https://jira.jboss.org/jira/browse/JBRULES-2211
Project: JBoss Drools
Issue Type: Bug
Security Level: Public (Everyone can see)
Components: drools-core
Affects Versions: 5.0.1.FINAL, 5.0.0.FINAL
Reporter: Edson Tirelli
Assignee: Edson Tirelli
Fix For: 5.1.0.M1
Hi all,
I've downloaded Drools fusion sample and started to make some changes to
the code (first of all wipe out the UI so I can test it easier).
I tried to get to a minimal set so I can run a console main class and see
what happens but I am facing a strange behaviour.
As soon as I start pushing events into the WorkingMemoryEntryPoint
("StockTick stream") a Thread - not daemonized since it blocks shutdown from
ending - is spawned and this prevents my JVM from shutting down (obviously
if I call System.exit(0) it will but I am avoiding this).
I've tried both to halt and dispose the session that this entry point
belongs but with no success. Does anyone know how could I get rid of this
thread?
==================
Hi Edson!
as I've already mentioned I've modified the sample so, if you get the StockTick sample and replace the Main class this will run fine.
The sample shuts down fine but as I saw it sets the JFrame uses frame.setDefaultCloseOperation( WindowConstants.EXIT_ON_CLOSE ); which in turn makes the trick.
Below the code of my modified main class:
package org.drools.examples.broker;
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseConfiguration;
import org.drools.KnowledgeBaseFactory;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.conf.EventProcessingOption;
import org.drools.examples.broker.model.Company;
import org.drools.examples.broker.model.CompanyRegistry;
import org.drools.examples.broker.model.StockTick;
import org.drools.io.ResourceFactory;
import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.runtime.rule.WorkingMemoryEntryPoint;
public class Main {
private static final String RULES_FILE = "/broker.drl";
static StatefulKnowledgeSession session;
static WorkingMemoryEntryPoint tickStream;
/**
* @param args
*/
public static void main(String[] args) throws Exception {
// set up and show main window
CompanyRegistry companies = new CompanyRegistry();
KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder();
try {
builder.add( ResourceFactory.newInputStreamResource( Main.class.getResourceAsStream( RULES_FILE ) ),
ResourceType.DRL);
} catch ( Exception e ) {
e.printStackTrace();
}
if( builder.hasErrors() ) {
System.err.println(builder.getErrors());
System.exit( 0 );
}
KnowledgeBaseConfiguration conf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
conf.setOption( EventProcessingOption.STREAM );
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase( conf );
kbase.addKnowledgePackages( builder.getKnowledgePackages() );
session = kbase.newStatefulKnowledgeSession();
session.setGlobal( "services", new BrokerServices() {
public void log(String message) {
System.out.println(message);
}
});
for( Company company : companies.getCompanies() ) {
session.insert( company );
}
session.fireAllRules();
tickStream = session.getWorkingMemoryEntryPoint( "StockTick stream" );
for (int i=10;i>0;i--) {
tickStream.insert(new StockTick("RHT", i*10, System.currentTimeMillis()));
session.getAgenda().getAgendaGroup( "evaluation" ).setFocus();
session.fireAllRules();
}
session.dispose();
session.halt();
System.out.println("Still running...");
}
}
regards,
Rafael Ribeiro
--
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
15 years
[JBoss JIRA] Created: (JBRULES-2778) Rule with timer( int: 1m 1m ( causes ArrayStoreException in PackageBuilder
by Wolfgang Laun (JIRA)
Rule with timer( int: 1m 1m ( causes ArrayStoreException in PackageBuilder
--------------------------------------------------------------------------
Key: JBRULES-2778
URL: https://jira.jboss.org/browse/JBRULES-2778
Project: Drools
Issue Type: Bug
Security Level: Public (Everyone can see)
Components: drools-compiler
Affects Versions: 5.1.1.FINAL
Reporter: Wolfgang Laun
Assignee: Mark Proctor
Fix For: 5.2.0.M1
A single rule in a DRL file:
rule "minute ticker"
timer( int: 1m 1m )
when
then
System.out.println( "Tick" );
end
causes
xception in thread "main" java.lang.ArrayStoreException
at java.lang.System.arraycopy(Native Method)
at java.util.ArrayList.toArray(ArrayList.java:328)
at org.drools.compiler.PackageBuilder.getErrors(PackageBuilder.java:1274)
at org.drools.builder.impl.KnowledgeBuilderImpl.getErrors(KnowledgeBuilderImpl.java:70)
at event.Main.compilePackage(Main.java:72)
at event.Main.main(Main.java:219)
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
15 years
[JBoss JIRA] Created: (JBRULES-2675) Syntax error in /trunk/src/documentation/index.html
by Lawrence Terrill (JIRA)
Syntax error in /trunk/src/documentation/index.html
---------------------------------------------------
Key: JBRULES-2675
URL: https://jira.jboss.org/browse/JBRULES-2675
Project: Drools
Issue Type: Bug
Security Level: Public (Everyone can see)
Components: All
Affects Versions: 5.1.0.FINAL, 5.1.0.CR1, 5.1.0.M2, 5.1.0.M1, 5.0.1.FINAL, 5.1.1.FINAL, 5.2.0.M1, FUTURE
Reporter: Lawrence Terrill
Assignee: Mark Proctor
Priority: Trivial
In in /trunk/src/documentation/index.html, in the first <tr> group for drools-introduction, the last <td> group for the pdf reference, drools-introduction/pdf/drools-docs-introduction.pdf, is commented out. The ending comment tag is malformed entered as '</td>--' instead of the intended '</td-->'
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
15 years
[JBoss JIRA] Created: (JBRULES-2380) KnowledgeBuilderImpl.add(...) throws org.mvel2.CompileException when executed concurrently for the same resource
by Grigoriy Grigoriev (JIRA)
KnowledgeBuilderImpl.add(...) throws org.mvel2.CompileException when executed concurrently for the same resource
----------------------------------------------------------------------------------------------------------------
Key: JBRULES-2380
URL: https://jira.jboss.org/jira/browse/JBRULES-2380
Project: Drools
Issue Type: Quality Risk
Security Level: Public (Everyone can see)
Environment: Drools 5.0.1
core 2 duo @ 2.6 ghz, win xp prof sp3, sun jdk 1.6.0_17
Pentium Dual CPU E2160 @ 1.8GHz, XP prof SP3, sun jdk 1.6.0_16.
Reporter: Grigoriy Grigoriev
Assignee: Mark Proctor
Let us assume a multithreaded application, that tries to initialise & start several processes using a StatefulKnowledgeSession in order to use in these processes rule flow. The flow in all the processes is the same but every process instance must have an own StatefulKnowledgeSession instance because of stateful session.
Actually the problem:
At the initializing phase occurs an org.mvel2.CompileException exception from time to time at KnowledgeBuilder.add(...):
Exception in thread "Thread-60" [Error: incomplete statement: (possible use of reserved keyword as identifier: )]
[Near : {... globals != empt ....}]
^
[Line: 0, Column: 0]
at org.mvel2.MVELInterpretedRuntime.parseAndExecuteInterpreted(MVELInterpretedRuntime.java:153)
at org.mvel2.MVELInterpretedRuntime.parse(MVELInterpretedRuntime.java:44)
at org.mvel2.MVEL.eval(MVEL.java:514)
at org.mvel2.templates.res.IfNode.eval(IfNode.java:61)
at org.mvel2.templates.res.TextNode.eval(TextNode.java:46)
at org.mvel2.templates.res.TerminalNode.eval(TerminalNode.java:39)
at org.mvel2.templates.res.ForEachNode.eval(ForEachNode.java:116)
at org.mvel2.templates.res.TextNode.eval(TextNode.java:46)
at org.mvel2.templates.res.TerminalNode.eval(TerminalNode.java:39)
at org.mvel2.templates.res.IfNode.eval(IfNode.java:64)
at org.mvel2.templates.res.TextNode.eval(TextNode.java:46)
at org.mvel2.templates.res.ExpressionNode.eval(ExpressionNode.java:53)
at org.mvel2.templates.res.TextNode.eval(TextNode.java:46)
at org.mvel2.templates.TemplateRuntime.execute(TemplateRuntime.java:195)
at org.mvel2.templates.TemplateRuntime.execute(TemplateRuntime.java:190)
at org.mvel2.templates.TemplateRuntime.execute(TemplateRuntime.java:180)
at org.mvel2.templates.TemplateRuntime.execute(TemplateRuntime.java:169)
at org.drools.rule.builder.dialect.java.AbstractJavaRuleBuilder.generatTemplates(AbstractJavaRuleBuilder.java:126)
at org.drools.rule.builder.dialect.java.JavaConsequenceBuilder.build(JavaConsequenceBuilder.java:128)
at org.drools.rule.builder.RuleBuilder.build(RuleBuilder.java:86)
at org.drools.compiler.PackageBuilder.addRule(PackageBuilder.java:1159)
at org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:649)
at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:290)
at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:488)
at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:25)
at com.myfirm.RuleFlowProcess.init(RuleFlowProcess.java:25)
at com.myfirm.RuleFlowProcess.clone(RuleFlowProcess.java:53)
at com.myfirm.ThreadTest$CloneThread.run(ThreadTest.java:35)
Caused by: java.lang.NullPointerException
at org.mvel2.MVELInterpretedRuntime.parseAndExecuteInterpreted(MVELInterpretedRuntime.java:113)
... 27 more
Exception in thread "Thread-72" [Error: incomplete statement: (possible use of reserved keyword as identifier: )]
[Near : {... declarations != empt ....}]
^
[Line: 0, Column: 0]
at org.mvel2.MVELInterpretedRuntime.parseAndExecuteInterpreted(MVELInterpretedRuntime.java:153)
at org.mvel2.MVELInterpretedRuntime.parse(MVELInterpretedRuntime.java:44)
at org.mvel2.MVEL.eval(MVEL.java:514)
at org.mvel2.templates.res.IfNode.eval(IfNode.java:61)
at org.mvel2.templates.res.TextNode.eval(TextNode.java:46)
at org.mvel2.templates.res.ExpressionNode.eval(ExpressionNode.java:53)
at org.mvel2.templates.res.TextNode.eval(TextNode.java:46)
at org.mvel2.templates.res.ExpressionNode.eval(ExpressionNode.java:53)
at org.mvel2.templates.res.TextNode.eval(TextNode.java:46)
at org.mvel2.templates.res.TerminalNode.eval(TerminalNode.java:39)
at org.mvel2.templates.res.ForEachNode.eval(ForEachNode.java:116)
at org.mvel2.templates.res.TextNode.eval(TextNode.java:46)
at org.mvel2.templates.res.TerminalNode.eval(TerminalNode.java:39)
at org.mvel2.templates.res.ForEachNode.eval(ForEachNode.java:116)
at org.mvel2.templates.res.TextNode.eval(TextNode.java:46)
at org.mvel2.templates.res.ExpressionNode.eval(ExpressionNode.java:53)
at org.mvel2.templates.res.TextNode.eval(TextNode.java:46)
at org.mvel2.templates.res.ExpressionNode.eval(ExpressionNode.java:53)
at org.mvel2.templates.res.TextNode.eval(TextNode.java:46)
at org.mvel2.templates.TemplateRuntime.execute(TemplateRuntime.java:195)
at org.mvel2.templates.TemplateRuntime.execute(TemplateRuntime.java:190)
at org.mvel2.templates.TemplateRuntime.execute(TemplateRuntime.java:180)
at org.mvel2.templates.TemplateRuntime.execute(TemplateRuntime.java:169)
at org.drools.rule.builder.dialect.java.AbstractJavaRuleBuilder.generatTemplates(AbstractJavaRuleBuilder.java:135)
at org.drools.rule.builder.dialect.java.JavaConsequenceBuilder.build(JavaConsequenceBuilder.java:128)
at org.drools.rule.builder.RuleBuilder.build(RuleBuilder.java:86)
at org.drools.compiler.PackageBuilder.addRule(PackageBuilder.java:1159)
at org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:649)
at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:290)
at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:488)
at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:25)
at com.myfirm.RuleFlowProcess.init(RuleFlowProcess.java:25)
at com.myfirm.RuleFlowProcess.clone(RuleFlowProcess.java:53)
at com.myfirm.ThreadTest$CloneThread.run(ThreadTest.java:35)
Caused by: java.lang.NullPointerException
at org.mvel2.MVELInterpretedRuntime.parseAndExecuteInterpreted(MVELInterpretedRuntime.java:113)
... 33 more
To demonstrate this problem I have created a simple test maven project that reproduces this error (s. attach):
I have a class that creates & inits stateful knowledge session in a init method (RuleFlowProcess):
/**
* inits the rule flow
*/
public class RuleFlowProcess {
private StatefulKnowledgeSession ksession;
public void init() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("threadSafeTest.rf"), ResourceType.DRF);
kbuilder.add(ResourceFactory.newClassPathResource("testRules1.drl"), ResourceType.DRL);
kbuilder.add(ResourceFactory.newClassPathResource("testRules2.drl"), ResourceType.DRL);
kbuilder.add(ResourceFactory.newClassPathResource("testRules3.drl"), ResourceType.DRL);
kbuilder.add(ResourceFactory.newClassPathResource("testRules4.drl"), ResourceType.DRL);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
StringBuilder errorString = new StringBuilder();
for (KnowledgeBuilderError error : errors) {
errorString.append(error);
}
throw new RuntimeException(errorString.toString());
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
ksession = kbase.newStatefulKnowledgeSession();
}
...
}
I create & init concurrently in several (200) threads this RuleFlowProcess and some threads crash with this exceptions while adding the resources.
--
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
15 years
[JBoss JIRA] Created: (JBRULES-2738) osgi-bundles: the slf4j and the ant version differ from the ones in the main drools build
by Geoffrey De Smet (JIRA)
osgi-bundles: the slf4j and the ant version differ from the ones in the main drools build
-----------------------------------------------------------------------------------------
Key: JBRULES-2738
URL: https://jira.jboss.org/browse/JBRULES-2738
Project: Drools
Issue Type: Task
Security Level: Public (Everyone can see)
Components: All
Affects Versions: 5.1.1.FINAL
Reporter: Geoffrey De Smet
Assignee: Mark Proctor
Priority: Minor
Fix For: 5.2.0.M1
Since I am upgrading ant from 1.6.5 to 1.8.1 (to get the build working in maven 3),
I noticed that osgi-bundles uses a totally different version: 1.71
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>com.springsource.org.apache.tools.ant</artifactId>
<version>1.7.1</version>
</dependency>
Also, slf4j is 1.6 in drools, but 1.5.10 for the osgi-bundles.
That could cause an ugly MethotNotFoundError at runtime (if someone on trunk start using the 1.6 new methods),
or bugs with the osgi users which we can't reproduce in the non-osgi bundles.
Mark, I am not sure how the osgi-bundles build works, but if you explain it's purpose to me, I can handle this issue.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
15 years
[JBoss JIRA] Created: (JBRULES-2335) StackOverflowError on serialization of KnowledgeBase
by Justin Waugh (JIRA)
StackOverflowError on serialization of KnowledgeBase
----------------------------------------------------
Key: JBRULES-2335
URL: https://jira.jboss.org/jira/browse/JBRULES-2335
Project: Drools
Issue Type: Bug
Security Level: Public (Everyone can see)
Components: drools-core
Affects Versions: 5.0.1.FINAL
Environment: Windows, JDK 1.6
Reporter: Justin Waugh
Assignee: Mark Proctor
This is a bit of a duplicate of another issue, which I will link, however I only tested against 5.0.1 and I have a proposed solution which I believe is only applicable to 5.0.1 +
The problem is of course, that when serializing a KnowledgeBase with a very large amount of rules, it can potentially cause a StackOverflowError on serialization. As far as I can tell this is due to the linked lists held by ObjectSinkNodeList and LeftTupleSinkNodeList. The problem is that they recursively serialize the list, by serializing the first node, which serializes its next node, which serializes its next node.... and so on. This was a bit harder to solve in the 4.0+ case I think as it relied purely on the built in java serialization. However in 5.0+ those classes all use write/readExternal to do their own serialization. That makes it a bit easier to solve, as we can now implement an iterative serialization for the lists.
The problem code looks like this:
ObjectSinkNodeList (also applies to LeftTupleSinkNodeList):
public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
firstNode = (ObjectSinkNode) in.readObject();
lastNode = (ObjectSinkNode) in.readObject();
size = in.readInt();
}
public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject( firstNode );
out.writeObject( lastNode );
out.writeInt( size );
}
AlphaNode (and all others implementing ObjectSinkNode, and similarly LeftTupleSinkNode):
public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
super.readExternal( in );
constraint = (AlphaNodeFieldConstraint) in.readObject();
previousRightTupleSinkNode = (ObjectSinkNode) in.readObject();
nextRightTupleSinkNode = (ObjectSinkNode) in.readObject();
}
public void writeExternal(ObjectOutput out) throws IOException {
super.writeExternal( out );
out.writeObject( constraint );
out.writeObject( previousRightTupleSinkNode );
out.writeObject( nextRightTupleSinkNode );
}
As you can see it recursively serializes the list, so the stack depth increases linearly with the list length.
The solution is this:
ObjectSinkNodeList (also applies to LeftTupleSinkNodeList):
public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
firstNode = (ObjectSinkNode) in.readObject();
lastNode = (ObjectSinkNode) in.readObject();
size = in.readInt();
ObjectSinkNode current = firstNode;
while(current != null)
{
ObjectSinkNode previous = (ObjectSinkNode) in.readObject();
ObjectSinkNode next = (ObjectSinkNode) in.readObject();
current.setPreviousObjectSinkNode(previous);
current.setNextObjectSinkNode(next);
current = next;
}
}
public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject( firstNode );
out.writeObject( lastNode );
out.writeInt( size );
for (ObjectSinkNode node = firstNode; node != null; node = node.getNextObjectSinkNode())
{
out.writeObject(node.getPreviousObjectSinkNode());
out.writeObject(node.getNextObjectSinkNode());
}
}
AlphaNode (and all others implementing ObjectSinkNode, and similarly LeftTupleSinkNode):
public void writeExternal(ObjectOutput out) throws IOException {
super.writeExternal( out );
out.writeObject( constraint );
}
public AlphaNodeFieldConstraint getConstraint() {
return this.constraint;
}
As you can see the responsibility for serializing the list node links is now placed into the list objects themselves, and is performed iteratively. I suppose technically the lastNode reference of the list doesn't need to be stored separately, but it was just easier code.
The obvious concern here is if for some reason you had linked nodes which were not held by one of the list objects, then the links would be lost. However I checked references to the get/set of the prev/next, and they were only referenced by the list objects themselves, so I believe there is no chance for that to happen.
I'll attach a test case (but it's just the one from the linked ticket)
--
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
15 years