Re: [rules-users] Strategy for initializing objects
by Greg Barton
You answer your own question. Use accumulate:
rule "Hello World"
when
b : Box( x == -1 )
newX : Integer() from accumulate( box: Box( x != -1 ),
init( int i = 0; ),
action( i += box.size; ),
reverse( i -= box.size; ),
result( i ) )
then
System.out.println("Sum: " + newX);
b.setX(newX);
System.out.println(b);
update(b);
end
See attached project.
--- On Sat, 8/8/09, sonia <robotnic+drools(a)gmail.com> wrote:
> From: sonia <robotnic+drools(a)gmail.com>
> Subject: Re: [rules-users] Strategy for initializing objects
> To: "Rules Users List" <rules-users(a)lists.jboss.org>
> Date: Saturday, August 8, 2009, 2:36 AM
> In general: I want to set a property
> in the Box objects, depending on
> all previously set objects..
>
> My goal is to place the boxes one after another, for this I
> keep a
> variable in Box object.
> It seems like the easiest way to accumulate the sizes of
> boxes that
> are already placed.
>
> In the 'then' clause, I set the box location, and update
> the X by
> adding the size of the currently placed box.
>
> 2009/8/8 Wolfgang Laun <wolfgang.laun(a)gmail.com>:
> > Your goal and the presented code aren't clear to me.
> The consequence (after
> > then) contains calls to static/class methods
> (Box.setX()) which isn't going
> > to change anything in your fact object. The call
> b.setX() might change your
> > object, but this depends on what the class method
> Box.getX() returns.
> >
> > Assuming Drools 5, a typical consequence would look
> like
> > b: Box(...)
> > then
> > modify( b ){
> > setX( ... )
> > }
> > end
> >
> > -W
> >
> > On Sat, Aug 8, 2009 at 1:48 AM, sonia <robotnic+drools(a)gmail.com>
> wrote:
> >>
> >> Hello
> >>
> >> I want to achieve this:
> >> box1.setX(0)
> >> box2.setX(box1.size());
> >> box2.setX(box1.size + box2.size)
> >> ...
> >>
> >> I want to do it with rules, and would like to know
> what's the best
> >> method of initializing (or any other operation
> with varying data) a
> >> group of objects
> >>
> >> rule "init box"
> >> when
> >> b : Box( x == -1)
> >> then
> >> b.setX(Box.getX());
> >> Box.setX( Box.getX() + b.size);
> >> end
> >>
> >> This does not work.
> >> A single box object is matched several times
> instead of different box
> >> objects.
> >> What is happening? how come a single box object is
> matched several
> >> times? Why doesnt drools choose other instances of
> box?
> >>
> >> What do I need to do to initialize all boxes, once
> for every box?
> >>
> >> Thank you.
> >>
> >> --
> >> robosonia
> >> _______________________________________________
> >> rules-users mailing list
> >> rules-users(a)lists.jboss.org
> >> https://lists.jboss.org/mailman/listinfo/rules-users
> >
> >
> > _______________________________________________
> > rules-users mailing list
> > rules-users(a)lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/rules-users
> >
> >
>
>
>
> --
> robosonia
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
16 years, 10 months
Strategy for initializing objects
by sonia
Hello
I want to achieve this:
box1.setX(0)
box2.setX(box1.size());
box2.setX(box1.size + box2.size)
...
I want to do it with rules, and would like to know what's the best
method of initializing (or any other operation with varying data) a
group of objects
rule "init box"
when
b : Box( x == -1)
then
b.setX(Box.getX());
Box.setX( Box.getX() + b.size);
end
This does not work.
A single box object is matched several times instead of different box objects.
What is happening? how come a single box object is matched several
times? Why doesnt drools choose other instances of box?
What do I need to do to initialize all boxes, once for every box?
Thank you.
--
robosonia
16 years, 10 months
How can I configure who is an Admin in Guvnor?
by Steve Ronderos
Hello Drools Users,
In the Guvnor Documentation (
http://downloads.jboss.com/drools/docs/5.0.1.26597.FINAL/drools-guvnor/ht...
) it states that ". It is also possible (thanks to JAAS) to define what
users have the "admin" role for Guvnor (note that an Admin user of Guvnor
doesn't have to really be a system administrator). " I wasn't sure if
this meant that there was a way to define Admins from within the Guvnor UI
or if it was possible to configure the admin role to read from an LDAP
group or some other JAAS method.
We are going to be deploying Guvnor to a production environment in the
near future, we want to take advantage of Role Based Authorization, we
want to start with an empty DB and we don't want to have to deploy with
Authorization off, set up roles and then turn it back on.
Is this possible? Or did I misinterpret the documentation?
Thanks,
Steve Ronderos
16 years, 10 months
DRL Pattern match to subclass?
by Kris Nuttycombe
Hi, all,
I'm trying to figure out a way to perform the following pattern match
in a "when" clause in a drl file. This is with Drools 4.x
I have the following parameterized class (boilerplate omitted):
abstract class Property<T> {
public String getName() {
//...
}
public abstract T getValue();
}
and subclasses such as
class BigDecimalProperty extends Property<BigDecimal> {
public BigDecimal getValue() {
//...
}
}
I then have an interface as such:
public interface Propertied {
public Set<Property<?>> getProperties();
}
and an implementing class:
class Plan implements Propertied {
//...
}
In my rules file, I would like to be able to perform the following
pattern match:
rule "Ensure that plan minimum commitment has been met."
agenda-group "evaluate-balance"
when
$plan: Plan()
$minCommitProperty: BigDecimalProperty(name ==
"minimum_commitment", $minCommitment : value) from $plan.properties
then
//...
end
Of course, this results in a runtime rule compilation exception
complaining of type mismatch. Is there any better way to encode this
match than to add all properties to the working memory, match the
desired property as a first-class object, then match against the plan
with Plan(properties contains $minCommitProperty)?
Thanks,
Kris
16 years, 10 months
Using Enums in when clause
by Zevenbergen, Alex
Hi,
This is my where clause:
when
resultInfo : TennisResultInfo(endGame == true , setNumber ==
5,gameWinner == PARTICIPANTS.HOME.getId() , gameLoseScore == 0)
then
the rule falls over on PARTICIPANTS.HOME.getId()
PARTICIPANTS.HOME.getId() is an enum and returns an integer.
If I replace this line with the value that it would return the rule runs
perfectly.
Do I have to reference this in a certain way because it is an integer?
(Note all imports are present and correct)
Thanks,
Alex
________________________________________________________________________
Privileged, confidential and/or copyright information may be contained in this communication. This e-mail and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you are not the intended addressee, you may not copy, forward, disclose or otherwise use this e-mail or any part of it in any way whatsoever. To do so is prohibited and may be unlawful. If you have received this email in error
please notify the sender immediately.
Paddy Power PLC may monitor the content of e-mail sent and received for the purpose of ensuring compliance with its policies and procedures.
Paddy Power plc, Airton House, Airton Road, Tallaght, Dublin 24 Registered in Ireland: 16956
________________________________________________________________________
16 years, 10 months
multi-threaded deadlock?
by Charles Binford
All,
Drools 4.0.7.
I have a single rulebase and three threads running stateless sessions
(each thread has it's own session). All appears to work fine until I
try to dynamically update the packages in the rulebase. That scenario
intermittently hangs on an apparent deadlock. The documentation says,
"Packages can be added and removed at any time...", but maybe this
wasn't assuming a multi-threaded context?
The stack trace of my three threads is below.
- Thread 10 is in the middle if fireAllRules
- Thread 12 is trying to add facts to its session
- thread 11 is trying to add a new package to the ruleBase, but seems to
be in some flavor of fireAllRules on the ruleBase even though there is
no session argument in this code path.
Am I breaking some fundamental drools rule for multi-threading? Do I
need to lock out other sessions from activity while updating packages?
Thanks
Charles Binford
"Thread-10"
java.lang.Object.wait(Object.java)
java.lang.Object.wait(Object.java:485)
org.drools.util.concurrent.locks.ReentrantLock$NonfairSync.lock(ReentrantLock.java:106)
org.drools.util.concurrent.locks.ReentrantLock.lock(ReentrantLock.java:195)
org.drools.common.AbstractWorkingMemory.getFactHandleByIdentity(AbstractWorkingMemory.java:604)
org.drools.base.DefaultKnowledgeHelper.update(DefaultKnowledgeHelper.java:98)
com.sun.evtl.pe.customerPolicy.adm.rules.Rule_turn_on_batch_0.consequence(Rule_turn_on_batch_0.java:8)
com.sun.evtl.pe.customerPolicy.adm.rules.Rule_turn_on_batch_0ConsequenceInvoker.evaluate(Rule_turn_on_batch_0ConsequenceInvoker.java:22)
org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:554)
org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:518)
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:475)
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:439)
com.sun.evtl.pe.common.PolicyManager.fireRules(PolicyManager.java:353)
com.sun.evtl.pe.customerPolicy.adm.rules.ArchiveMgrThrd.fireRules(ArchiveMgrThrd.java:132)
com.sun.evtl.pe.customerPolicy.adm.rules.ArchiveMgrThrd.runEngine(ArchiveMgrThrd.java:51)
com.sun.evtl.pe.customerPolicy.adm.msg.PolicyListenerThrd.run(PolicyListenerThrd.java:57)
java.lang.Thread.run(Thread.java:619)
"Thread-11"
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:439)
org.drools.base.FireAllRulesRuleBaseUpdateListener.beforeRuleBaseUnlocked(FireAllRulesRuleBaseUpdateListener.java:29)
org.drools.event.RuleBaseEventSupport.fireBeforeRuleBaseUnlocked(RuleBaseEventSupport.java:168)
org.drools.common.AbstractRuleBase.unlock(AbstractRuleBase.java:361)
org.drools.common.AbstractRuleBase.addPackage(AbstractRuleBase.java:456)
com.sun.evtl.pe.common.PolicyManager.addPackage(PolicyManager.java:237)
com.sun.evtl.pe.customerPolicy.adm.rules.ArchiveMgr.loadNewUserRules(ArchiveMgr.java:170)
com.sun.evtl.pe.customerPolicy.adm.msg.PolicyListenerThrd.run(PolicyListenerThrd.java:78)
java.lang.Thread.run(Thread.java:619)
"Thread-12"
java.lang.Object.wait(Object.java)
java.lang.Object.wait(Object.java:485)
org.drools.util.concurrent.locks.ReentrantLock$NonfairSync.lock(ReentrantLock.java:106)
org.drools.util.concurrent.locks.ReentrantLock.lock(ReentrantLock.java:195)
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:743)
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:704)
com.sun.evtl.pe.common.PolicyManager.insertSensor(PolicyManager.java:316)
com.sun.evtl.pe.customerPolicy.adm.rules.ArchiveMgrThrd.assertFacts(ArchiveMgrThrd.java:79)
com.sun.evtl.pe.customerPolicy.adm.rules.ArchiveMgrThrd.runEngine(ArchiveMgrThrd.java:50)
com.sun.evtl.pe.customerPolicy.adm.msg.PolicyListenerThrd.run(PolicyListenerThrd.java:57)
java.lang.Thread.run(Thread.java:619)
16 years, 11 months
Re: [rules-users] Type declaration in DSL
by Matt Geis
You just need to create a mapping like..
There is a product type = productType : ProductType()
There is a customer = customer : Party()
and you can write the LHS of the rule like
when
>not PricingResult()
There is a product type
There is a customer
Matt
*********************
hi all,
I have recently started using Drools 5.0 .I have a difficulty in
writing the expressions in DSL file.i have my .dslr file written like
this
when
>not PricingResult()
>productType : ProductType()
>customer : Party()
then
create a PricingResult
set productType
set customer
now, i am able to fire the rule successfully,with the following in
.dslr file with rule language mappings set to
pricingResult.setProductType(productType);
pricingResult.setCustomer(customer);
where productType and customer are set using CommandFactory.insert(....)
but
i want to remove the below 2 lines from .dslr file and expand them in .dsl file
productType : ProductType()
customer : Party()
how do i declare these types in DSL?
16 years, 11 months
advice on fact loading through database using globals
by Rafael Ribeiro
Hi all,
I am about to start a new project here using Drools and in order to
better understand it I am reading the developer's guide book written
by Michal Bali.
During my readings, one thing caught my attention, on page 26 of the
book the author mentions:
"Use the global variable in a rule condition or a consequence. If used
in a condition, they must return a time-constant value while the rule
session is active."
And that's exactly one of the things our application will need to do
since we'll be checking events against facts stored in a database. One
interesting thing is that it turns out that the architecture we had in
mind is exactly what is described on the page 192 of the book,
services that would be registered as globals would be responsible for
accessing database and augmenting the facts on knowledge sessions when
necessary.
But... if we take the restriction mentioned on page 26 into
consideration we would have to open a new session for each event
received (and close it after). I am pretty sure this isnt much smart
not to mention that it kills any chance of using capabilities
introduced by Fusion.
Is there any other approach we could take to achieve this ?
best regards,
Rafael Ribeiro
16 years, 11 months
(no subject)
by Chandana Pingle
chandana.pingle(a)intunity.com.au
16 years, 11 months
Problems with persistence of drools-flow
by Ševčík Martin
I have a simple flow with human task and I want to persist it into database. I'm using MSSQL DB.
My code is like this:
KnowledgeBase kbase = readKnowledgeBase();
// create the entity manager factory and register it in the environment
EntityManagerFactory emf =
Persistence.createEntityManagerFactory( "org.drools.persistence.jpa" );
Environment env = KnowledgeBaseFactory.newEnvironment();
env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, emf );
BitronixTransactionManager btm = TransactionManagerServices.getTransactionManager();
env.set( EnvironmentName.TRANSACTION_MANAGER, btm);
StatefulKnowledgeSession ksession =
JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env );
KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new WSHumanTaskHandler());
// start a new process instance
Map<String,Object> data = new HashMap<String,Object>();
data.put("data3", new MyTask(1,"This is taks 1"));
ProcessInstance pi = ksession.startProcess("com.sample.ruleflow",data);
logger.close();
But when i run it, it end up with this error and there is nothing in the database (the tables were created, but there are all empty):
java.lang.NullPointerException
at org.drools.persistence.processinstance.ProcessInstanceInfo.getId(ProcessInstanceInfo.java:70)
at org.drools.persistence.processinstance.JPAProcessInstanceManager.addProcessInstance(JPAProcessInstanceManager.java:34)
at org.drools.common.AbstractWorkingMemory.startProcess(AbstractWorkingMemory.java:1620)
at org.drools.process.command.StartProcessCommand.execute(StartProcessCommand.java:46)
at org.drools.process.command.StartProcessCommand.execute(StartProcessCommand.java:10)
at org.drools.persistence.session.SingleSessionCommandService.execute(SingleSessionCommandService.java:229)
at org.drools.process.command.impl.CommandBasedStatefulKnowledgeSession.startProcess(CommandBasedStatefulKnowledgeSession.java:163)
at com.sample.RuleFlowPersistenceTest.main(RuleFlowPersistenceTest.java:74)
java.lang.RuntimeException: Could not rollback transaction
at org.drools.persistence.session.SingleSessionCommandService.execute(SingleSessionCommandService.java:258)
at org.drools.process.command.impl.CommandBasedStatefulKnowledgeSession.startProcess(CommandBasedStatefulKnowledgeSession.java:163)
at com.sample.RuleFlowPersistenceTest.main(RuleFlowPersistenceTest.java:74)
Caused by: java.lang.RuntimeException: Could not execute command
at org.drools.persistence.session.SingleSessionCommandService.execute(SingleSessionCommandService.java:255)
... 2 more
Caused by: java.lang.NullPointerException
at org.drools.persistence.processinstance.ProcessInstanceInfo.getId(ProcessInstanceInfo.java:70)
at org.drools.persistence.processinstance.JPAProcessInstanceManager.addProcessInstance(JPAProcessInstanceManager.java:34)
at org.drools.common.AbstractWorkingMemory.startProcess(AbstractWorkingMemory.java:1620)
at org.drools.process.command.StartProcessCommand.execute(StartProcessCommand.java:46)
at org.drools.process.command.StartProcessCommand.execute(StartProcessCommand.java:10)
at org.drools.persistence.session.SingleSessionCommandService.execute(SingleSessionCommandService.java:229)
... 2 more
In JPAProcessInstanceManager.java there this method is called:
public void addProcessInstance(ProcessInstance processInstance) {
ProcessInstanceInfo processInstanceInfo = new ProcessInstanceInfo( processInstance );
EntityManager em = (EntityManager) this.workingMemory.getEnvironment().get( EnvironmentName.ENTITY_MANAGER );
em.persist( processInstanceInfo );
((ProcessInstance) processInstance).setId( processInstanceInfo.getId() );
processInstanceInfo.updateLastReadDate();
internalAddProcessInstance(processInstance);
}
But em.persist does nothing, no connection do DB is called. And then the next line will fail.
Can anybody help me.
Thanks
Martin Sevcik
16 years, 11 months