6 Replies Latest reply on Sep 11, 2013 8:13 AM by pferraro

    ClassCastException resulting from simple (I think) cache usage in single application

    lincolnthree

      Hey Folks,

       

      I'm working on a pretty simple application (from an Infinispan point of view,) and I've got an issue where I store an object into a cache, then retrieve it again, and I get a ClassCastException on the same type. This obviously means that the type is being created by the wrong classloader, but I don't know why this would be; particularly since I am not even running this on a cluster yet, simply on my local dev box with one application on one server.

       

      The application can be found here: https://github.com/ocpsoft/redoculous/tree/plain_cache (under the `plain_cache` branch) Simply deploy and access the URL: http://localhost:8080/redoculous-server/v1/serve?repo=https://github.com/ocpsoft/redoculous.git&ref=master&path=/docs/in…

       

      To summarize, this is the cache:

      public class CacheProducer

      {

         private static final String REPOSITORY_CACHE = "repository.cache";

       

       

         @Inject

         private EmbeddedCacheManager cacheManager;

       

       

         @Produces

         @RepositoryCache

         public Cache<String, Repository> getRepositoryCache()

         {

            Cache<String, Repository> result = cacheManager.getCache(REPOSITORY_CACHE);

            return result;

         }

      }

       

      This is the usage:

       

         @Inject

         @RepositoryCache

         private Cache<String, Repository> repositoryCache;

       

       

         @Inject

         private FileOperations io;

       

       

         @Inject

         private GridFilesystem gfs;

       

       

         @Inject

         private RenderService render;

       

       

         @Override

         public Repository getCachedRepository(String url)

         {

            String key = Keys.repository(url);

            Repository result = (Repository) repositoryCache.get(key);

            if (result == null)

            {

               Repository localRepo = getLocalRepository(url);

               localRepo.init();

       

       

               result = new GitRepository(gfs.getFile("/"), url);

               io.copyDirectoryToGrid(gfs, localRepo.getBaseDir(), result.getBaseDir());

               repositoryCache.putIfAbsentAsync(key, result);

            }

            return result;

         }

       

      This is the exception:

      Caused by: java.lang.ClassCastException: org.ocpsoft.redoculous.model.impl.GitRepository cannot be cast to org.ocpsoft.redoculous.model.Repository

        at org.ocpsoft.redoculous.service.impl.RepositoryServiceImpl.getCachedRepository(RepositoryServiceImpl.java:44) [classes:]

        at org.ocpsoft.redoculous.service.impl.RepositoryServiceImpl.getRenderedPath(RepositoryServiceImpl.java:60) [classes:]

        at org.ocpsoft.redoculous.rest.DocumentService.serve(DocumentService.java:40) [classes:]

        at org.ocpsoft.redoculous.rest.DocumentService$Proxy$_$$_WeldClientProxy.serve(DocumentService$Proxy$_$$_WeldClientProxy.java) [classes:]

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [classes.jar:1.6.0_51]

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [classes.jar:1.6.0_51]

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [classes.jar:1.6.0_51]

        at java.lang.reflect.Method.invoke(Method.java:597) [classes.jar:1.6.0_51]

        at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:167) [resteasy-jaxrs-2.3.6.Final-redhat-1.jar:2.3.6.Final-redhat-1]

        at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:269) [resteasy-jaxrs-2.3.6.Final-redhat-1.jar:2.3.6.Final-redhat-1]

        at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:227) [resteasy-jaxrs-2.3.6.Final-redhat-1.jar:2.3.6.Final-redhat-1]

        at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:216) [resteasy-jaxrs-2.3.6.Final-redhat-1.jar:2.3.6.Final-redhat-1]

        at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:542) [resteasy-jaxrs-2.3.6.Final-redhat-1.jar:2.3.6.Final-redhat-1]

        ... 28 more

       

      Yes GitRepository implements Repository:

      public class GitRepository extends AbstractRepository implements Repository

       

      Where my app-server has a simple cache configured like so:

      <cache-container name="local" default-cache="local" jndi-name="java:jboss/infinispan/cluster" start="EAGER">

         <local-cache name="local"/>

      </cache-container> 

       

      I don't think I'm doing anything that crazy, but... obviously either I must be doing something wrong, or there is a bug in what I am trying to do. What should I do to resolve this?

       

      Also, question #2 - what is the best way of simulating an openshift infinispan cluster locally? (without running origin, obviously) I just want to work on my local EAP installation.

       

      Thanks!