[rules-users] Drools 5.4.0.FINAL and OSGI. Unable to instantiate service for Class 'org.drools.concurrent.ExecutorProvider'

Per Sterner pelle711 at yahoo.de
Tue May 29 09:30:21 EDT 2012


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



More information about the rules-users mailing list