Cron Rule doesn't work
by Andy
*Issue 1*
Steps:
1. Add a Rule with cron + when condition always true.
2. FireAllRules
Expected: Cron to fire every 15 seconds
Rule:
"
rule "Rule 123" dialect "mvel"
timer (cron:0/15 * * * * ?)
when
eval(true)
then
System.out.println("Fired!");
end
"
Other Details:
"
...(initialized kagent using changeset)
kbase = kagent.getKnowledgeBase();
ksession = kbase.newStatefulKnowledgeSession();
ksession.fireAllRules();
"
The same rule works fine when I insert some object.
*Issue 2*
Inserting some object and then adding a second cron makes the previous cron
fire twice, then thrice and so on...
Is statefulknowledge session right choice for me?
Are there any known issues with cron rules?
Any help/advice is appreciated. Thx!
--
View this message in context: http://drools.46999.n3.nabble.com/Cron-Rule-doesn-t-work-tp4024399.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 7 months
property change listeners aren't working as described in the Expert Doc
by abasile
Hello,
The property change listener advise from the expert doc isn't working for
me.
http://docs.jboss.org/drools/release/5.5.0.Final/drools-expert-docs/html/...
(4.8.3.5)
- I've tried setting the configuration
KnowledgeBuilderConfiguration config =
KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
config.setOption(PropertySpecificOption.ALWAYS);
KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder(config);
- Tried added annotations to Java Class
@PropertyReactive, @Modifies
- Tried adding @watch to rule
FYI: We're using salience but not Agency Groups; also StatelessSession but
tried StatefulSesson as well.
Any suggestions? Reference to a working code sample would be great.
----------------------------------------------------------------------------
(snippet for creating knowledge base)
// Set Property Specific Evaluation
KnowledgeBuilderConfiguration config =
KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
config.setOption(PropertySpecificOption.ALWAYS);
//final KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder(config);
addRulesToKBuilder(ruleFiles, logger, kbuilder);
// get the compiled packages (which are serializable)
final Collection<KnowledgePackage> pkgs =
kbuilder.getKnowledgePackages();
// add the packages to a knowledgebase (deploy the knowledge
packages).
kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( pkgs );
(snippet for adding rules to KBuilder)
for (String ruleFile : ruleFiles) {
// this will parse and compile in one step
kbuilder.add( ResourceFactory.newClassPathResource(ruleFile),
ResourceType.DRL );
if ( kbuilder.hasErrors() ) {
logger.error( kbuilder.getErrors().toString() );
throw new RuntimeException( "ERROR: Unable to compile " +
ruleFile );
}
}
(snippet for creating a stateless session)
public StatelessKnowledgeSession createStatelessSession(boolean isDebug) {
StatelessKnowledgeSession ksession =
kbase.newStatelessKnowledgeSession();
if (isDebug) {
ksession.addEventListener(new DebugWorkingMemoryEventListener());
ksession.addEventListener(new DebugAgendaEventListener());
ksession.addEventListener(new DebugProcessEventListener());
}
return ksession;
}
(snippet for rule)
dialect "java"
salience 1350
rule "Initial Normalization: Bid Size - Remove Unwanted Characters"
when
$md : MarketDataRow (
candidate,
hasValue( bidSize ),
bidSize not matches "123"//,
)
then
System.out.println( String.format( "%s; Row %d: '%s';",
drools.getRule().getName(), $md.getRowNumber(), $md.getBidSize() ) );
modify( $md ) {
setBidSize( "678m" );
}
end
Thank you in advance,
Alex
--
View this message in context: http://drools.46999.n3.nabble.com/property-change-listeners-aren-t-workin...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 7 months
Updating object model dynamically
by ashish6276
Hi
I have a requirement where we have xsds as our object model. We use jaxb
to get java object model and create a jar. That jar we upload in guvnor. Now
We have a major change in xsd. where some of previous elements are renamed
and some of previous elements are removed and some new element are added. So
now is there any way to dynamically update all the objects. Like
refractoring. So that there should not be any rework in writing all rules
again.
--
View this message in context: http://drools.46999.n3.nabble.com/Updating-object-model-dynamically-tp402...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 7 months
Identity Mode?
by rjr201
If I have a rule such as:
When
Person()
Person()
Then
System.out.println("There are two people!")
End
I only want this to fire if there are two (or more) Person objects inserted
into the session, however as default drools will fire even when there is
just one Person object inserted (i.e. both Person patterns get matched to
the same fact).
I seem to remember there is a flag I can set that swaps between these two
types of behavior, and seem to remember it's to do with Identity/Equality
mode. However, I can't remember how or where to do this.
Any help on this would be greatly appreciated..
Cheers,
Rich.
P.S I realise that I could add constraints to the patterns to explicitly
check that the facts aren't the same.. however I'd rather not have to do
that as I'm trying to make it as simple as possible for users to create
rules..
--
View this message in context: http://drools.46999.n3.nabble.com/Identity-Mode-tp4024428.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 7 months
Available rule stores
by Florian Pirchner
Hi,
i know that guvnor can be attached to drools core by KnowledgeAgent.
Is there a way to attach a git repository too? Could see in standalone
jbpm designer that rules and bpms have been loaded by git.
Thanks, Florian
11 years, 7 months
Moving rules from DB to a rules engine
by mohan.radhakrishnan@polarisft.com
Hi,
This is my first post. We have a facility in our Java web
application to upload SQL queries to the Oracle DB. These queries are not
controlled or audited. There are queries the are several pages long. Some
of these queries are configured to fire one after the other to approve our
workflow. When our workflow fires these query rules create an enormous load
on the system.
My concern at this time is that we are using the DB as a primitive and
uncontrolled rules engine. I am interested in using a proper rules engine.
What should my approach be ? Can I look at case studies or just Drools
documentation ?
Thanks.
This e-Mail may contain proprietary and confidential information and is sent for the intended recipient(s) only. If by an addressing or transmission error this mail has been misdirected to you, you are requested to delete this mail immediately. You are also hereby notified that any use, any form of reproduction, dissemination, copying, disclosure, modification, distribution and/or publication of this e-mail message, contents or its attachment other than by its intended recipient/s is strictly prohibited.
Visit us at http://www.polarisFT.com
11 years, 7 months
Possible issue regarding 'accumulate' and 'collect' conditions
by Álvaro Pantoja
Hello
I switched recently from Drools 5.5.0 to Drools 6.0.0.Beta3 and some of
my rule tests failed because Drools started doing weird things.
I've isolated the problem and I figured out that it has to do with the
combination of "accumulate" and "collect" conditions in the same rule.
See this example here:
> import java.util.ArrayList
>
> declare Item
> code: int
> price: int
> present: boolean
> end
>
> rule "Init"
> when
> then
> insert(new Item(1,40,false));
> insert(new Item(2,40,false));
> insert(new Item(3,40,false));
> insert(new Item(4,40,false));
> end
>
> rule "CollectAndAccumulateRule"
> when
> //At least two items that aren't presents
> objList: ArrayList(size>=2) from collect( Item(present==false))
> //Total price bigger than 100
> price: Number(intValue>=100) from accumulate( Item($w:price,
> present==false), sum($w))
> then
>
> System.out.println("Sum: "+price);
> System.out.println("Items size: "+objList.size());
>
> //Look for the minor price item
> Item min = null;
> for(Object obj: objList){
> if (min!=null){
> min = (min.getPrice()>((Item)obj).getPrice())?(Item)obj:min;
> }
> else {
> min = (Item)obj;
> }
> }
>
> //And make it a present
> if (min!=null){
> modify(min){setPresent(true)};
> }
> end
It gets a list of items, and when exist at least two of them and the sum
of its prices is bigger than 100, it makes a present of the cheapest
one. For this, items have a "present" flag that gets activated when it
becomes a present. Also, this flag is part of both "collect" and
"accumulate" conditions, for the rule not to loop over already
"presented" items.
So, having 4 items with price 40 each (rule "Init" insert them),
expected result is to have 2 presents of price 40. Rule
"CollectAndAccumulateRule" gets executed two times and loop stops when
there are just two remaining items, with sum 80 (<100). Expected output
would be:
Sum: 160.0
Items size: 4
Sum: 120.0
Items size: 3
This works fine in Drools 5.5.0, but not in 6.0.0.Beta3. In the latter
rule "CollectAndAccumulateRule" gets called 3 times, and output is like
this:
Sum: 160.0
Items size: 4
Sum: 120.0
Items size: 4
Sum: 120.0
Items size: 3
Is there some overall change in 6.0.0.Beta3 that affects this kind of
rules or conditions? Or could this be an issue?
Furthermore, including this kind of rules in a package along with other
no-conflictive rules, it makes the hole package start behaving
unexpectedly. I guess it has to do with the way of the Rete tree is
bulided when this kind of rules are present.
Note: I know there are alternatives and workwarounds to the scenario
shown here (like merging both conditions into a single "accumulate").
Nevertheless the aim of this post is just to try to determinate wheter
this must be considered an issue or not
Regards,
--
Alvaro
11 years, 7 months
How to display Knowledge base / DRL
by dfreeman@gio.com.au
Hi, I'm fairly new to Drools and am loading an Excel spreadsheet decision
table into a Knowledge base. This works but I have problems when I fire the
rules. Under the older Rulebase model it seemed fairly simple to display the
generated DRL. I am having problems with my current task and feel it would
be helpful if I could see the generated rules. I'm assuming this is the best
approach. Any help would be appreciated.
--
View this message in context: http://drools.46999.n3.nabble.com/How-to-display-Knowledge-base-DRL-tp402...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 7 months
MultiValueRestriction
by droolster
Hello,
I saw the following in the "Design Patterns for PRS system" pdf and could
not understand the difference between the two statements (they look the same
to me). Please can the community clarify what the difference is:
A multiple choice could be written using the same syntactic form, e.g.,
Type( strField == "Huey" || == "Dewey" || == "Louie" )
but if you are testing for equality, the MultiValueRestriction is to be
preferred, so that the preceding
pattern is better written as
Type( strField in ( "Huey", "Dewey", "Louie" ) )
Thank you,
Iftikhar
--
View this message in context: http://drools.46999.n3.nabble.com/MultiValueRestriction-tp4024384.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 7 months
Is "modify" available from the Java API?
by Thomas Grayson
In the RHS of a rule one can use either an "update" or "modify" block to notify Drools that a fact has changed. In the Java API for 5.5.0 Final, I can call StatefulKnowledgeSession.update(factHandle, object) to update a fact handle with an object. However, there's no complementary StatefulKnowledgeSession.modify method. Is there a way to get modify's property-reactive functionality through the API? That is, can Java code update fact objects and then inform Drools that only certain properties have been changed? This capability would allow just the rules that reference those properties to be reevaluated, unlike update, which causes all the rules that reference the Java class to be reevaluated.
There is a CommandFactory.newModify method, but the JavaDoc<http://docs.jboss.org/drools/release/5.5.0.Final/knowledge-api-javadoc/or...> has no explanatory text. I explored the source to understand how this is used, and it appears that it is meant to be passed a list of Setter objects that contain literal bean property names and string values which are then dynamically interpreted by MVEL. It might be possible to use this in a pinch, but it seems a rather roundabout way to update an object that the code can access directly.
Thanks,
Tom
11 years, 7 months