Re: [rules-users] Question about Drools Spring, StatelessKnowledgeSession and globals
by Patrick van Kann
Hello fellow Droolers,
A while ago I asked why the <drools:batch> element seemed to work
differently in the case of a StatelessKnowledgeSession and a
StatefulKnowedgeSession (see below).
I just wanted to update those interested with the answer and ask some
further questions, probably aimed at any developers who happen to be
reading.
I checked out the 5.1.1.34858 tag and had a look at how the Spring
integration works. I found that the reason that the global is not set in the
case of a StatelessKnowledgeSession is because the <spring:batch> element is
effectively ignored in the StatelessKnowledgeSessionBeanFactory, which lacks
the following code present in the StatefulKnowledgeSessionBeanFactory (in
the internalAfterPropertiesSet() method):
if ( getBatch() != null && !getBatch().isEmpty()) {
for ( Command<?> cmd : getBatch() ) {
ksession.execute( cmd );
}
}
So, either by accident or design the <spring:batch> element has no effect
when using a StatelessKnowledgeSession (but is perfectly allowable in the
XSD/Spring namespace).
So my questions are:
1) Is this the intended behaviour or a bug? On reflection, I am now not sure
the idea of a "batch/script" makes sense for a StatelessKnowledgeSession
since execute() is a one-shot method and any globals set this way would not
be available to later executions, which is what I was looking for.
2) If so, should the XSD be changed to disallow the batch element within a
stateless session (difficult, given that this is determined via the "type"
attribute) or should the documentation simply warn people that the
<spring:batch> element doesn't do anything if you set the type attribute to
stateless (somewhat confusing, I suppose)
3) If not, should the code above be added to the
StatelessKnowledgeSessionBeanFactory.internalAfterPropertiesSet() method?
4) Should there be another way to declare a global that isn't through the
batch element (one that would cause globals to be set via the
setGlobal(String, Object) method rather than using the SetGlobalCommand via
the execute() method.
I am happy to try and contribute something along these lines if I can get
some guidance as to what was actually intended.
Hope this helps and thanks again for Drools.
Patrick
=====================================
Hello,
I've been trying out the Spring integration package in Drools 5.1.1 and it
works really well, but I have run into one issue I can't figure out.
I've defined 2 knowledge sessions from the same knowledge base in the app
context - one stateless, one stateful but otherwise identical. They both
refer to a collaborator defined as a bean in the app context which is to be
used as a global in my rules. This is just an excerpt of my full Spring
context, the kbase definition itself is not an issue.
<bean id="applicantDao" class="com.acme.app.dao.impl.ApplicantDaoImpl" />
<drools:ksession id="statelessKSession" type="stateless"
name="statelessKSession" kbase="kbase">
<drools:batch>
<drools:set-global identifier="applicantDao" ref="applicantDao" />
</drools:batch>
</drools:ksession>
<drools:ksession id="statefulKSession" type="stateful"
name="statefulKSession" kbase="kbase">
<drools:batch>
<drools:set-global identifier="applicantDao" ref="applicantDao" />
</drools:batch>
</drools:ksession>
The issue is that this configuration works for the stateful but not the
stateless session, in the sense that the stateful session appears to have a
valid reference to the applicantDao object in the Globals object but the
stateless session doesn't.
<at> Test
public void testStatelessGlobal() {
Globals globals = statelessKSession.getGlobals();
Object global = globals.get("applicantDao");
Assert.assertNotNull(global);
}
<at> Test
public void testStatefulGlobal() {
Globals globals = statefulKSession.getGlobals();
Object global = globals.get("applicantDao");
Assert.assertNotNull(global);
}
The first test fails (the global variable is null) but the second passes. No
errors are thrown by Drools during the setup of the Spring container.
What am I doing wrong? Should I be able to define globals in this way for
stateless sessions? The XSD seems to indicate this is a valid configuration,
but it just doesn't work.
Is anyone else working with the Spring integration that can point out my
error here?
Many thanks,
Patrick
11 years, 10 months
Drools as a Webservice
by abhinavgupta
Hi,
I am new to the Drools , i wanted to expose rules as a webservice using
Axis2.
what i have done is that
1. I have created a drools Project (working fine on eclispe) export all
files in jar
2. Placed the jar file in C:\Program Files\Apache Software Foundation\Tomcat
7.0\webapps\axis2\WEB-INF\lib directory
3. Created a new Dynamic java project with axis2 facet.created a class with
**
package in.abhi.ws;
import java.math.BigDecimal;
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseFactory;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderError;
import org.drools.builder.KnowledgeBuilderErrors;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.io.ResourceFactory;
import org.drools.runtime.StatefulKnowledgeSession;
import com.sample.SaleItem;
public class Test {
private static KnowledgeBase readKnowledgeBase() throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("KanasSalesTax.drl"),
ResourceType.DRL);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (KnowledgeBuilderError error : errors) {
System.err.println(error);
}
throw new IllegalArgumentException("Could not parse knowledge.");
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
return kbase;
}
public BigDecimal salesTax(String taxState, String typeItem) {
BigDecimal taxCal = null;
try {
// load up the knowledge base
KnowledgeBase kbase = readKnowledgeBase();
StatefulKnowledgeSession ksession = kbase
.newStatefulKnowledgeSession();
// Non-prescription item
// Expect $1.89 for the tax
SaleItem item1 = new SaleItem();
item1.setPurchaseState(taxState);
item1.setItemType(typeItem);
item1.setSalesPrice(new BigDecimal(29.95));
ksession.insert(item1);
ksession.fireAllRules();
taxCal = item1.getSalesTax();
System.out.println(item1.getPurchaseState().toString() + " "
+ item1.getItemType().toString() + ": "
+ item1.getSalesTax().toString());
} catch (Throwable t) {
t.printStackTrace();
}
return taxCal;
}
}
**
4. Then created a bottom up java bean webservice of it using the same above
class.
5. Wsdl is generated
i am getting the error response on eclispe console while testing by soap-ui
**********
java.lang.NullPointerException
at
org.drools.util.CompositeClassLoader.getResourceAsStream(CompositeClassLoader.java:122)
at
org.drools.commons.jci.compilers.EclipseJavaCompiler$2.findType(EclipseJavaCompiler.java:234)
at
org.drools.commons.jci.compilers.EclipseJavaCompiler$2.findType(EclipseJavaCompiler.java:215)
at
org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.createPackage(LookupEnvironment.java:748)
at
org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.buildTypeBindings(CompilationUnitScope.java:87)
at
org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.buildTypeBindings(LookupEnvironment.java:167)
at
org.eclipse.jdt.internal.compiler.Compiler.internalBeginToCompile(Compiler.java:721)
at
org.eclipse.jdt.internal.compiler.Compiler.beginToCompile(Compiler.java:381)
at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:426)
at
org.drools.commons.jci.compilers.EclipseJavaCompiler.compile(EclipseJavaCompiler.java:358)
at
org.drools.commons.jci.compilers.AbstractJavaCompiler.compile(AbstractJavaCompiler.java:49)
at
org.drools.rule.builder.dialect.java.JavaDialect.compileAll(JavaDialect.java:369)
at
org.drools.compiler.DialectCompiletimeRegistry.compileAll(DialectCompiletimeRegistry.java:53)
at org.drools.compiler.PackageRegistry.compileAll(PackageRegistry.java:71)
at org.drools.compiler.PackageBuilder.compileAll(PackageBuilder.java:869)
at org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:826)
at
org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:404)
at
org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:586)
at
org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:37)
at in.abhi.ws.Test.readKnowledgeBase(Test.java:31)
at in.abhi.ws.Test.salesTax(Test.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:212)
at
org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:117)
at
org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
at
org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:110)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:181)
at
org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:172)
at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:146)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
java.lang.NullPointerException
at
org.drools.util.CompositeClassLoader.getResourceAsStream(CompositeClassLoader.java:122)
at
org.drools.commons.jci.compilers.EclipseJavaCompiler$2.findType(EclipseJavaCompiler.java:234)
at
org.drools.commons.jci.compilers.EclipseJavaCompiler$2.findType(EclipseJavaCompiler.java:215)
at
org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.createPackage(LookupEnvironment.java:748)
at
org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.buildTypeBindings(CompilationUnitScope.java:87)
at
org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.buildTypeBindings(LookupEnvironment.java:167)
at
org.eclipse.jdt.internal.compiler.Compiler.internalBeginToCompile(Compiler.java:721)
at
org.eclipse.jdt.internal.compiler.Compiler.beginToCompile(Compiler.java:381)
at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:426)
at
org.drools.commons.jci.compilers.EclipseJavaCompiler.compile(EclipseJavaCompiler.java:358)
at
org.drools.commons.jci.compilers.AbstractJavaCompiler.compile(AbstractJavaCompiler.java:49)
at
org.drools.rule.builder.dialect.java.JavaDialect.compileAll(JavaDialect.java:369)
at
org.drools.compiler.DialectCompiletimeRegistry.compileAll(DialectCompiletimeRegistry.java:53)
at org.drools.compiler.PackageRegistry.compileAll(PackageRegistry.java:71)
at org.drools.compiler.PackageBuilder.compileAll(PackageBuilder.java:869)
at org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:826)
at
org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:404)
at
org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:586)
at
org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:37)
at in.abhi.ws.Test.readKnowledgeBase(Test.java:31)
at in.abhi.ws.Test.salesTax(Test.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:212)
at
org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:117)
at
org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
at
org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:110)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:181)
at
org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:172)
at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:146)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
****************
Please let me know how to make it work
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-as-a-Webservice-tp3950198.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 10 months
Drools 5.4.0.FINAL and OSGI. Unable to instantiate service for Class 'org.drools.concurrent.ExecutorProvider'
by Per Sterner
Hello,
I have been using Drools 5.3.0.FINAL until now. I am upgrading my
running system with 5.4.0.FINAL. The bundles are all runing. I got some
error messages and tried to reduce the problem and created a simple bundle.
The code only inserts facts and after 20 facts I get the following error:
[ERROR] [System] - Exception in thread "Thread-8"
java.lang.ExceptionInInitializerError
[ERROR] [System] - at
org.drools.concurrent.ExecutorProviderFactory.getExecutorProvider(ExecutorProviderFactory.java:12)
[ERROR] [System] - at
org.drools.rule.constraint.MvelConstraint$ExecutorHolder.<clinit>(MvelConstraint.java:208)
[ERROR] [System] - at
org.drools.rule.constraint.MvelConstraint.jitEvaluator(MvelConstraint.java:199)
[ERROR] [System] - at
org.drools.rule.constraint.MvelConstraint.evaluate(MvelConstraint.java:164)
[ERROR] [System] - at
org.drools.rule.constraint.MvelConstraint.isAllowed(MvelConstraint.java:124)
[ERROR] [System] - at
org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:137)
[ERROR] [System] - at
org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:59)
[ERROR] [System] - at
org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:235)
[ERROR] [System] - at
org.drools.reteoo.EntryPointNode.assertObject(EntryPointNode.java:240)
[ERROR] [System] - at
org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:337)
[ERROR] [System] - at
org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:298)
[ERROR] [System] - at
org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:123)
[ERROR] [System] - at
org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:53)
[ERROR] [System] - at
de.pelle7.drools.test1.simpletest.SimpleTestDrools$1.run(SimpleTestDrools.java:74)
[ERROR] [System] - Caused by: java.lang.IllegalArgumentException: Unable
to instantiate service for Class 'org.drools.concurrent.ExecutorProvider'
[ERROR] [System] - at
org.drools.util.ServiceRegistryImpl.get(ServiceRegistryImpl.java:162)
[ERROR] [System] - at
org.drools.concurrent.ExecutorProviderFactory$ExecutorProviderHolder.<clinit>(ExecutorProviderFactory.java:8)
[ERROR] [System] - ... 14 more
[ERROR] [System] - Caused by: java.lang.IllegalArgumentException: Unable
to instantiate 'org.drools.concurrent.ExecutorProviderImpl'
[ERROR] [System] - at
org.drools.util.ServiceRegistryImpl$ReflectionInstantiator.newInstance(ServiceRegistryImpl.java:213)
[ERROR] [System] - at
org.drools.util.ServiceRegistryImpl$ReflectionInstantiator.call(ServiceRegistryImpl.java:205)
[ERROR] [System] - at
org.drools.util.ServiceRegistryImpl.get(ServiceRegistryImpl.java:160)
[ERROR] [System] - ... 15 more
[ERROR] [System] - Caused by: java.lang.ClassNotFoundException:
org.drools.concurrent.ExecutorProviderImpl
[ERROR] [System] - at
org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:506)
[ERROR] [System] - at
org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:422)
[ERROR] [System] - at
org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410)
[ERROR] [System] - at
org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
[ERROR] [System] - at java.lang.ClassLoader.loadClass(Unknown Source)
[ERROR] [System] - at java.lang.Class.forName0(Native Method)
[ERROR] [System] - at java.lang.Class.forName(Unknown Source)
[ERROR] [System] - at
org.drools.util.ServiceRegistryImpl$ReflectionInstantiator.newInstance(ServiceRegistryImpl.java:210)
[ERROR] [System] - ... 17 more
The Rule file:
package de.pelle7.drools.test1.users.rules.impl;
import de.pelle7.drools.test1.simpletest.*;
import org.jbpm.ruleflow.instance.*;
rule "Funny Rule #1"
dialect "java"
when
$testObject : TestObjectA( value == 0 ) from entry-point "my_entry"
then
System.err.println("New Item: " + $testObject);
retract($testObject);
end
If I change the line
--> $testObject : TestObjectA( value == 0 ) from entry-point "my_entry"
to
--> $testObject : TestObjectA( ) from entry-point "my_entry"
there is no problem.
In the java code i initialize a Drools Session programatically and add
one rule file:
package de.pelle7.drools.test1.simpletest;
import java.io.InputStream;
import java.net.URI;
import java.net.URL;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseConfiguration;
import org.drools.KnowledgeBaseFactoryService;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderConfiguration;
import org.drools.builder.KnowledgeBuilderFactoryService;
import org.drools.builder.ResourceType;
import org.drools.definition.KnowledgePackage;
import org.drools.io.ResourceFactory;
import org.drools.io.ResourceFactoryService;
import org.drools.runtime.StatefulKnowledgeSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SimpleTestDrools {
public static final String DEFAULT_ENTRY = "my_entry";
private static Logger logger =
LoggerFactory.getLogger(SimpleTestDrools.class);
private StatefulKnowledgeSession droolsSession;
private KnowledgeBuilderFactoryService
droolsKnowledgeBuilderFactoryService;
private ResourceFactoryService droolsResourceFactoryService;
private KnowledgeBaseFactoryService droolsKnowledgeBaseFactoryService;
public static Logger getLogger() {
return logger;
}
public StatefulKnowledgeSession getDroolsSession() {
return droolsSession;
}
public void start() {
KnowledgeBuilder kbuilder =
getDroolsKnowledgeBuilderFactoryService().newKnowledgeBuilder();
KnowledgeBaseConfiguration config =
getDroolsKnowledgeBaseFactoryService().newKnowledgeBaseConfiguration();
//config.setOption( MBeansOption.ENABLED );
KnowledgeBase knowledgeBase =
getDroolsKnowledgeBaseFactoryService().newKnowledgeBase(config);
droolsSession = knowledgeBase.newStatefulKnowledgeSession();
LinkedList<URI> resourcesList = new LinkedList<URI>();
try {
resourcesList.add(
getClass().getResource("MyDrools.drl").toURI() );
addResources(droolsSession,
getDroolsKnowledgeBuilderFactoryService(),
resourcesList);
} catch (Exception e) {
e.printStackTrace();
}
new Thread() {
public void run() {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
}
System.out.println("Go 1");
for (int i = 0; i< 1000; i++) {
System.out.println(i);
getDroolsSession().getWorkingMemoryEntryPoint(DEFAULT_ENTRY).insert(new
TestObjectA());
getDroolsSession().fireAllRules();
try {
Thread.sleep(1);
} catch (InterruptedException e) {
}
}
System.out.println("Go 2");
};
}.start();
System.err.println("wait");
//getDroolsSession().fireUntilHalt();
}
public static void addResources(
StatefulKnowledgeSession droolsSession,
KnowledgeBuilderFactoryService
droolsKnowledgeBuilderFactoryService,
List<URI> resources
) throws MyDroolsException {
getLogger().debug("Drools: Register: " + resources);
MyDroolsException exception = null;
KnowledgeBuilderConfiguration lnowledgeBuilderConfiguration =
droolsKnowledgeBuilderFactoryService.newKnowledgeBuilderConfiguration();
HashSet<URI> defects = new HashSet<URI>();
KnowledgeBuilder kbuilder = null;
while (true) {
URI uriError = null;
kbuilder =
droolsKnowledgeBuilderFactoryService.newKnowledgeBuilder(lnowledgeBuilderConfiguration);
try {
Iterator<URI> it = resources.iterator();
while (it.hasNext()) {
URI uri = (URI) it.next();
if (defects.contains(uri)) {
continue;
}
StringBuilder builder = new StringBuilder();
builder.append("Adding drools file '" +
uri.toString() + "'");
URL url = uri.toURL();
InputStream iStream = url.openStream();
ResourceType resourceType;
String path = uri.getPath().toLowerCase();
resourceType =
ResourceType.determineResourceType(path);
getLogger().debug(builder.toString());
kbuilder.add(ResourceFactory.newInputStreamResource(iStream), resourceType);
// Check the builder for errors
if (kbuilder.hasErrors()) {
uriError = uri;
//getLogger().error(kbuilder.getErrors().toString());
String errorMessage =
kbuilder.getErrors().toString();
kbuilder.getErrors().clear();
throw new MyDroolsException(errorMessage);
}
try {
iStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (Throwable e) {
if (uriError != null) {
defects.add(uriError);
}
String msg = "Error in Resource '" + uriError + "'";
getLogger().error(msg);
e.printStackTrace();
if (exception != null) {
exception = new MyDroolsException(msg, exception);
} else {
exception = new MyDroolsException(msg);
}
exception = new MyDroolsException(e.getMessage(),
exception);
continue;
}
// All done!
break;
}
final Collection<KnowledgePackage> pkgs =
kbuilder.getKnowledgePackages();
droolsSession.getKnowledgeBase().addKnowledgePackages(pkgs);
if (exception != null) {
throw new MyDroolsException("Error while adding
resources!", exception);
}
}
public KnowledgeBuilderFactoryService
getDroolsKnowledgeBuilderFactoryService() {
return droolsKnowledgeBuilderFactoryService;
}
public void setDroolsKnowledgeBuilderFactoryService(
KnowledgeBuilderFactoryService
droolsKnowledgeBuilderFactoryService) {
this.droolsKnowledgeBuilderFactoryService =
droolsKnowledgeBuilderFactoryService;
}
public ResourceFactoryService getDroolsResourceFactoryService() {
return droolsResourceFactoryService;
}
public void setDroolsResourceFactoryService(
ResourceFactoryService droolsResourceFactoryService) {
this.droolsResourceFactoryService = droolsResourceFactoryService;
}
public KnowledgeBaseFactoryService
getDroolsKnowledgeBaseFactoryService() {
return droolsKnowledgeBaseFactoryService;
}
public void setDroolsKnowledgeBaseFactoryService(
KnowledgeBaseFactoryService
droolsKnowledgeBaseFactoryService) {
this.droolsKnowledgeBaseFactoryService =
droolsKnowledgeBaseFactoryService;
}
}
Some of the bundles in my runtime are:
39 ACTIVE org.drools.core_5.4.0.Final
66 ACTIVE org.drools.compiler_5.4.0.Final
78 ACTIVE org.drools.templates_5.4.0.Final
94 ACTIVE org.drools.internalapi_5.4.0.Final
136 ACTIVE org.drools.decisiontables_5.4.0.Final
189 ACTIVE org.drools.api_5.4.0.Final
191 ACTIVE org.mvel2_2.1.0.drools16
6 ACTIVE org.jbpm.flow.core_5.3.0.Final
13 ACTIVE org.jbpm.bpmn2_5.3.0.Final
71 ACTIVE org.jbpm.flow.builder_5.3.0.Final
142 ACTIVE org.jbpm.flow-persistence-jpa_5.3.0.FINAL
regards,
Per Sterner
11 years, 10 months
Drools: Using Declared Types in Decision Tables
by David Smith
Hi,
I am trying to use a declared type in a decision table
but get an "Unable to resolve ObjectType" message.
The declared type is in a file types.drl,
I have a spreadsheet test.xls that has a Ruleset with
an import line for the declared type.
Is it possible to reference a declared type from a decision table?
Is it possible to declare a type in a decision table?
Thanks
David
11 years, 10 months
Drools 5.4 Jitting Error
by gboro54
I just updated to Drools 5.4 and I am not getting the following error on all
my map accessors:
10:41:12,997 ERROR [stderr] (Thread-169) Exception in thread "Thread-169"
java.lang.RuntimeException: Exception jitting: feeKeys[1] == null
10:41:12,998 ERROR [stderr] (Thread-169) at
org.drools.rule.constraint.MvelConstraint.executeJitting(MvelConstraint.java:219)
10:41:12,999 ERROR [stderr] (Thread-169) at
org.drools.rule.constraint.MvelConstraint.access$000(MvelConstraint.java:41)
10:41:13,000 ERROR [stderr] (Thread-169) at
org.drools.rule.constraint.MvelConstraint$1.run(MvelConstraint.java:201)
10:41:13,000 ERROR [stderr] (Thread-169) at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
10:41:13,001 ERROR [stderr] (Thread-169) at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
10:41:13,002 ERROR [stderr] (Thread-169) at
java.lang.Thread.run(Thread.java:662)
10:41:13,002 ERROR [stderr] (Thread-169) Caused by: java.lang.VerifyError:
(class: ConditionEvaluator51817e9f4a7542c5b295be7d674f854c, method: evaluate
signature:
(Ljava/lang/Object;Lorg/drools/common/InternalWorkingMemory;Lorg/drools/reteoo/LeftTuple;)Z)
Expecting to find object/array on stack
10:41:13,004 ERROR [stderr] (Thread-169) at
java.lang.Class.getDeclaredConstructors0(Native Method)
10:41:13,004 ERROR [stderr] (Thread-169) at
java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
10:41:13,005 ERROR [stderr] (Thread-169) at
java.lang.Class.getConstructor0(Class.java:2699)
10:41:13,005 ERROR [stderr] (Thread-169) at
java.lang.Class.getConstructor(Class.java:1657)
10:41:13,006 ERROR [stderr] (Thread-169) at
org.drools.rule.builder.dialect.asm.ClassGenerator.newInstance(ClassGenerator.java:173)
10:41:13,006 ERROR [stderr] (Thread-169) at
org.drools.rule.constraint.ASMConditionEvaluatorJitter.jitEvaluator(ASMConditionEvaluatorJitter.java:53)
10:41:13,007 ERROR [stderr] (Thread-169) at
org.drools.rule.constraint.MvelConstraint.executeJitting(MvelConstraint.java:217)
10:41:13,008 ERROR [stderr] (Thread-169) ... 5 more
Could anyone indicate how to fix this?
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-5-4-Jitting-Error-tp3999176.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 11 months
Rules with variable timers
by Shannon Hastings
Is there a way to write a rule in DRL that uses a timer or something that is dynamic. I.E. I want the time that rule waits to fire to be dependent on a variable such as below:
rule "CheckDoseMissed"
no-loop
timer(int: $eventA.sleepTime)
when
$eventA : MyEvent()
………..
----------
Shannon Hastings
Inventrio
shannon.hastings(a)inventrio.com
(614) 389-2795 ext: 101
http://www.inventrio.com
11 years, 11 months
Building our own UI for Drools
by kapokfly
Due to some reasons (for example, build a consistent UI within our own
application, easier to work with our own meta data, don't want SSO etc), we
are considering to build our own UI to generate Drools rule file basing on
the user input via the UI , has anyone tried this before? Is there any
library shipped within Drools Gunvor can be used to be easier to work with
Drools rule syntax?
Thanks,
Ivan
-----
Ivan, your Panda, forever
--
View this message in context: http://drools.46999.n3.nabble.com/Building-our-own-UI-for-Drools-tp350884...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years
Drools Guvnor API information?
by Vikas Hazrati
Hi,
I am looking at using Guvnor for our project where users would be creating
rules using our UI. For this i need to add / modify rule or any asset for
that matter using an api.
Unfortunately, i could not find enough documentation to suggest the best way
to use the REST api, which I guess is provided by Guvnor. Could someone let
me know the location of where i can get some information for this api. I
also see that the issue GUVNOR-1080
(https://issues.jboss.org/browse/GUVNOR-1080) is marked resolved so the api
should exist right? or that we cannot access it remotely until we have the
Atom Pub Interface done?
Help appreciated .
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Drools-Guvnor-API-inf...
Sent from the Drools - User mailing list archive at Nabble.com.
12 years