Drools Flow - Dependency Injection
by jawa
Hi,
I am writing a custom workItem handler in drools flow and want to access my
Stateless session bean from there. I will deploy my drools project to JBoss
so can I use @EJB annotation to get my stateless bean injected by jboss with
in WorkItemHandler?
Secondly I'll call my flow from with in a Stateless session bean. Is it ok?
Or does drools use multi threading? As multi threading is not recommended to
be used in EJBs?
Thanks
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Drools-Flow-Dependenc...
Sent from the Drools - User mailing list archive at Nabble.com.
15 years, 4 months
Is nested loops possible ?
by Dinesh kumar
Hi,
I am having a problem in iterating a list inside a list.
I am having the following business scenario.
Public Class CustomerOrder {
private String customerName;
private ArrayList<Order> orderList;
}
Public Class Order {
private String orderId;
private String orderTime;
private ArrayList<OrderItem> orderList;
}
Public Class OrderItem {
private String itemName;
private Double itemAmount;
}
I need to find the total order amount for each order and the sum of all
order.
My rule is like individual orders should not exceed a 10000 and total order
amount of all customers should not exceed 100000.
For this, I need to iterate ArrayList<Order> orderList and during each
iteration , I need to iterate ArrayList<OrderItem> orderList. Is this
possible in Drools ?
I tried something like this. But it doesn't seem to be working.
when
ClaimRegistration($orderList: orderList)
Number( $count : intValue > 0)
from accumulate(Order(orderId== "order1"
&&
Number( doubleValue > 10000 )
from accumulate( OrderItem( $value : itemAmount),
init( double total = 0; ),
action( total += $value; ),
reverse( total -= $value; ),
result( total ) )
) from $orderList,count(1))
then
Sysout(",,,,,");
It would be of great help if any one can give suggestions to solve this.
Is nested loops possible in Drools ?
Regards,
Dinesh
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Is-nested-loops-possi...
Sent from the Drools - User mailing list archive at Nabble.com.
15 years, 4 months
Math calculations on attributes in WHEN section of rules.
by tom ska
Hello,
what I want to do, is to calculate on object's attributes in WHEN section of
rule. Can I do it?
For example:
class CObj
{
private int k;
private int n;
// setters and getters
}
Now what I want to do is:
rule "r1"
when
p : CObj ( k + n <= 1000)
then
System.out.println("We love Drools :)");
end
Why can't I construct conditions like in Java, or C++ (with calculations in
conditions)? How can I achieve my goal?
Thx,
Tom.
15 years, 4 months
Another solution for: Detecting more than 3 occurrences within 1 hour
by Tina Vießmann
Hi,
I'm working on thinking in Drools rules. Right now I'm trying to solve this:
The rule shall fire if _a special event occurs more than 3 times
within 1 hour_.
My _first thought of a solution_ was to count the count the detected
events using a counter. But the counter has to be a global variable,
hasn't it? And global variables are not to be used to frequently, aren't
they?
And global variables must always be initialized from outside the rules
file, don't they?
Because of these thoughts I've looked for a _different solution without
global variables_. I came up with:
function boolean valueExceededLimit(Set<Alarms> alarmSet) {
//....
}
rule "more than 3 occurs within 1 hour"
when
// event #1
$eventA : Value(
eval(parameterValueExceededLimit($eventA.getAlarms())) )
// event #2
$eventB : Value( this after[0ms,1h] $eventA &&
this != $eventA &&
eval(valueExceededLimit($eventB.getAlarms())) )
// event #3
$eventC : Value( this after[0ms,1h] $eventA &&
this != $eventA &&
this != $eventB &&
eval(valueExceededLimit($eventC.getAlarms())) )
// event #4 -> 4 > 3
$eventD : Value( this after[0ms,1h] $eventA &&
this != $eventA &&
this != $eventB &&
this != $eventC &&
eval(valueExceededLimit($eventD.getAlarms())) )
then
// ... do something ...
end
More than 3 is kind of a doable task. But I think of this solution as
heavy in case its needed to detect a larger number of events. I would be
thankful for other approaches to the problem.
Thanks :)
Tina
15 years, 4 months
NullPointerException on jpaSingleSessionCommandService
by drooRam
I have configured the applicationContext.xml as follows for stateful JPA
persistance session - jpaSingleSessionCommandService :
<drools:ksession id="jpaSingleSessionCommandService" type="stateful"
kbase="flowKnowledge">
<drools:configuration>
<drools:jpa-persistence>
<drools:transaction-manager ref="transactionManager" />
<drools:entity-manager-factory ref="entityManagerFactory" />
<drools:variable-persisters>
<drools:persister for-class="javax.persistence.Entity"
implementation="org.drools.persistence.processinstance.persisters.JPAVariablePersister"/>
<drools:persister for-class="java.io.Serializable"
implementation="org.drools.persistence.processinstance.persisters.SerializableVariablePersister"/>
</drools:variable-persisters>
</drools:jpa-persistence>
</drools:configuration>
</drools:ksession>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="persistenceUnitName" value="rascalflow-persistence" />
<property name="persistenceProvider">
<bean class="org.hibernate.ejb.HibernatePersistence" />
</property>
<property name="jpaVendorAdapter">
<bean id="jpaVendorAdapter"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="database" value="ORACLE" />
<property name="showSql" value="true" />
</bean>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
p:dataSource-ref="dataSource">
<property name="hibernateProperties">
<value>
hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver
hibernate.hbm2ddl.auto=update
hibernate.show_sql=true
hibernate.max_fetch_depth=3
hibernate.format_sql=true
hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
</value>
</property>
</bean>
<bean id="sharedEntityManagerBean"
class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager"
p:sessionFactory-ref="sessionFactory" />
When i tried to start the application, i have got Null pointer exception
from drools ...Error creating bean with name
'jpaSingleSessionCommandService': ... i know this is something to do with
the parameter transaction manager in drools configuration tag... but i have
no clue why this error is occuring or any soln....
It might be the configuration that i have done was incorrect, someone please
go through the above configuration and let me know where exactly that I am
doing the mistake....
Basic runtime exception is :
Caused by: java.lang.RuntimeException: Could not commit session
at
org.drools.persistence.session.SingleSessionCommandService.<init>(SingleSessionCommandService.java:135)
... 52 more
Caused by: java.lang.NullPointerException
at
org.drools.persistence.session.SingleSessionCommandService.<init>(SingleSessionCommandService.java:124)
... 52 more
Aug 5, 2010 3:26:44 PM org.apache.catalina.core.StandardContext
loadOnStartup
SEVERE: Servlet /rascalFlow threw load() exception
java.lang.NullPointerException
at
org.drools.persistence.session.SingleSessionCommandService.<init>(SingleSessionCommandService.java:124)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at
org.drools.persistence.jpa.impl.KnowledgeStoreServiceImpl.buildCommanService(KnowledgeStoreServiceImpl.java:119)
at
org.drools.persistence.jpa.impl.KnowledgeStoreServiceImpl.newStatefulKnowledgeSession(KnowledgeStoreServiceImpl.java:57)
at
org.drools.persistence.jpa.JPAKnowledgeService.newStatefulKnowledgeSession(JPAKnowledgeService.java:93)
at
org.drools.container.spring.beans.StatefulKnowledgeSessionBeanFactory.internalAfterPropertiesSet(StatefulKnowledgeSessionBeanFactory.java:71)
at
org.drools.container.spring.beans.AbstractKnowledgeSessionBeanFactory.afterPropertiesSet(AbstractKnowledgeSessionBeanFactory.java:93)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1469)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1409)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:557)
at
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442)
at
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458)
at
org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339)
at
org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306)
at
org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at
org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993)
at
org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4187)
at
org.apache.catalina.core.StandardContext.start(StandardContext.java:4496)
at
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546)
at
org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:637)
at
org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:563)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:498)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277)
at
org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321)
at
org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:519)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/NullPointerException-...
Sent from the Drools - User mailing list archive at Nabble.com.
15 years, 4 months
A Set of Rules but no match
by Wolfgang Laun
I'm using code such as
KnowledgeRuntime knowledgeRuntime;
for( KnowledgePackage knowledgePackage:
knowledgeRuntime.getKnowledgeBase().getKnowledgePackages() ){
for( Rule rule: knowledgePackage.getRules() ){
}
}
to obtain rules, intending to construct a Set<Rule>. This, however, breaks
since repeated executions of
knowledgePackage.getRules() appear to return different objects and - this is
the evil thing -
org.drools.definitions.rule.impl.RuleImpl does not implement hashCode() and
equals(); hence
Set<Rules>( rule ).contains( rule ) fails for actually identical rules. I
consider this a bug in Drools (5.1).
org.drools.definitions.rule.impl.RuleImpl could easily retain a reference to
the org.drools.rule.Rule object from which it is built and delegate
hashCode/equals to that.
-W
15 years, 4 months
Is Drools rule engine thread safe
by james corrigan
Hi All,
I am trying to implement a mutli-threaded application using Drools Guvnor,
my question is whether or not i can share a reference of say a
StatefulKnowledgeSession or Knowledge between multiple threads? Any help is
much appreciated.
Kind regards,
James.
15 years, 4 months
drools 5.1 overview
by miguel machado
Hi all,
I just recently noticed that drools 5.1 is out and i'd like to congratulate
the jboss team for this great milestone achievement. I've also noticed that
there is separate documentation for this version on
http://jboss.org/drools/documentation.html but i haven't been able to find
the major updates on the project, since 5.0.0.
I presume the *changelog* so far is huge, so what I was looking is some kind
of blog post or release announcement so i can update a few reports i've been
writing on drools features, modules, architecture, API, requirements,
integration mechanisms, etc.
Any help is very much appreciated.
Thanks in advance,
_ miguel
--
"To understand what is recursion you must first understand recursion"
15 years, 4 months