8 Replies Latest reply on Dec 3, 2007 7:55 AM by Arjan Molenaar

    Problem reading (deserializing) objects from FileCacheLoader

    Arjan Molenaar Newbie

      Hi,

      I can't seem to get it working.. I'm running JBossCache on a default JBoss4.0.5 installation (JDK 1.5). I've configured JBossCache as a service (deploy/treecache-service.xml). For each deployed webapp a separate ClassLoader is instantiated, so I have to register a ClassLoader for a section of the TreeCache (see below).

      The problem is that once objects are serialized to the file cache, they can't be de-serialized (unmarshalled).

      I'm getting stack traces like this:

      java.lang.ClassNotFoundException: No ClassLoaders found for: nl.yirdis.monet.chart.ChartMetadata
       at org.jboss.mx.loading.LoadMgr3.beginLoadTask(LoadMgr3.java:212)
       at org.jboss.mx.loading.RepositoryClassLoader.loadClassImpl(RepositoryClassLoader.java:514)
       at org.jboss.mx.loading.RepositoryClassLoader.loadClass(RepositoryClassLoader.java:408)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
       at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
       at java.lang.Class.forName0(Native Method)
       at java.lang.Class.forName(Class.java:242)
       at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:584)
       at org.jboss.invocation.MarshalledValueInputStream.resolveClass(MarshalledValueInputStream.java:109)
       at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1543)
       at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1465)
       at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1698)
       at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1304)
       at java.io.ObjectInputStream.readObject(ObjectInputStream.java:349)
       at java.util.HashMap.readObject(HashMap.java:1013)
       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:585)
       at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:946)
       at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1818)
       at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1718)
       at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1304)
       at java.io.ObjectInputStream.readObject(ObjectInputStream.java:349)
       at org.jboss.cache.loader.FileCacheLoader.loadAttributes(FileCacheLoader.java:486)
       at org.jboss.cache.loader.FileCacheLoader.get(FileCacheLoader.java:136)
       at org.jboss.cache.interceptors.CacheLoaderInterceptor.loadData(CacheLoaderInterceptor.java:443)
       at org.jboss.cache.interceptors.CacheLoaderInterceptor.loadNode(CacheLoaderInterceptor.java:353)
       at org.jboss.cache.interceptors.CacheLoaderInterceptor.invoke(CacheLoaderInterceptor.java:180)
       at org.jboss.cache.interceptors.Interceptor.invoke(Interceptor.java:68)
       at org.jboss.cache.interceptors.UnlockInterceptor.invoke(UnlockInterceptor.java:32)
      


      In my treecache configuration I've enabled RegionBasedMarshalling and InactiveOnStartup, as described in the user guide:

       <attribute name="UseRegionBasedMarshalling">true</attribute>
       <attribute name="InactiveOnStartup">true</attribute>
      


      The region is configured like this:

       <region name="/nl/yirdis/monet/charts">
       <attribute name="maxNodes">1000</attribute>
       <attribute name="timeToLiveSeconds">86400</attribute>
       <attribute name="maxAgeSeconds">86400</attribute>
       </region>
      


      In my code (using Spring), I've set the ClassLoader for that region to the Classloader of the webapp:

       public void afterPropertiesSet() throws Exception {
       treeCache.registerClassLoader("/nl/yirdis/monet/charts/", ChartMetadata.class.getClassLoader());
       treeCache.activateRegion("/nl/yirdis/monet/charts/");
       }
      


      (ChartMetadata is a class containing the serialized stuff. It implements the Serializable interface).

      Deactivation on undeployment of the webapp is done likewise, as stated in the docs.

      Where did I go wrong? What's causing the TreeCache (FileCacheLoader) to cause class loading errors?


      Regards,

      Arjan