7 Replies Latest reply on Mar 8, 2012 8:25 AM by dbeltran

    Infinispan preload custom application class from file persistence

    dbeltran

      Hi,

       

      I would like to know what's the easy way to get the infinispan Cache configurated like EAGER and file persistence to preload our custom applicattion classes. We can put and get the classes without problems, but when we restart the server we get the following excepcion:

       

      14:19:55,411 ERROR [org.infinispan.loaders.file.FileCacheStore] (pool-15-thread-1) ISPN000062: Error while reading from file: /var/lib/jboss-as-7.1.0.Final/standalone/configuration/pcci/escache/persistencia/CachePersistenciaFichero/1610233856: java.lang.ClassNotFoundException: com.eliopseinalia.pcci.escache.test.junit.dominio.ESCacheTestCiudad from [Module "org.jboss.as.clustering.infinispan:main" from local module loader @177b3cd (roots: /var/lib/jboss-as-7.1.0.Final/modules)]
          at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
          at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
          at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
          at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:423)
          at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
          at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
          at java.lang.Class.forName0(Native Method) [rt.jar:1.6.0_30]
          at java.lang.Class.forName(Class.java:247) [rt.jar:1.6.0_30]
          at org.jboss.marshalling.AbstractClassResolver.loadClass(AbstractClassResolver.java:135) [jboss-marshalling-1.3.9.GA.jar:1.3.9.GA]
          at org.jboss.marshalling.AbstractClassResolver.resolveClass(AbstractClassResolver.java:116) [jboss-marshalling-1.3.9.GA.jar:1.3.9.GA]
          at org.jboss.marshalling.river.RiverUnmarshaller.doReadClassDescriptor(RiverUnmarshaller.java:892)
          at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1204)
          at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:272)
          at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:209)
          at org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:37) [jboss-marshalling-1.3.9.GA.jar:1.3.9.GA]
          at org.infinispan.container.entries.ImmortalCacheEntry$Externalizer.readObject(ImmortalCacheEntry.java:158) [infinispan-core-5.1.1.FINAL.jar:5.1.1.FINAL]
          at org.infinispan.container.entries.ImmortalCacheEntry$Externalizer.readObject(ImmortalCacheEntry.java:148) [infinispan-core-5.1.1.FINAL.jar:5.1.1.FINAL]
          at org.infinispan.marshall.jboss.ExternalizerTable$ExternalizerAdapter.readObject(ExternalizerTable.java:399) [infinispan-core-5.1.1.FINAL.jar:5.1.1.FINAL]
          at org.infinispan.marshall.jboss.ExternalizerTable.readObject(ExternalizerTable.java:287) [infinispan-core-5.1.1.FINAL.jar:5.1.1.FINAL]
          at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:351)
          at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:209)
          at org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:37) [jboss-marshalling-1.3.9.GA.jar:1.3.9.GA]
          at org.infinispan.loaders.bucket.Bucket$Externalizer.readObject(Bucket.java:157) [infinispan-core-5.1.1.FINAL.jar:5.1.1.FINAL]
      ...
      

      I understand tha infinispan can't locate our classes, and we have created a jar with the classes that infinispan is looking for, but we don't know where to put it. Of course the lib folder doesn't work. I haved tried to create a simple module with our jar and to add a dependece in the infinispan module but this doesn't work either.

       

      Any help would be appreciate. Thank you in advance,

       

      David

        • 1. Re: Infinispan preload custom application class from file persistence
          pferraro

          Why would you want to configure the cache to start eagerly start and preload if its contents can only be read by your application?

          In order to use preload successfully, your application need to be the agent that starts the cache.  Eager starting by the server won't work.  I suggest you add some bootstrap code to your application that starts the cache on deploy and stops it on undeploy.

          • 2. Re: Infinispan preload custom application class from file persistence
            dbeltran

            Thank you for your answer,

             

            But if I configure the cache as LAZY and execute the following code in my application I get the same ClassNotFoundException error:

             

            this.container = (EmbeddedCacheManager) new InitialContext().lookup(containerLookup);
            objCache = this.container.getCache(getConfig().getId());
            

             

            am I missing something?

             

            Best regards,

             

            David

            • 3. Re: Infinispan preload custom application class from file persistence
              helga.w.

              I have been having problems with the Infinispan FileStoreCache.  One thing that I wasted a lot of time on was that issues that I thought were related to server startups were actually issues that were related to demarshalling values that had been evicted from memory.

               

              To see if this issue is related to initial load or demarshalling, try to reduce the number of entries in the cache to something very low, for example 10 entries.

               

              i.e. something like:

               

              <eviction maxEntries="10" strategy="LIRS" />

              • 4. Re: Infinispan preload custom application class from file persistence
                pferraro

                David,

                Do you still have your cache-container set to start EAGERly?  Otherwise, it would not be available to JNDI via that mechanism.

                You may need to explicitly set the classloader of your cache via CacheConfigurationBuilder.classLoader(...).

                1 of 1 people found this helpful
                • 5. Re: Infinispan preload custom application class from file persistence
                  dbeltran

                  Thanks Helga,

                   

                  But the problem is not related with the eviction policy because I haved placed only one object into the cache. Beside to that, today I have the file storage working but I have had to create a module with my classes and I have had to define a dependency in the org.jboss.as.clustering.infinispan module over my module.

                  • 6. Re: Infinispan preload custom application class from file persistence
                    dbeltran

                    Thanks Paul,

                     

                    We have changed the cache to LAZY some time ago and I already knew the JNDI problem which we have resolved through a call to the container's getCache method. As you can see above we got the cache working today but I dont like the dependency adjustment in the infinispan module. I will investigate the classLoader aproximation you have proposed. Thank you again,

                     

                    David

                    • 7. Re: Infinispan preload custom application class from file persistence
                      dbeltran

                      Finally the following line did the trick:

                       

                      Cache cache = container.getCache(idCache);
                      cache.getConfiguration().setClassLoader(Thread.currentThread().getContextClassLoader());
                      

                       

                      Also I have had to deactivate the preload attribute in file-storage.

                       

                      Thank you Paul