Coding up an "intersects" operator
by Dirk Bergstrom
It looks like I'm going to need to implement the "intersects" operator for a
project I'm working on. As in "Does this collection share at least one element
with that collection".
Unfortunately, I'm going to need it in about two weeks. Too bad I didn't plan
ahead...
So, if anyone can send me some pointers on where in the code I should be
looking, I'd be very grateful. I don't think it will be particularly difficult
to write the actual code, but I'm worried that I'll never be able to figure out
all the places in the codebase that I have to touch.
A ways back, Edson said that I could use the work on "contains" as a model; is
there a single subversion commit that lists all the files affected by that?
Thanks.
--
Dirk Bergstrom dirk(a)juniper.net
_____________________________________________
Juniper Networks Inc., Computer Geek
Tel: 408.745.3182 Fax: 408.745.8905
16 years, 9 months
Java Generics - Using a object model that has generic signatures.
by Krishna Satya
Greetings.
I have been looking at the postings on the user group and it appears that
Java Generics is not supported in the constraint section of the rule.
In one of the postings:
http://www.nabble.com/Problem-in-using-genrics-with-drools4.0.1.-td130922...,
Mark Proctor. has indicated that this cannot be supported. I see other
postings where drools team has indicated that generics is not supported.
Given the following would be invalid:
rule "Generic Test"
request : InputRequest()
genericList : List<SomeType> ( request.getterAttributeName != null ) from
request.getterAttributeName
then
end
what are the alternatives/workaround to using a model object that has
getters that return say a collection of generic types. Our object model
uses generics pretty heavily and it would be bad alternative to replicate
these model objects without generic signatures just for the sake of Drools.
Curiosity got the better of me and I tried to modify the above rule to see
what Drools would let me get away with. I cannot have a rule that has any
Generic semantics, so I had to drop <SomeType>. I tried
Approach 1 - genericList : List ( request.getterAttributeName != null )
from request.getterAttributeName
Approach 2 - genericList : SomeType ( request.getterAttributeName != null
) from request.getterAttributeName (forced to do this to avoid run time
exception from approach 1)
Here is what I observe:
Approach 1 - I tried to see if Drools would give me a reference to a List
Type object. The rule compiled but I was getting a classcast exception
during runtime when I tried to use the reference in the consequence. Looking
at what the root cause for the class cast shows that Drools actually was
creating a reference to "SomeType" object which is the type of the object
contained in the list.
Approach 2 - I modified the rule to avoid the class cast exception from
approach 1. The rule compiled and executed. But the rule was getting fired
as many times as the number of objects in the list.
Both of the above observations are neither intuitive nor typically desired.
I understand the rule definition was exploratory.
Questions I have :
- Is the above observation a result of a bug in drools? Can the observation
be explained.
- What is the approach recommended to using an object model that has generic
signatures ?
Hoping some one will weigh in on this subject.
Thanks a lot.
- Krishna
16 years, 10 months
Java5 Enum - Reference on usage in constraints.
by Krishna Satya
Greetings.
I am trying to find the correct approach to defining and using Java5 Enum's
in Drools constraints.
*Psudo code:*
Class RuleRequest {
... other attributes ...
// RequestType is an enum type.
RequestType type ;
public RequestType getRequestType() {
return type;
}
}
public enum RequestType {
INTERNAL("internal"), EXTERNAL("external");
}
*Drools Rule:*
# 1st Constraint - I could have listed the type in the constraint for
RuleRequest but say I want that to be in a separate constraint
# 2nd Constraint - on the nested RequestType enum
*req: RuleRequest(..some match not based on the RequestType but other
attributes of RuleRequest...)
type: RequestType( ??? == RequestType.INTERNAL ) from req.requestType
*
What should be plugged in ??? to be able to match the requestType.
Interestingly, if I say
*type: RequestType( this == RequestType.INTERNAL ) from req.requestType *when
the ruleRequest has an RequestType of INTERNAL, the matching works. But I
do not see any examples/reference in the Drools documentation on the usage
of "this" in constraints. I saw a posting from Edson T. using this which is
why I tried it in the first place.
*Question
*- What is the expectation for the Enum. Should it have methods (getters)
that return the Enum type itself or methods that return the strigified value
of the Enum?
- What is syntax and usage practices for the usage of the "this" keyword
- What really happens when the Drools engine does the == comparison on
Enum's. Does it convert to the string value of the enum and then compare
that or is there something else in play.
I hope I have asked valid questions as I see many questions relating to Enum
but maybe a definitive/suggested approach and explanation from the drools
dream team may serve as a good reference on this subject.
Thanks.
- Krishna
16 years, 10 months
Duplicated classes in JBOSS\JBRMS...
by mmquelo massi
Hi there...
I post something that I just wrote in the irc channel...I hope u can help
me.
I use JBoss 4.2.2 and drools 4.0.4 (IDE and jbrms).
I deployed my rule assets into the jbrms (technical rules, business rules,
decision tables, ruleflows, object model, DSLs).
Then i deployed my J2EE application into the same JBoss.
My J2ee module is an .ear file which contains a Web-app, some EJBs, the
Drools fundamental libs and a class which invokes the RuleAgent.
The .ear file contains the object model as well.
So I have got the object model duplicated. One instance in the jbrms
and the other one in the .ear file.
For this reason I get back an "InvalidClassException" from the RuleAgent
each time I call the ruleagent itself.
So...
If I would be able to avoid deployin' the Obj Model into the brms
I would have just one instance of the Obj model... I would have
just the .ear object model.
Do u know how Could I do it?
Thank You anyway.
Bye bye.
Massi
16 years, 10 months
Invalid MagicNumber when validating package.
by Darko Ivancan
Product: JBoss DRools
Version: 4.0.3
JDK: 1.5.0_12
OS: Windows XP SP2
AS: JBoss 4.2.2GA
Hi,
Sorry haven't been on the list for a while, busy with a project, which keeps me now really busy.
We have here an exception which does not seem to make any sense and we're a bit lost in the why and where this happens.
Any help will be appreciated.
Thanks,
Darko IVANCAN
----------------------------------
Steps to reproduce:
1. Log in to jBRMS
2. Created Package as “com.xyz.abcservice.rules”
3. Imported two jars (“rulescore.jar”,” sampleDomain.jar”) into Model.
4. Created New Rule with the following content
package com.xyz.abcservice.rules;
import domain.Accommodation1;
import java.util.List;
import com.xyz.common.rules.api.GenericRuleViolation;
global java.util.List errList;
rule "Conflict Rule 1"
when
accommodation1:Accommodation1(name == "Car")
accommodation2:Accommodation1(name == "Caravan")
then
errList.add(new
GenericRuleViolation(accommodation1,"Invalid cabin combination."));
end
4. Validate it…
------------Output------------------
An error occurred executing the action.
Details
<!-- AppServer Exceptions moved below this exception for readability--!>
Caused by: java.lang.ClassFormatError: Incompatible magic value 1885430635 in class file domain/Accommodation1
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at org.drools.rule.MapBackedClassLoader.fastFindClass(MapBackedClassLoader.java:60)
at org.drools.rule.MapBackedClassLoader.loadClass(MapBackedClassLoader.java:79)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at org.drools.rule.PackageCompilationData$PackageClassLoader.loadClass(PackageCompilationData.java:358)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at org.drools.base.ClassTypeResolver.resolveType(ClassTypeResolver.java:146)
at org.drools.rule.builder.dialect.mvel.MVELDialect.addImport(MVELDialect.java:254)
at org.drools.compiler.DialectRegistry.addImport(DialectRegistry.java:98)
at org.drools.compiler.PackageBuilder.mergePackage(PackageBuilder.java:377)
at org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:264)
at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:167)
at org.drools.brms.server.contenthandler.DecisionTableXLSHandler.compile(DecisionTableXLSHandler.java:63)
at org.drools.brms.server.builder.ContentPackageAssembler.buildAsset(ContentPackageAssembler.java:139)
at org.drools.brms.server.builder.ContentPackageAssembler.<init>(ContentPackageAssembler.java:103)
at org.drools.brms.server.ServiceImplementation.buildAsset(ServiceImplementation.java:867)
... 51 more
<!-- AppServer Exceptions: --!>
java.lang.reflect.InvocationTargetException
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:585)
at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:31)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:46)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at org.jboss.seam.security.SecurityInterceptor.aroundInvoke(SecurityInterceptor.java:40)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:106)
at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:155)
at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:91)
at org.drools.brms.server.ServiceImplementation_$$_javassist_3.buildAsset(ServiceImplementation_$$_javassist_3.java)
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:585)
at org.jboss.seam.remoting.gwt.GWTToSeamAdapter.callWebRemoteMethod(GWTToSeamAdapter.java:74)
at org.jboss.seam.remoting.gwt.GWTRemoteServiceServlet.processCall(GWTRemoteServiceServlet.java:290)
at org.jboss.seam.remoting.gwt.GWTRemoteServiceServlet.doPost(GWTRemoteServiceServlet.java:172)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.seam.web.ContextFilter$1.process(ContextFilter.java:42)
at org.jboss.seam.servlet.ContextualHttpServletRequest.run(ContextualHttpServletRequest.java:46)
at org.jboss.seam.web.ContextFilter.doFilter(ContextFilter.java:37)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
at java.lang.Thread.run(Thread.java:595)
--
GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.
Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail
16 years, 10 months
Querying for a particular object from working memory
by Jai Vasanth
Hi,
Is there a way to query for an object of type X among a pool of objects of
type X in working memory that have the maximum/minimum value of a
particular attribute a1 ?
For example
if I have a class C
Class C {
int a1;
int a2;
}
As part of my rules evaluataion I have N instances of C inserted into
working memory c1,c2.....cn. Now I would like to query for the object that
the max value of attribute a1
Is this possible?
Thanks
Jai
16 years, 10 months
using a disjunction instead of a conjunction in DecisionTables
by Mescher,Mark
Hello out there,
the different conditions of a Rule in a DecisionTable are combined with an AND (so all Contitions have to be true).
Is there a way to use a logical OR instead (so only one condition of a rule have to be true)?
Thx
Mark
16 years, 10 months
Stopping Rule-Execution after first match
by Mescher,Mark
Hello,
we have realized a project using drools with Decision Tables. We are working in sequential mode.
Now we have the request for a mechanism to stop the rule execution after the first rule matches (so no more rules are executed). Is there a native way to do this with decision tables?
Thx
Mark
16 years, 10 months
OutOfMemory with BRMS 4.0.3
by sophie.ramel@tudor.lu
Hello,
I am using Drools BRMS 4.0.3 with tomcat 5.5.25, and I get OutOfMemory
exceptions in tomcat regularly.
I recently changed the java option of tomcat to add "-Xmx512m", but it
only resulted in taking a little more time before crashing (3 days,
instead of 1 before).
The server has nearly no access - it's a development server which is not a
lot used at the moment - and there are only a few rules, for tests, so I
really don't understand this error. I'm using java 1.5.0 on a linux
server.
The BRMS is accessed by web, to create and deploy the rules, and queried
from another tool (on the same machine but in another server: in JBoss),
to insert data in a workingMemory and execute the rules from the deployed
package URL. I call the dispose() method on the StatefulSession at the end
of the query (but this shouldn't be linked to this error, since this is in
JBoss and the OutOfMemory occurs in tomcat...).
Any idea?
Thanks,
Sophie
16 years, 10 months