3 Replies Latest reply on Jul 12, 2012 2:33 AM by viktor

    ClassCastException when accessing CacheManager in jBoss 7.1.1

    viktor

      Hi,

       

      I am newby with Infinispan, don't hit me hard please.

      I am trying to access cache within jBoss 7.1.1.Final server. The intent is to use cache within EJB.

      We use java 1.6, hence code uses JNDI lookup:

       

       

      @PostConstruct

        private void initMe(){

       

            InitialContext ic = new InitialContext();

            Object fromLookup = ic.lookup("java:jboss/infinispan/jboss-as7-quickstart");

            log.log(Level.INFO, "******************************** fromLookup.getClass()= " + fromLookup.getClass() );

            DefaultEmbeddedCacheManager cm = (DefaultEmbeddedCacheManager)fromLookup;

      ....

       

      As a result I get class cast exception(note that class signatures are the same): 

       

      27.0.0.1-8443-3) ******************************** fromLookup.getClass()= class org.jboss.as.clustering.infinispan.DefaultEmbeddedCacheManager

      09:34:48,043 SEVERE [xxx.SystemConfig] (http--127.0.0.1-8443-3) Could not cust jboss-as7-quickstart: java.lang.ClassCastException:

      org.jboss.as.clustering.infinispan.DefaultEmbeddedCacheManager cannot be cast to

      org.jboss.as.clustering.infinispan.DefaultEmbeddedCacheManager

       

       

      Looks like build issue...difference in class serial id?

       

      My maven dependancy is

       

      <dependency>

      <groupId>org.jboss.as</groupId>

      <artifactId>jboss-as-clustering-infinispan</artifactId>

      <version>7.1.1.Final</version>

      </dependency>

       

       

      Extract from standalone.xml:

       

                  <cache-container name="jboss-as7-quickstart" default-cache="jboss-as7-quickstart-cache" jndi-name="java:jboss/infinispan/jboss-as7-quickstart">

                      <local-cache name="jboss-as7-quickstart-cache" start="EAGER"/>

                  </cache-container>

       

      Any hints?

       

      Cheers,

       

      Viktor

        • 1. Re: ClassCastException when accessing CacheManager in jBoss 7.1.1
          viktor

          Ok... no answers.

           

          Wondering if anybody has managed to use infinispan under jBoss 7.1.1 and Java 1.6 at all.

           

          I suspect that everybody uses Java 1.7... Is it correct?

          • 2. Re: ClassCastException when accessing CacheManager in jBoss 7.1.1
            galder.zamarreno

            What's most likely happening is that you're embedding AS7 classes in your application and that's causing classloader issues, because the same class that belongs to two different classloaders cannot be cast.

             

            Instead, inject the cache as instructed in https://github.com/infinispan/infinispan-quickstart/tree/master/jboss-as7 and you'd better off. You can inject the cache into an EJB too

            1 of 1 people found this helpful
            • 3. Re: ClassCastException when accessing CacheManager in jBoss 7.1.1
              viktor

              Galder,

               

              Thanx for the hint.

              I've upgradeded to Java SE 7 to workaround the @Resource lookup problem and  managed to deploy sample above to jBoss 7.1.1.

               

              But when I try using it in my app in jBoss 7 - my injected cache is always null.

               

              I miss something...I went as far as copying Resource.java and Controller.java from the sample as is into my app.

               

               

               

              @Singleton

              public class Resources {

              .....  

                 @SuppressWarnings("unused")

                 @Produces

                 @Resource(lookup="java:jboss/infinispan/container/jboss-as7-quickstart")// note that config is unchanged and works in quickstart

                 private static EmbeddedCacheManager container;

               

               

               

              @SessionScoped

              @Named

              public class Controller implements Serializable {

                

                 @Inject

                 transient AdvancedCache<Object, Object> cache;

               

              Still cache in controller null. No complains from jBoss when deploying.

              I've copied most of the pom stuff in my pom....any hints what else needs to be done to get that elusive cache?