Guvnor: Accessing Bound Variable in "Then" Statement
by Vann_the_Red
Hello. I started with a search and didn't find an answer. I apologize if my
search-fu was lacking today.
I'm a non-developer tasked with rules creation and testing using guvnor. I
have found some scenarios where I can bind a variable to either the whole
input model or a fact in the input model and then later access those in the
output model by selecting "Bound Variable" from the popup box in the Then
statement. In other scenarios, "Bound Variable" is not an option (only
Literal or Formula). What must I do to be able to access the bound
variables from the When statement(s) in the Then statement(s)?
TIA,
Vann
This is a repost because I wasn't on the mailing list yet and I gather most
didn't see it. Apologies again.
--
View this message in context: http://drools.46999.n3.nabble.com/Guvnor-Accessing-Bound-Variable-in-Then...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 11 months
fact updates with query-only usage of Drools
by Andras Nagy
Dear All,
In a multithreaded application I plan to use Drools the following way:
-use only queries but not rules
-keep an outside reference to all facts inserted into the working memory,
and keep modifying the facts after they were inserted
-use locks synchronizing outside fact changes and Drools query executions
(happening parallelly on other threads), to make sure that when the queries
are executed, the facts are always in a consistent state
Given that the application only uses queries (and no rules), I wonder if
there is a need to notify the engine of the fact changes (e.g.
workingMemory.update(...) etc.).
Could someone confirm that?
Thank you,
Andras
12 years, 11 months
Re: [rules-users] IllegalStateException when disposing of a persisted session
by Thomas Grayson
For whoever is interested, I determined why StatefulKnowledgeSession.dispose threw an IllegalStateException for a persisted session. The error message refers to the thread, which led me to discover that the dispose would work if it was executed on the same thread where it had been created. The org.springframework.transaction.support.TransactionSynchronizationManager.unbindResource method at the top of the stack trace attempts to look up the resource in ThreadLocal storage. My shutdown hook was running on a different thread, so this lookup was failing.
I used the standard Java wait/notify mechanism to fix this. I now suspend my main thread after it creates the knowledge session with Object.wait. When the shutdown hook thread runs, it calls Object.notifyAll to release the main thread, which then disposes of the session successfully. The rest of my application runs in other threads, so suspending the main thread causes no harm.
I still would appreciate some clarification of how the "Configuring JTA DataSource" code<http://docs.jboss.org/drools/release/5.5.0.Final/drools-expert-docs/html/...> in the documentation is meant to be used.
Thanks,
Tom
From: rules-users-bounces(a)lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Thomas Grayson
Sent: Wednesday, June 12, 2013 3:42 PM
To: Rules Users List
Subject: [rules-users] IllegalStateException when disposing of a persisted session
We are using Drools persistence with a StatefulKnowledgeSession. The persistence itself works fine, but I am encountering an IllegalStateException when disposing of the StatefulKnowledgeSession. This happens with either a brand new session with no facts or one that has had facts added to it. It also happens with sessions that have been restored from the persistent store. The code does no explicit transaction management and relies on Drools to do this under the covers. We are using Drools 5.5.0 Final. How do I dispose of a session correctly?
The documentation<http://docs.jboss.org/drools/release/5.5.0.Final/drools-expert-docs/html/...> includes Example 3.66, "Configuring JTA DataSource." My code does not include code like this anywhere. Do I need it? It's not clear from the example where the PoolingDataSource instance would be used or when this code should be called. If this configuration is required, can it be done via Spring instead of programmatically?
I'll provide some supporting information below. I've edited these excerpts to redact some private details and eliminate distracting code, but the substance is intact.
Here is the stack trace created by invoking the "dispose" method from a shutdown hook:
java.lang.IllegalStateException: No value for key [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean@732e3e73] bound to thread [Thread-3]
at org.springframework.transaction.support.TransactionSynchronizationManager.unbindResource(TransactionSynchronizationManager.java:209)
at org.drools.container.spring.beans.persistence.DroolsSpringJpaManager.dispose(DroolsSpringJpaManager.java:135)
at org.drools.persistence.SingleSessionCommandService.execute(SingleSessionCommandService.java:345)
at org.drools.command.impl.CommandBasedStatefulKnowledgeSession.dispose(CommandBasedStatefulKnowledgeSession.java:241)
at MyClass1.stop
at MyClass2$1.run
at java.lang.Thread.run(Unknown Source)
The code uses Drools-Spring to configure the knowledge base and Java code to initialize the knowledge session. We're using JPA, the Bitronix transaction manager, and the H2 database, basically as described in the documentation<http://docs.jboss.org/drools/release/5.5.0.Final/droolsjbpm-introduction-...>. Here is the code for creating the session:
ApplicationContext context = new ClassPathXmlApplicationContext(APPLICATION_CONTEXT_XML);
KnowledgeStoreService kstore = (KnowledgeStoreService) context.getBean("myAppKnowledgeStore");
KnowledgeBase kbase = ...; // initialized by Spring configuration
Environment env = KnowledgeBaseFactory.newEnvironment();
env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, context.getBean("entityManagerFactory"));
env.set(EnvironmentName.TRANSACTION_MANAGER, context.getBean("txManager"));
StatefulKnowledgeSession ksession = kstore.newStatefulKnowledgeSession(kbase, null, env);
Here is the relevant portion of the Spring ApplicationContext.xml file:
<bean id="dataSourceH2"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.h2.Driver" />
<property name="url" value="jdbc:h2:tcp://localhost/~/myApp" />
<property name="username" value="sa" />
<property name="password" value="" />
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSourceH2" />
<property name="persistenceUnitName" value="myAppH2" />
</bean>
<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<drools:grid-node id="myAppEngineNode" />
<drools:kstore id="myAppKnowledgeStore" />
<drools:kbase id="myAppEngineKBase" node="MyAppEngineNode">
<drools:configuration>
<drools:assert-behavior mode="EQUALITY" />
</drools:configuration>
<drools:resources>
<drools:resource type="DRL" source="classpath:MyAppInternalRules.drl" />
<drools:resource type="DTABLE" source="classpath:MyAppRules.xls" >
<drools:decisiontable-conf input-type="XLS" worksheet-name="Sheet 1" />
</drools:resource>
<drools:resource type="DTABLE" source="classpath:MyAppRules.xls" >
<drools:decisiontable-conf input-type="XLS" worksheet-name="Sheet 2" />
</drools:resource>
</drools:resources>
</drools:kbase>
Here is the relevant part of the persistence.xml file:
<persistence-unit name="myAppH2">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>org.drools.persistence.info.SessionInfo</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
<property name="hibernate.max_fetch_depth" value="3" />
<property name="hibernate.hbm2ddl.auto" value="UPDATE" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.connection.autocommit" value="true" />
<property name="hibernate.transaction.manager_lookup_class" value= "org.hibernate.transaction.BTMTransactionManagerLookup"/>
</properties>
</persistence-unit>
I have a jndi.properties that's identical to what's in the documentation<http://docs.jboss.org/drools/release/5.5.0.Final/drools-expert-docs/html/...>.
I noticed in the documentation (Example 3.65, Configuring JPA) that the persistence-unit block is defined a bit differently. In particular, transaction-type is specified and a jta-data-source are defined, unlike in my file:
<persistence-unit name="org.drools.persistence.jpa" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/BitronixJTADataSource</jta-data-source>
...
</persistence-unit>
I tried defining these as shown, but then the code failed on startup when it tried to create a transaction:
org.drools.container.spring.beans.persistence.DroolsSpringTransactionManager: Unable to begin transaction
org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is java.lang.IllegalStateException: A JTA EntityManager cannot use getTransaction()
at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:427)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
at org.drools.container.spring.beans.persistence.DroolsSpringTransactionManager.begin(DroolsSpringTransactionManager.java:48)
at org.drools.persistence.SingleSessionCommandService.<init>(SingleSessionCommandService.java:190)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.buildCommandService(KnowledgeStoreServiceImpl.java:100)
at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.loadStatefulKnowledgeSession(KnowledgeStoreServiceImpl.java:83)
at MyClass1.initializeKnowledgeSession
at MyClass1.initializeKnowledgeEngine
at MyClass2.main
Caused by: java.lang.IllegalStateException: A JTA EntityManager cannot use getTransaction()
at org.hibernate.ejb.AbstractEntityManagerImpl.getTransaction(AbstractEntityManagerImpl.java:996)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:365)
at com.sun.proxy.$Proxy16.getTransaction(Unknown Source)
at org.springframework.orm.jpa.DefaultJpaDialect.beginTransaction(DefaultJpaDialect.java:70)
at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:377)
... 12 more
Thanks,
Tom
12 years, 11 months
IllegalStateException when disposing of a persisted session
by Thomas Grayson
We are using Drools persistence with a StatefulKnowledgeSession. The persistence itself works fine, but I am encountering an IllegalStateException when disposing of the StatefulKnowledgeSession. This happens with either a brand new session with no facts or one that has had facts added to it. It also happens with sessions that have been restored from the persistent store. The code does no explicit transaction management and relies on Drools to do this under the covers. We are using Drools 5.5.0 Final. How do I dispose of a session correctly?
The documentation<http://docs.jboss.org/drools/release/5.5.0.Final/drools-expert-docs/html/...> includes Example 3.66, "Configuring JTA DataSource." My code does not include code like this anywhere. Do I need it? It's not clear from the example where the PoolingDataSource instance would be used or when this code should be called. If this configuration is required, can it be done via Spring instead of programmatically?
I'll provide some supporting information below. I've edited these excerpts to redact some private details and eliminate distracting code, but the substance is intact.
Here is the stack trace created by invoking the "dispose" method from a shutdown hook:
java.lang.IllegalStateException: No value for key [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean@732e3e73] bound to thread [Thread-3]
at org.springframework.transaction.support.TransactionSynchronizationManager.unbindResource(TransactionSynchronizationManager.java:209)
at org.drools.container.spring.beans.persistence.DroolsSpringJpaManager.dispose(DroolsSpringJpaManager.java:135)
at org.drools.persistence.SingleSessionCommandService.execute(SingleSessionCommandService.java:345)
at org.drools.command.impl.CommandBasedStatefulKnowledgeSession.dispose(CommandBasedStatefulKnowledgeSession.java:241)
at MyClass1.stop
at MyClass2$1.run
at java.lang.Thread.run(Unknown Source)
The code uses Drools-Spring to configure the knowledge base and Java code to initialize the knowledge session. We're using JPA, the Bitronix transaction manager, and the H2 database, basically as described in the documentation<http://docs.jboss.org/drools/release/5.5.0.Final/droolsjbpm-introduction-...>. Here is the code for creating the session:
ApplicationContext context = new ClassPathXmlApplicationContext(APPLICATION_CONTEXT_XML);
KnowledgeStoreService kstore = (KnowledgeStoreService) context.getBean("myAppKnowledgeStore");
KnowledgeBase kbase = ...; // initialized by Spring configuration
Environment env = KnowledgeBaseFactory.newEnvironment();
env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, context.getBean("entityManagerFactory"));
env.set(EnvironmentName.TRANSACTION_MANAGER, context.getBean("txManager"));
StatefulKnowledgeSession ksession = kstore.newStatefulKnowledgeSession(kbase, null, env);
Here is the relevant portion of the Spring ApplicationContext.xml file:
<bean id="dataSourceH2"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.h2.Driver" />
<property name="url" value="jdbc:h2:tcp://localhost/~/myApp" />
<property name="username" value="sa" />
<property name="password" value="" />
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSourceH2" />
<property name="persistenceUnitName" value="myAppH2" />
</bean>
<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<drools:grid-node id="myAppEngineNode" />
<drools:kstore id="myAppKnowledgeStore" />
<drools:kbase id="myAppEngineKBase" node="MyAppEngineNode">
<drools:configuration>
<drools:assert-behavior mode="EQUALITY" />
</drools:configuration>
<drools:resources>
<drools:resource type="DRL" source="classpath:MyAppInternalRules.drl" />
<drools:resource type="DTABLE" source="classpath:MyAppRules.xls" >
<drools:decisiontable-conf input-type="XLS" worksheet-name="Sheet 1" />
</drools:resource>
<drools:resource type="DTABLE" source="classpath:MyAppRules.xls" >
<drools:decisiontable-conf input-type="XLS" worksheet-name="Sheet 2" />
</drools:resource>
</drools:resources>
</drools:kbase>
Here is the relevant part of the persistence.xml file:
<persistence-unit name="myAppH2">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>org.drools.persistence.info.SessionInfo</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
<property name="hibernate.max_fetch_depth" value="3" />
<property name="hibernate.hbm2ddl.auto" value="UPDATE" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.connection.autocommit" value="true" />
<property name="hibernate.transaction.manager_lookup_class" value= "org.hibernate.transaction.BTMTransactionManagerLookup"/>
</properties>
</persistence-unit>
I have a jndi.properties that's identical to what's in the documentation<http://docs.jboss.org/drools/release/5.5.0.Final/drools-expert-docs/html/...>.
I noticed in the documentation (Example 3.65, Configuring JPA) that the persistence-unit block is defined a bit differently. In particular, transaction-type is specified and a jta-data-source are defined, unlike in my file:
<persistence-unit name="org.drools.persistence.jpa" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/BitronixJTADataSource</jta-data-source>
...
</persistence-unit>
I tried defining these as shown, but then the code failed on startup when it tried to create a transaction:
org.drools.container.spring.beans.persistence.DroolsSpringTransactionManager: Unable to begin transaction
org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is java.lang.IllegalStateException: A JTA EntityManager cannot use getTransaction()
at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:427)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
at org.drools.container.spring.beans.persistence.DroolsSpringTransactionManager.begin(DroolsSpringTransactionManager.java:48)
at org.drools.persistence.SingleSessionCommandService.<init>(SingleSessionCommandService.java:190)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.buildCommandService(KnowledgeStoreServiceImpl.java:100)
at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.loadStatefulKnowledgeSession(KnowledgeStoreServiceImpl.java:83)
at MyClass1.initializeKnowledgeSession
at MyClass1.initializeKnowledgeEngine
at MyClass2.main
Caused by: java.lang.IllegalStateException: A JTA EntityManager cannot use getTransaction()
at org.hibernate.ejb.AbstractEntityManagerImpl.getTransaction(AbstractEntityManagerImpl.java:996)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:365)
at com.sun.proxy.$Proxy16.getTransaction(Unknown Source)
at org.springframework.orm.jpa.DefaultJpaDialect.beginTransaction(DefaultJpaDialect.java:70)
at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:377)
... 12 more
Thanks,
Tom
12 years, 11 months
Decision table invoked frm Spring app
by Raju Bandaru
Hi,
Am new to guvnor . I have created decision table based rules in guvnor which
is located in tomcat server and now i want to invoke that rule from my
sample spring application .
I don't know how to do that even searched lot but couldn't find any proper
answer so please help me its very urgent for me .
Concept is to invoke a decision table based rule created from guvnor from
spring application and modify it .
Please help me .
Regards,
Raju
--
View this message in context: http://drools.46999.n3.nabble.com/Decision-table-invoked-frm-Spring-app-t...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 11 months
Guvnor Rule Validation
by rjr201
I'm creating a system which embeds the Guvnor Guided Editor and uses the REST
API to allow the user to edit and create rules.
I can't trust the user to create syntactically correct rules. If they do
create an invalid rule then the whole package of rules will fail to compile.
I need to find a way to detect that a individual rule has broken, and point
the user to that rule. So they don't just sit there not understanding why
it's not working.
I can see that when using standalone Guvnor this wouldn't be a problem, as
the user would be able to see that the rule has a red cross next to it
meaning something is wrong with that rule.
Has anyone else had experience doing this? Is there a way to get the UUID of
the specific rule that is causing the package not to compile?
I've had thoughts about putting each rule in it's own package, and then
creating a layer in my code to hide this from the user. But that seems like
a hack.. and I suspect it would drastically effect the performance..
As always, thanks any help/advice anyone can give.
--
View this message in context: http://drools.46999.n3.nabble.com/Guvnor-Rule-Validation-tp4024218.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 11 months
Monitoring sensor parameter change
by Bartek
Hello,
I am using Drools with Guvnor and Drools Fusion. I have application
that read data from sensors and after each read insert event to
StatefulKnowledgeSession. I have some basic rules that works.
Now I need to detect when one of sensor parameter change by some value
between reads from given sensor, e. g.
Lets say I want to detect when power rise by more then 2:
4 sensor reads (4 events inserted to session)
1. power=0.9
2. power=1
3. power =4 --> rule should detect that fact (4-1=3 ; 3>2)
4. power = 2
I do not now how to get access to previous reads in rule to do
subtraction (4-1=3). Any advice appreciated.
Thanks,
Bartek
12 years, 11 months
Memory Leak while working with Drools 5.5.1 Final
by ganapathya
Hi,
I'm using Drools 5.5.1 Final and am facing Memory Leak Issues with
org.drools.reteoo.ReteooRuleBase not getting released.
We maintain Rules Sheets as Excel Decision tables and these are maintained
as BLOBs in the DB. When the application is starting up, these BLOBs are
read from the DB and compiled into RuleBase and are maintained in memory. We
execute the rules by reading the compiled drools rule base from memory.
The memory does not seem to be getting released and we get an outofmemory
exception once every week and we're having to restart the app. When we took
a memory dump and analyzed the dump we see that most of the memory is
occupied by the org.drools.reteoo.ReteooRuleBase class.
Has anyone else experienced this before? Any insight as to how we can solve
this?
P.S: The component using Drools is a stand alone component and runs on OSGi.
Spring Injection is used but not for Drools. JDK used is JROCKIT 1.6. 0_31.
Thanks,
Ganapathy
--
View this message in context: http://drools.46999.n3.nabble.com/Memory-Leak-while-working-with-Drools-5...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 11 months