4 Replies Latest reply on Aug 31, 2010 9:43 AM by ivokolev

    Using infinispan in an OSGi container

    sellhorn

      Hi! I can't find any information about using Infinispan in an OSGi container.

       

      Here's what I've done so far, inside a Felix like OSGi container (karaf running on felix) I've installed the following maven artifacts;

       

      org.infinispan/infinispan-core/4.0.0-FINAL

      jgroups/jgroups/2.9.0.GA

      org.jboss.javaee/jboss-transaction-api/1.0.1.GA

      org.jboss.marshalling/river/1.2.0.GA

      org.jboss.marshalling/marshalling-api/1.2.0.GA

      org.jboss/jboss-common-core/2.2.14.GA

      org.rhq.helpers/rhq-pluginAnnotations/1.4.0.B01

       

      Since none of these packages are proper OSGi bundles, I installed them using the wrap command, ex:

       

      install -s wrap:mvn:org.infinispan/infinispan-core/4.0.0.FINAL

       

      Everything loads and goes to "Active" state.

       

      Now I create a sample OSGi project, all the activator does is this;

       

      public void start(BundleContext context) throws Exception {
              System.out.println("Cache Start");
                try
              {
                  System.out.println("Creating cache");

       

                  org.infinispan.manager.DefaultCacheManager manager =
                      new org.infinispan.manager.DefaultCacheManager();


              manager.getCache();
              }
              catch (Throwable ex)
              {
                  System.out.println("Failed to start cache!");
                  ex.printStackTrace();
              }
          }

       

      Here is what this bundle information looks like (for the test);

       

      InfinispanTest Bundle (203)
      ----------------------------
      Manifest-Version = 1.0
      Export-Package = test.infinispan;uses:="org.infinispan,org.jboss.marshalli
      ng.river,org.osgi.framework,org.infinispan.manager"
      Built-By = SellhoAu
      Tool = Bnd-0.0.357
      Bundle-Name = InfinispanTestOSGi Bundle
      Created-By = Apache Maven Bundle Plugin
      Bundle-Version = 1.0.0.SNAPSHOT
      Build-Jdk = 1.6.0_16
      Bnd-LastModified = 1279075996419
      Bundle-ManifestVersion = 2
      Bundle-Activator = test.infinispan.Activator
      Import-Package = test.infinispan,org.infinispan,org.infinispan.manager,org
      .jboss.marshalling.river,org.osgi.framework;version="1.5"
      Bundle-SymbolicName = test.infinispan

       

      When I start the bundle, it fails on getCache() (it can create the manager)

       

      ====================================================================================

       

      org.infinispan.CacheException: Unable to invoke method public void org.infinispa
      n.marshall.VersionAwareMarshaller.start() on object
              at org.infinispan.util.ReflectionUtil.invokeAccessibly(ReflectionUtil.ja
      va:173)
              at org.infinispan.factories.AbstractComponentRegistry$PrioritizedMethod.
      invoke(AbstractComponentRegistry.java:852)
              at org.infinispan.factories.AbstractComponentRegistry.internalStart(Abst
      ractComponentRegistry.java:672)
              at org.infinispan.factories.AbstractComponentRegistry.start(AbstractComp
      onentRegistry.java:574)
              at org.infinispan.factories.GlobalComponentRegistry.start(GlobalComponen
      tRegistry.java:131)
              at org.infinispan.factories.ComponentRegistry.start(ComponentRegistry.ja
      va:135)
              at org.infinispan.CacheDelegate.start(CacheDelegate.java:311)
              at org.infinispan.manager.DefaultCacheManager.createCache(DefaultCacheMa
      nager.java:507)
              at org.infinispan.manager.DefaultCacheManager.getCache(DefaultCacheManag
      er.java:473)
              at org.infinispan.manager.DefaultCacheManager.getCache(DefaultCacheManag
      er.java:446)
              at ge.energy.ssi.om.core.OMActivator.start(OMActivator.java:32)
              at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(Bund
      leContextImpl.java:783)
              at java.security.AccessController.doPrivileged(Native Method)
              at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActiv
      ator(BundleContextImpl.java:774)
              at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(Bund
      leContextImpl.java:755)
              at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(Bundl
      eHost.java:352)
              at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(Abstrac
      tBundle.java:280)
              at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(Abstrac
      tBundle.java:272)
              at org.apache.felix.karaf.shell.osgi.StartBundle.doExecute(StartBundle.j
      ava:29)
              at org.apache.felix.karaf.shell.osgi.BundlesCommand.doExecute(BundlesCom
      mand.java:49)
              at org.apache.felix.karaf.shell.console.OsgiCommandSupport.execute(OsgiC
      ommandSupport.java:41)
              at org.apache.felix.gogo.commands.basic.AbstractCommand.execute(Abstract
      Command.java:35)
              at org.apache.felix.gogo.runtime.shell.CommandProxy.execute(CommandProxy
      .java:50)
              at org.apache.felix.gogo.runtime.shell.Closure.execute(Closure.java:229)

       

              at org.apache.felix.gogo.runtime.shell.Closure.executeStatement(Closure.
      java:162)
              at org.apache.felix.gogo.runtime.shell.Pipe.run(Pipe.java:101)
              at org.apache.felix.gogo.runtime.shell.Closure.execute(Closure.java:79)
              at org.apache.felix.gogo.runtime.shell.CommandSessionImpl.execute(Comman
      dSessionImpl.java:71)
              at org.apache.felix.karaf.shell.console.jline.Console.run(Console.java:1
      81)
              at java.lang.Thread.run(Thread.java:619)
      Caused by: java.lang.reflect.InvocationTargetException
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
      java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
      sorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at org.infinispan.util.ReflectionUtil.invokeAccessibly(ReflectionUtil.ja
      va:170)
              ... 29 more
      Caused by: org.infinispan.CacheException: Unable to load JBoss Marshalling marsh
      aller factory org.jboss.marshalling.river.RiverMarshallerFactory
              at org.infinispan.marshall.jboss.JBossMarshaller.start(JBossMarshaller.j
      ava:102)
              at org.infinispan.marshall.VersionAwareMarshaller.start(VersionAwareMars
      haller.java:75)
              ... 34 more
      Caused by: java.lang.ClassNotFoundException: org.jboss.marshalling.river.RiverMa
      rshallerFactory
              at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
              at java.security.AccessController.doPrivileged(Native Method)
              at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
              at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
              at org.eclipse.core.runtime.internal.adaptor.ContextFinder.loadClass(Con
      textFinder.java:129)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
              at org.infinispan.util.Util.loadClass(Util.java:56)
              at org.infinispan.util.Util.getInstance(Util.java:86)
              at org.infinispan.marshall.jboss.JBossMarshaller.start(JBossMarshaller.j
      ava:100)
              ... 35 more

       

      ====================================================================================

       

      Now my module doesn't use river directly so I shouldn't have to import it, however in the header information posted above you'll see it. I did that to test, either way I get an error.

       

      Now on the infinispan bundle it imports (via wrap) every statically compiled package, which doesn't include river. So I manually edited it so that it imports a wildcard (everything). Still doesn't work ...

       

      ex: (without the super long Export-Package, again this is done by wrap or bnd to be more exact)

       

      Private-Package = .
      Implementation-Title = Infinispan Core
      Implementation-Version = 4.0.0.FINAL
      Specification-Vendor = JBoss, a division of Red Hat
      Built-By = manik
      Tool = Bnd-0.0.313
      Bundle-Name = wrap_mvn_org.infinispan_infinispan-core_4.0.0.FINAL
      Created-By = 1.6.0_16 (Sun Microsystems Inc.)
      Implementation-Vendor = JBoss, a division of Red Hat
      Generated-By-Ops4j-Pax-From = wrap:mvn:org.infinispan/infinispan-core/4.0.0.FINA
      L
      Implementation-Vendor-Id = org.infinispan
      Bundle-Version = 0
      Build-Jdk = 1.6.0_17
      Bnd-LastModified = 1279071183515
      Bundle-ManifestVersion = 2
      Specification-Title = Infinispan Core
      Bundle-SymbolicName = wrap_mvn_org.infinispan_infinispan-core_4.0.0.FINAL
      Import-Package = *;resolution:=optional
      Specification-Version = 4.0.0.FINAL
      Originally-Created-By = Apache Maven
      Main-Class = org.infinispan.Version
      Archiver-Version = Plexus Archiver

       

      ==================================================

       

       

      Any ideas??? Or is there an OSGi enabled infinispan package out there (or a plan to do this)?

       

      Thanks

        • 1. Re: Using infinispan in an OSGi container
          sellhorn

          Well, I guess I answered this myself ;-)

           

          The problem is the infinispan-core jar when wrapped in OSGi has no visibility to the river marshalling bundle. So one solution is when installing the bundle to wrap it and use a file to to a dynamic import.

           

          http://wiki.ops4j.org/display/paxurl/Wrap+Protocol

           

          I do;

           

          install wrap:mvn:org.infinispan/infinispan-core/4.0.0.FINAL,file:infinispan.bnd

           

          infinispan.bnd contents are;

           

          DynamicImport-Package: *

           

          And that's it! Now I can run a bundle that uses infinispan and the infinispan bundle can load the river marshalling implementation. Everybody is happy!

          • 2. Re: Using infinispan in an OSGi container
            galder.zamarreno

            Hey Augusto, could you write a wiki in the Infinispan wiki space (http://community.jboss.org/wiki/Infinispan) explaining the steps you did in greater detail? That way the whole Infinispan community can benefit from the excellent work you did

            • 3. Re: Using infinispan in an OSGi container
              galder.zamarreno

              Note as well that we run a JBoss Community Awards on a yearly basis which includes a category for Best Wiki. So, if you write a wiki you get the chance to win in next year's contest

              • 4. Re: Using infinispan in an OSGi container
                ivokolev

                Hallo, Augusto,

                 

                First to share my approach.

                 

                I downloaded Infinispan 4.0.0 and its dependencies (the jars you'd listed). Then I created BND property files to customize the defaults for impored and exported packages. I installed the "OSGified" bundles in my Maven and build the project which is going to use Infinispan. The bundles run in Apache Felix. All bundles are properly installed and activated, but when creating SCR context for a bundle, an error in Infinispan core bundle appears (trace below). It seems related to class loader.

                 

                Have you encountered some runtime issues running Infinispan in OSGi?

                 

                Cheers, Ivo

                 

                P.S. If someone is interested I can share the scripts, though they are not really worthy if Infinispan is not running in the end.

                 

                2010-08-31 16:04:19,766 18610 [SCR Component Actor] ERROR org.infinispan.jmx.AbstractJmxRegistration  - Could not instantiate MBeanServerLookup('org.infinispan.jmx.PlatformMBeanServerLookup')
                java.lang.ClassNotFoundException: org.infinispan.jmx.PlatformMBeanServerLookup
                    at java.net.URLClassLoader$1.run(Unknown Source)
                    at java.security.AccessController.doPrivileged(Native Method)
                    at java.net.URLClassLoader.findClass(Unknown Source)
                    at java.lang.ClassLoader.loadClass(Unknown Source)
                    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
                    at java.lang.ClassLoader.loadClass(Unknown Source)
                    at org.infinispan.util.Util.loadClass(Util.java:56)
                    at org.infinispan.util.Util.getInstance(Util.java:86)
                    at org.infinispan.jmx.AbstractJmxRegistration.getMBeanServer(AbstractJmxRegistration.java:64)
                    at org.infinispan.jmx.AbstractJmxRegistration.registerMBeans(AbstractJmxRegistration.java:51)
                    at org.infinispan.jmx.CacheManagerJmxRegistration.start(CacheManagerJmxRegistration.java:39)
                    at org.infinispan.manager.DefaultCacheManager.start(DefaultCacheManager.java:515)
                    at org.infinispan.manager.DefaultCacheManager.<init>(DefaultCacheManager.java:336)
                    at org.infinispan.manager.DefaultCacheManager.<init>(DefaultCacheManager.java:302)