For loop inside a modify block problem
by Martin A
Hello, guys,
I have the following snippet of a right side rule:
modify ($gsc) {
doSomething($item.id);
for (int i = 0; i < $item.quantity; i++) {
doSomethingElse($item.id);
}
}
which looks like is invalid syntax in some way, but it comes out with
strange error report, such as '[Error: no such identifier: $item]'
Would you please assist me on how to put that loop inside that modify block?
Thank you and regards,
Martin
14 years, 4 months
How to add Packages to RuleBase
by srinivasasanda
Hi
I wrote code for creating RuleBase. But I got error at retrieving URL
resource by passing ruleFile to the getResource() method.It is returning
null. How to get the URL resource. I posted the sample code which i have
written for creating RuleBase.
public RuleBase createRuleBase() throws Exception
{
if(rules==null)
{
throw new Exception("No rules provided for Engine");
}
ruleBase = RuleBaseFactory.newRuleBase();
PackageBuilder builder = new PackageBuilder();
for(String ruleFile : rules)
{
System.out.println("Rule is "+ruleFile); //prints
the ruleFile
URL resource = this.getClass().getResource(ruleFile); //gets the URL
resource of the ruleFile
if(resource==null)
{
System.err.println("Could not find resource: "+ruleFile);
continue;
}
File file = new File(this.getClass().getResource(ruleFile).getPath());
if(!file.exists())
{
System.err.println("Could not find rule file: "+file.getPath());
continue;
}
builder.addPackageFromDrl(new FileReader(file.getPath()));
}
org.drools.rule.Package pkg = builder.getPackage();
ruleBase.addPackage(pkg);
return ruleBase;
}
My Packages are not adding to RuleBase.It is returning null.
How to add the packages to ruleBase.Please suggest me
Thanks
--
View this message in context: http://drools.46999.n3.nabble.com/How-to-add-Packages-to-RuleBase-tp36534...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 4 months
Re: [rules-users] Problem with “after” operator
by Davide Sottara
Quoting the Drools fusion manual:
"The after evaluator correlates two events and matches when the temporal
distance from the current event to the event being correlated belongs to the
distance range declared for the operator.
The temporal distance interval for the after operator is optional:
If two values are defined (like in the example below), the interval starts
on the first value and finishes on the second.
If only one value is defined, the interval starts on the value and finishes
on the positive infinity.
*If no value is defined, it is assumed that the initial value is 1ms and the
final value is the positive infinity."*
try changing after --> after[0ms] and see if this solves your problem.
--
View this message in context: http://drools.46999.n3.nabble.com/Problem-with-after-operator-tp3620746p3...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 4 months
Fresh Guvnor Install throws ClassNotFoundException
by Mike Key
Hi all,
I have installed Guvnor 5.3.0-Final on a fresh Tomcat 7.0.12. I am able to
import existing rules I have, however when I try to upload my fact model I
get an error in the localhost log file:
SEVERE: Servlet.service() for servlet [AssetFileServlet] in context with
path [/guvnor-5.3.0.Final-tomcat-6.0] threw exception [Servlet execution
threw an exception] with root cause
java.lang.ClassNotFoundException: org.osgi.framework.BundleActivator
>...at
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
>...at
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
>...at java.lang.Class.forName0(Native Method)
>...at java.lang.Class.forName(Class.java:247)
>...at
org.drools.rule.MapBackedClassLoader.loadClass(MapBackedClassLoader.java:109)
>...at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
>...at java.lang.ClassLoader.defineClass1(Native Method)
>...at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
>...at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
>...at
org.drools.rule.MapBackedClassLoader.fastFindClass(MapBackedClassLoader.java:86)
>...at
org.drools.rule.MapBackedClassLoader.loadClass(MapBackedClassLoader.java:104)
>...at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
>...at
org.drools.guvnor.server.contenthandler.ModelContentHandler.isClassVisible(ModelContentHandler.java:183)
>...at
org.drools.guvnor.server.contenthandler.ModelContentHandler.getImportsFromJar(ModelContentHandler.java:148)
>...at
org.drools.guvnor.server.contenthandler.ModelContentHandler.onAttachmentAdded(ModelContentHandler.java:66)
>...at
org.drools.guvnor.server.files.FileManagerUtils.attachFileToAsset(FileManagerUtils.java:115)
>...at
org.drools.guvnor.server.files.FileManagerUtils.attachFile(FileManagerUtils.java:87)
>...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.jboss.seam.util.Reflections.invoke(Reflections.java:22)
>...at
org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
>...at
org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
>...at
org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
>...at
org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
>...at
org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)
>...at
org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
>...at
org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
>...at
org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
>...at
org.jboss.seam.security.SecurityInterceptor.aroundInvoke(SecurityInterceptor.java:163)
>...at
org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
>...at
org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
>...at
org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
>...at
org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
I am attempting to upload a jar with all dependencies it uses (which
includes JPA annotations and JAXB annotations). I have verified that the
jar contains all its proper dependencies. This message seems to indicate I
am missing some OSGi jar or something that I would have expected to be
delivered with Guvnor. Do I need some sort of global libraries for OSGi to
run Guvnor or to use my model when it has these external dependencies in
the jar?
Any help on this is greatly appreciated.
Cheers.
Mike Key
14 years, 4 months
Unable to apply ChangeSet to DRL file
by srinivasasanda
Hi,
I've a DRL file and Java Class, and ChangeSet.xml present in local drive D:
DRL file is rulemaster.drl having rule A,rule B.
My ChangeSet.xml is <change-set
xmlns='http://drools.org/drools-5.0/change-set'
xmlns:xs='http://www.w3.org/2001/XMLSchema-instance'
xs:schemaLocation='http://drools.org/drools-5.0/change-set
http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-api/src/...'
>
<add>
<resource source='file:D:\rulemaster.drl' type='DRL' />
</add>
</change-set>
Now My Java class is
package com.sample;
public class RuleEngine
{
private RuleEngine()
{
}
public static final void main(String[] args)
{
int counter=0;
try
{
System.out.println("Before rule engine start ");
RuleEngine.start();
System.out.println("After rule engine start ");
do{
Collection<KnowledgePackage> kpackages =
_kbase.getKnowledgePackages();
System.out.println("no of packages"+kpackages.size());
for(KnowledgePackage kpackage : kpackages)
{
for(org.drools.definition.rule.Rule rule1
:kpackage.getRules())
{
String packname= rule1.getPackageName();
String rulename=rule1.getName();
System.out.println("This is : "+packname+" Packages and
RuleName is " +rulename);
}
}
counter++;
try{
Thread.sleep(10000);
}catch (InterruptedException e){
System.out.println("Sleep exception occured");
}
}while(counter < 10000);
}catch (Throwable t){
t.printStackTrace();
}
}
public static synchronized RuleEngine start()
{
try{
if ( _instance == null)
{
_instance = new RuleEngine();
//create knowledgeBuilder
String url="file:D:\\ChangeSet.xml";
_kagent = KnowledgeAgentFactory.newKnowledgeAgent( "MyAgent" );
System.out.println("after creating kagent");
_kagent.applyChangeSet(ResourceFactory.newUrlResource(url));
System.out.println("after apply change set");
//Create Knowledge Base
_kbase = _kagent.getKnowledgeBase();
ResourceChangeScannerConfiguration sconf=
ResourceFactory.getResourceChangeScannerService().newResourceChangeScannerConfiguration();
sconf.setProperty("drools.resource.scanner.interval", "5");
ResourceFactory.getResourceChangeScannerService().configure(sconf);
ResourceFactory.getResourceChangeNotifierService().start();
ResourceFactory.getResourceChangeScannerService().start();
System.out.println("After starting Notification service");
}
}catch(Exception e)
{
System.out.println(e.getMessage());
}
return _instance;
}
private static KnowledgeAgent _kagent;
private static RuleEngine _instance;
private static KnowledgeBase _kbase=null;
private static StatelessKnowledgeSession _ksession=null;
}
Now as I'm making changes to DRL file by adding Rule C,Rule D..I've written
applyChangeSet method in Java class.But it is not displaying new
RuleNames.Please suggest me what is the way to applyChangeSet to DRL
file.Does anythng went wrong in above code..
Please suggest me
THanks
--
View this message in context: http://drools.46999.n3.nabble.com/Unable-to-apply-ChangeSet-to-DRL-file-t...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 4 months
CPU Spike creating a StatefulKnowledgeSession using OSGi
by David Conde
Good Morning,
I now have drools running on the Spring DM-Server but I am seeing a CPU
spike when creating a StatefulKnowledgeSession. I've tested this outside of
an OSGi environment and I don't see the spike. Does anyone know any settings
that I can change that might make this go away?
Thanks,
Dave
--
David Conde
CTO Calom Technologies
14 years, 4 months
No Such Field Error:DESCR in implementing ChangeSet
by srinivasasanda
Hi,
I'm trying to implement CHANGESET.xml functinlaity through some example.Here
is my code
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
//kbuilder.add(ResourceFactory.newUrlResource("file:d:\\rulestest\\changeset.xml"),
ResourceType.CHANGE_SET);
kbuilder.add(ResourceFactory.newUrlResource(
"file:d:\\rulestest\\changeset.xml"), ResourceType.CHANGE_SET
);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (KnowledgeBuilderError error: errors) {
System.
err.println(error);
But It is generating exception as
java.lang.NoSuchFieldError: DESCR
at
org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:539)
at
org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:28)
at com.sample.DroolsTest.readKnowledgeBase(DroolsTest.java:42)
at com.sample.DroolsTest.main(DroolsTest.java:24)
Im using guvnor 5.2..Could you please suggest me
Thanks
--
View this message in context: http://drools.46999.n3.nabble.com/No-Such-Field-Error-DESCR-in-implementi...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 4 months