[rules-users] Multithreaded update of facts in Drools 5.5 - how to ensure that a nested value isn't null
Hello, My question is: How can I ensure that a nested property isn't null (in a multithreaded environment)? This is the rule: rule Drools Test3: Concurrency dialect java when $testObj : TestObject( $ref : subObject, $ref != null, $ref.message != null ) then System.out.println(Received-04-A: + $testObj); end I am getting the following exception if I try to modify the fact in different threads. java.lang.NullPointerException: null at ConditionEvaluator8d1e3555e8c34810957bbb1670f51176.evaluate(null:-1) at org.drools.rule.constraint.MvelConstraint.evaluate(MvelConstraint.java:200) at org.drools.rule.constraint.MvelConstraint.isAllowed(MvelConstraint.java:157) at org.drools.reteoo.AlphaNode.modifyObject(AlphaNode.java:154) at org.drools.reteoo.SingleObjectSinkAdapter.propagateModifyObject(SingleObjectSinkAdapter.java:68) at org.drools.reteoo.AlphaNode.modifyObject(AlphaNode.java:157) at org.drools.reteoo.SingleObjectSinkAdapter.propagateModifyObject(SingleObjectSinkAdapter.java:68) at org.drools.reteoo.ObjectTypeNode.modifyObject(ObjectTypeNode.java:314) at org.drools.reteoo.EntryPointNode.modifyObject(EntryPointNode.java:265) at org.drools.common.NamedEntryPoint.update(NamedEntryPoint.java:483) at org.drools.common.AbstractWorkingMemory.update(AbstractWorkingMemory.java:976) at org.drools.common.AbstractWorkingMemory.update(AbstractWorkingMemory.java:949) at org.drools.impl.StatefulKnowledgeSessionImpl.update(StatefulKnowledgeSessionImpl.java:284) [...] There are two threads running which modify the same reference in a testobject (subObject). They trigger a queued update of the fact. One solution would be: - insert the nested object in drools - and modify the rule: rule Drools Test3: Concurrency 2 dialect java when $subObj : TestObject( message != null ) $testObj : TestObject( subObject == $subObj ) then System.out.println(Received-04-A: + $testObj); end Can I achieve a thread safety differently? Thanks and regards, Per Sterner ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] WorkingMemoryEntryPoints
Hello, We are upgrading our project from Drools 5.3 to Drools 5.5.0 and got some problems. We tried to locate the problem and it seems there is a problem with the WorkingMemoryEntryPoints? In our project everything is in WorkingMemoryEntryPoints. In this example all facts are in test_me. We removed the dependencies to the memoryentrypoint and then it works. The problem is with the WorkingMemoryEntryPoints that the Rule TestRule - set state_2 is triggered more then two times. The output is: SETTING STATE 2 STATE 2 STATE 1 STATE 1 SETTING STATE 2 STATE 2 SETTING STATE 2 STATE 2 SETTING STATE 2 STATE 2 [...] If we remove the entrypoints the output is: SETTING STATE 2 STATE 2 SETTING STATE 2 STATE 2 [And that's it] Is there something with the usage from the WorkingMemoryEntryPoints or is this a bug? Regards, Per Sterner TestObject.java --- public class TestObject { private String stateAsString; public void setStateAsString(final String stateAsString) { this.stateAsString = stateAsString; } public String getStateAsString() { return stateAsString; } } --- MyTicker.java --- public class MyTicker { private final long timeStart; private long time; public MyTicker() { timeStart = System.currentTimeMillis(); } public long getTime() { return time; } public void setTime(final long time) { this.time = time; } public long getTimeStart() { return timeStart; } } --- DroolsTest.java --- public class DroolsTest { public static void main(final String[] args) { KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add(ResourceFactory.newClassPathResource(TestDrools.drl, Init.class), ResourceType.DRL); if (kbuilder.hasErrors()) { System.out.println(kbuilder.getErrors().toString()); throw new RuntimeException(Unable to compile \HelloWorld.drl\.); } final CollectionKnowledgePackage pkgs = kbuilder.getKnowledgePackages(); final KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); kbase.addKnowledgePackages(pkgs); final StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession(); TestObject testObject1 = new TestObject(); testObject1.setStateAsString(STATE_1); TestObject testObject2 = new TestObject(); testObject2.setStateAsString(STATE_1); TestCache testCache = new TestCache(); MyTicker ticker = new MyTicker(); ticker.setTime(System.currentTimeMillis()); WorkingMemoryEntryPoint e = ksession.getWorkingMemoryEntryPoint(test_me); e.insert(testObject1); e.insert(testObject2); e.insert(testCache); FactHandle tickerHandle = e.insert(ticker); DroolsTickerThread droolsTickerThread = new DroolsTickerThread(droolstickerthread, ticker, ksession, tickerHandle); droolsTickerThread.start(); } public static class DroolsTickerThread extends Thread { private final DroolsTicker ticker; private final StatefulKnowledgeSession ksession; private final FactHandle tickerHandle; public DroolsTickerThread(final String name, final DroolsTicker ticker, final StatefulKnowledgeSession ksession, final FactHandle tickerHandle) { super(name); this.ticker = ticker; this.ksession = ksession; this.tickerHandle = tickerHandle; } @Override public void run() { WorkingMemoryEntryPoint entry = ksession.getWorkingMemoryEntryPoint(test_me); while (!isInterrupted()) { try { ticker.setTime(System.currentTimeMillis()); entry.update(tickerHandle, ticker); ksession.fireAllRules(); Thread.sleep(1000); } catch (InterruptedException e) { break; } } }; } } --- TestCache.java --- public class TestCache { private long lastCheckTimestamp = 0; public void setLastCheckTimestamp(final long lastCheckTimestamp) { this.lastCheckTimestamp = lastCheckTimestamp; } public long getLastCheckTimestamp() { return lastCheckTimestamp
Re: [rules-users] Why does it seem like salience is being ignored?
Hello, isn't there just mussing a '\n' before the word saliance in the line rule += rule rule1a salience 100 \n; ? Regards, Per Sterner Am 14.07.12 20:18, schrieb Ladd: I just tried the same test using 5.3.0 and got the same results. Rule1b fires first. -- View this message in context: http://drools.46999.n3.nabble.com/Why-does-it-seem-like-salience-is-being-ignored-tp4018669p4018687.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Drools 5.4.0.FINAL and OSGI. Unable to instantiate service for Class 'org.drools.concurrent.ExecutorProvider'
Hello, perhaps it is an equinox /eclipse.osgi problem? The drools-api and the drools-core bundle have the same packages 'org.drools.concurrent'. I wrote a little test bundle which only does a dynamic-import like the 'drools-api' bundle. The class org.drools.concurrent.ExecutorProviderFactory can be found with 'Class.forName()'. But the class org.drools.concurrent.ExecutorProviderImpl can't be found. (If I manually require drools-core 'Class.forName()' works for org.drools.concurrent.ExecutorProviderImpl) I have tried eclipse.osgi 3.6.1 , 3.7.2 and the current 3.8.0 Regards, Per Sterner On 01.06.2012 03:29, Mark Proctor wrote: Looks like you have some classpath issues and using the incorrect jar versions. On 29/05/2012 14:30, Per Sterner wrote: [ERROR] [System] - Caused by: java.lang.ClassNotFoundException: org.drools.concurrent.ExecutorProviderImpl ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Drools 5.4.0.FINAL and OSGI. Unable to instantiate service for Class 'org.drools.concurrent.ExecutorProvider'
I just found an old eclipse forum entry: http://www.eclipse.org/forums/index.php/mv/msg/90154/278597/#msg_278597 On 01.06.2012 03:29, Mark Proctor wrote: Looks like you have some classpath issues and using the incorrect jar versions. On 29/05/2012 14:30, Per Sterner wrote: [ERROR] [System] - Caused by: java.lang.ClassNotFoundException: org.drools.concurrent.ExecutorProviderImpl ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] Drools 5.4.0.FINAL and OSGI. Unable to instantiate service for Class 'org.drools.concurrent.ExecutorProvider'
); e.printStackTrace(); if (exception != null) { exception = new MyDroolsException(msg, exception); } else { exception = new MyDroolsException(msg); } exception = new MyDroolsException(e.getMessage(), exception); continue; } // All done! break; } final CollectionKnowledgePackage pkgs = kbuilder.getKnowledgePackages(); droolsSession.getKnowledgeBase().addKnowledgePackages(pkgs); if (exception != null) { throw new MyDroolsException(Error while adding resources!, exception); } } public KnowledgeBuilderFactoryService getDroolsKnowledgeBuilderFactoryService() { return droolsKnowledgeBuilderFactoryService; } public void setDroolsKnowledgeBuilderFactoryService( KnowledgeBuilderFactoryService droolsKnowledgeBuilderFactoryService) { this.droolsKnowledgeBuilderFactoryService = droolsKnowledgeBuilderFactoryService; } public ResourceFactoryService getDroolsResourceFactoryService() { return droolsResourceFactoryService; } public void setDroolsResourceFactoryService( ResourceFactoryService droolsResourceFactoryService) { this.droolsResourceFactoryService = droolsResourceFactoryService; } public KnowledgeBaseFactoryService getDroolsKnowledgeBaseFactoryService() { return droolsKnowledgeBaseFactoryService; } public void setDroolsKnowledgeBaseFactoryService( KnowledgeBaseFactoryService droolsKnowledgeBaseFactoryService) { this.droolsKnowledgeBaseFactoryService = droolsKnowledgeBaseFactoryService; } } Some of the bundles in my runtime are: 39ACTIVE org.drools.core_5.4.0.Final 66ACTIVE org.drools.compiler_5.4.0.Final 78ACTIVE org.drools.templates_5.4.0.Final 94ACTIVE org.drools.internalapi_5.4.0.Final 136ACTIVE org.drools.decisiontables_5.4.0.Final 189ACTIVE org.drools.api_5.4.0.Final 191ACTIVE org.mvel2_2.1.0.drools16 6ACTIVE org.jbpm.flow.core_5.3.0.Final 13ACTIVE org.jbpm.bpmn2_5.3.0.Final 71ACTIVE org.jbpm.flow.builder_5.3.0.Final 142ACTIVE org.jbpm.flow-persistence-jpa_5.3.0.FINAL regards, Per Sterner ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] Rule, import with wildcards and variable / patternBinding
Hello, Yesterday I wanted to upgrade my drools version to 5.3 (from 5.1). I got the exception java.lang.NoClassDefFoundError: de/pelle7/testpackage/event/myEvent (wrong name: de/pelle7/testpackage/event/MyEvent) while adding my resources. I removed the import wildcards and the error disappeard. Finally I found the problem: I used the patternBinding 'myEvent' and there is a class called 'MyEvent' and I used an wildcard import where the class 'MyEvent' is located. Example code: package de.pelle7.testrules.impl.drools import de.pelle7.testpackage.event.* rule Test rule 1 dialect java salience 50 when myEvent : MyEvent( ) myEvent2 : MyEvent( data == myEvent.data ) -- here the Exception is thrown then System.err.println(Output); end My solution is that I replaced all my pattern bindings with the suffix '$' which is more convenient. Perhaps it would be nice to produce an rule-compilation error. with a line notice. Regard, Per Sterner ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users