4 Replies Latest reply on Sep 9, 2011 4:52 AM by Vikas V

    Infinispan : Getting Null pointer exception

    Vikas V Newbie

      Hi,

       

      Am using Jboss AS 6, GateIn 3.1 and Infinispan 5.1.CR8

       

      My configurations are as below,

       

      In  $JBOSS_HOME/server/all/deploy/cluster/infinispan-cache-registry.sar/cache-container-registry-jboss-beans.xml

       

       

      .........

       

       

      <bean id="testInfinispanServlet" class="com.tsky.selfcare.cache.InfinispanServlet">
            <property name="cacheManager" ref="cacheManager"/>
        </bean>


        <!-- JNDI Configuration -->

        <jee:jndi-lookup id="cacheManager" jndi-name="java:CacheManager/infinispanTest"/>

      .........

       

      My infinispan-config.xml in 

       

      $JBOSS_HOME/server/all/deploy/cluster/infinispan-cache-registry.sar/infinispan-config.xml

      is as below...

       

       

      infinispan-config.xml (portion of which was added)

      <!-- **************** infinispanTest *********************** -->
        <infinispan-config name="infinispanTest" jndi-name="java:CacheManager/infinispanTest">
            <alias>custom-testinfinispan-cache</alias>
            <infinispan xmlns="urn:infinispan:config:4.2">
              <global>
                <transport clusterName="${jboss.partition.name:DefaultPartition}-TestInfinispan" distributedSyncTimeout="17500">
                  <properties>
                    <property name="stack" value="${jboss.default.jgroups.stack:udp}"/>
                  </properties>
                </transport>
                <globalJmxStatistics enabled="true"/>
                <shutdown hookBehavior="DONT_REGISTER"/>
              </global>
              <default>
                <locking isolationLevel="REPEATABLE_READ" lockAcquisitionTimeout="15000" useLockStriping="false" concurrencyLevel="1000"/>
                <jmxStatistics enabled="true"/>
                <lazyDeserialization enabled="true"/>
                <invocationBatching enabled="true"/>
                <clustering mode="replication">
                  <!-- ISPN-835 workaround, use cluster cache loader in place of state transfer -->
                  <!--stateRetrieval timeout="60000" fetchInMemoryState="true"/-->
                  <async useReplQueue="false"/>
                </clustering>
                <loaders passivation="true">
                  <loader class="org.infinispan.loaders.file.FileCacheStore" fetchPersistentState="true" purgeOnStartup="true">
                    <properties>
                      <property name="location" value="${jboss.server.data.dir}${/}infinispantest"/>
                    </properties>
                  </loader>
                  <loader class="org.infinispan.loaders.cluster.ClusterCacheLoader"/>
                </loaders>
              </default>
              <namedCache name="numbersCache">
                <clustering mode="distribution">
                  <!-- ISPN-835 workaround, use cluster cache loader in place of state transfer -->
                  <!--stateRetrieval timeout="60000" fetchInMemoryState="false"/-->

                  <hash numOwners="2"/>
                  <async useReplQueue="false"/>
                </clustering>
                <loaders passivation="true">
                  <loader class="org.infinispan.loaders.file.FileCacheStore" fetchPersistentState="false" purgeOnStartup="true">
                    <properties>
                      <property name="location" value="${jboss.server.data.dir}${/}infinispantest"/>
                    </properties>
                  </loader>
                  <loader class="org.infinispan.loaders.cluster.ClusterCacheLoader">
                    <properties>
                      <property name="remoteCallTimeout" value="60000"/>
                    </properties>
                  </loader>
                </loaders>
              </namedCache>
            </infinispan>
          </infinispan-config>

      But, am getting Null Pointer Exception while server startup (cache is initialized during startup through web.xml)

       

      Full trace of the error is in the attachment.

        • 1. Re: Infinispan : Getting Null pointer exception
          Sanne Grinovero Master

          The stacktrace seems to point out a NullPointerException in your code, specifically at

          com.tsky.selfcare.cache.InfinispanServlet, line 36

          I don't think I can help you with that, sorry.

          • 2. Re: Infinispan : Getting Null pointer exception
            Vikas V Newbie

            Hi Sanne,

             

            Thanks for your reply.

             

            I am pasting below my code and when it comes across this part of the code

             

            Cache cache=cacheManager.getCache("numbersCache");       // This is 36th line in  my code

             

            its throwing null pointer exception.

             

             

            Code in my servlet

            --------------------------------------package com.tsky.selfcare.cache; 

             

             

             

            public class InfinispanServlet extends HttpServlet{


            @Resource(name = "CacheManager/infinispanTest", mappedName = "java:CacheManager/infinispanTest")
            private EmbeddedCacheManager cacheManager;

             

            public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
              //handleRequest(request, response);
            }

             

            public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
              //handleRequest(request, response);
            }
            public void init(ServletConfig config) throws ServletException {
                try{ 
               super.init(config);
               InfinishpanCache  subscriberCache = InfinishpanCache.getSubscriberCacheInstance();
               Cache cache=cacheManager.getCache("numbersCache");     // This is 36th line in my code

               subscriberCache.setCache(cache);
              }catch(Exception e){
               e.printStackTrace();
              }
               }
            public void setCacheManager(EmbeddedCacheManager cacheManager){
                                 this.cacheManager = cacheManager;
              System.out.println("cacheManager :: "+cacheManager);
            }
            }

             

             

            Code in InfinishpanCache  Class

            .....................................................

             

            public class InfinishpanCache {

               
              private static InfinishpanCache singleInstance;

              private static Cache cache;

               public static InfinishpanCache getSubscriberCacheInstance() {
                 try {
                if (singleInstance == null) {
                     singleInstance = new InfinishpanCache();
                }
               }
               catch(Exception e) {
                e.printStackTrace();
               }
                 return singleInstance;
              }

              public void setCache(Cache cache)
              {
               this.cache=cache;
              }
              public static Cache getInfinispaCache() {
               return cache;
              }

             

            Let me know if you want to know furthur details..

             

            Thanks in advance !

             

            Regards,

             

            Vikas

            • 3. Re: Infinispan : Getting Null pointer exception
              Pete Muir Master

              The resource injection of the cache manager is failing.

               

              How did you upgrade the server to use Infinispan 5.1?

              • 4. Re: Infinispan : Getting Null pointer exception
                Vikas V Newbie

                Hi Pete,

                 

                Sorry for delay in response.

                 

                BTW, Null pointer exception has been resolved after below code was added.

                 

                private EmbeddedCacheManager cacheManager=new DefaultCacheManager();


                Now I am getting the cache and its sharing across the portlets also, but I am getting the below exception during server start up.

                 

                Am using Jboss AS 6.0, Infinispan 5.0.0

                 

                DEPLOYMENTS MISSING DEPENDENCIES:
                  Deployment "CacheContainerFactory" is missing the following dependencies:
                    Dependency "JChannelFactory" (should be in state "Installed", but is actually in state "** NOT FOUND Depends on 'JChannelFactory' **")
                  Deployment "CacheContainerRegistry" is missing the following dependencies:
                    Dependency "CacheContainerFactory" (should be in state "Installed", but is actually in state "Described")

                DEPLOYMENTS IN ERROR:
                  Deployment "JChannelFactory" is in error due to the following reason(s): ** NOT FOUND Depends on 'JChannelFactory' **

                        at org.jboss.deployers.plugins.deployers.DeployersImpl.checkComplete(DeployersImpl.java:1228) [:2.2.0.GA]
                        at org.jboss.deployers.plugins.main.MainDeployerImpl.checkComplete(MainDeployerImpl.java:905) [:2.2.0.GA]
                        at org.jboss.system.server.profileservice.deployers.MainDeployerPlugin.checkComplete(MainDeployerPlugin.java:87) [:6.0.0.Final]
                        at org.jboss.profileservice.deployment.ProfileDeployerPluginRegistry.checkAllComplete(ProfileDeployerPluginRegistry.java:107) [:0.2.2]
                        at org.jboss.system.server.profileservice.bootstrap.BasicProfileServiceBootstrap.start(BasicProfileServiceBootstrap.java:135) [:6.0.0.Final]
                        at org.jboss.system.server.profileservice.bootstrap.BasicProfileServiceBootstrap.start(BasicProfileServiceBootstrap.java:56) [:6.0.0.Final]
                        at org.jboss.bootstrap.impl.base.server.AbstractServer.startBootstraps(AbstractServer.java:827) [jboss-bootstrap-impl-base.jar:2.1.0-alpha-5]
                        at org.jboss.bootstrap.impl.base.server.AbstractServer$StartServerTask.run(AbstractServer.java:417) [jboss-bootstrap-impl-base.jar:2.1.0-alpha-5]
                        at java.lang.Thread.run(Thread.java:619) [:1.6.0_21]

                 

                The infinispan-5.0.0 bundled jars are placed under $JBOSS_HOME/server/default/deploy/gatein.ear/lib path

                 

                Infinispan5.0.0 bundled jars which are placed are below.
                ---------------------------------------------------------------------------------
                infinispan-core.jar
                jboss-logging-3.0.0.GA.jar
                jboss-marshalling-1.3.0.GA.jar
                jboss-marshalling-river-1.3.0.GA.jar
                jboss-transaction-api-1.0.1.GA.jar
                jcip-annotations-1.0.jar
                jgroups-2.12.1.1.Final.jar
                org.osgi.core-4.3.0.jar
                rhq-pluginAnnotations-3.0.1.jar

                Also jboss-ha-server-ispn-1.0.0.CR5.jar  for handling NoClassDefFoundError:org.jboss.ha.ispn.DefaultCacheContainerFactory  exception.

                 

                How to resolve DEPLOYMENTS MISSING DEPENDENCIES exception ?

                 

                Regards,

                 

                Vikas