12 Replies Latest reply on Jun 18, 2009 10:58 AM by Guillaume Soing

    Bind cache with jndi

    Guillaume Soing Newbie

      Hi All,

      I'm trying to use jboss cache 3.0.3 and I want to bind it to the JNDI. For the moment I have the following exception :

      21:44:12,839 INFO [ComponentRegistry] JBoss Cache version: JBossCache 'Naga' 3.
      0.2.GA
      21:44:12,917 ERROR [STDERR] javax.naming.CommunicationException [Root exception
      is java.io.NotSerializableException: org.jboss.cache.invocation.CacheInvocationD
      elegate]
      21:44:12,917 ERROR [STDERR] at org.jnp.interfaces.NamingContext.bind(NamingC
      ontext.java:673)
      21:44:12,917 ERROR [STDERR] at org.jnp.interfaces.NamingContext.bind(NamingC
      ontext.java:607)
      21:44:12,917 ERROR [STDERR] at javax.naming.InitialContext.bind(InitialConte
      xt.java:400)
      21:44:12,917 ERROR [STDERR] at com.capgemini.test.InitServlet.init(InitServl
      et.java:70)
      21:44:12,917 ERROR [STDERR] at javax.servlet.GenericServlet.init(GenericServ
      let.java:212)
      21:44:12,917 ERROR [STDERR] at org.apache.catalina.core.StandardWrapper.load
      Servlet(StandardWrapper.java:1048)
      21:44:12,917 ERROR [STDERR] at org.apache.catalina.core.StandardWrapper.load
      (StandardWrapper.java:950)
      21:44:12,917 ERROR [STDERR] at org.apache.catalina.core.StandardContext.load
      OnStartup(StandardContext.java:4122)
      21:44:12,917 ERROR [STDERR] at org.apache.catalina.core.StandardContext.star
      t(StandardContext.java:4421)
      21:44:12,917 ERROR [STDERR] at org.jboss.web.tomcat.service.deployers.Tomcat
      Deployment.performDeployInternal(TomcatDeployment.java:312)
      21:44:12,917 ERROR [STDERR] at org.jboss.web.tomcat.service.deployers.Tomcat
      Deployment.performDeploy(TomcatDeployment.java:144)
      21:44:12,917 ERROR [STDERR] at org.jboss.web.deployers.AbstractWarDeployment
      .start(AbstractWarDeployment.java:461)
      21:44:12,917 ERROR [STDERR] at org.jboss.web.deployers.WebModule.startModule
      (WebModule.java:118)
      21:44:12,917 ERROR [STDERR] at org.jboss.web.deployers.WebModule.start(WebMo
      dule.java:97)
      21:44:12,917 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(
      Native Method)
      21:44:12,917 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(N
      ativeMethodAccessorImpl.java:39)
      21:44:12,917 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invo
      ke(DelegatingMethodAccessorImpl.java:25)
      21:44:12,917 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:5
      97)
      21:44:12,917 ERROR [STDERR] at org.jboss.mx.interceptor.ReflectedDispatcher.
      invoke(ReflectedDispatcher.java:157)
      21:44:12,917 ERROR [STDERR] at org.jboss.mx.server.Invocation.dispatch(Invoc
      ation.java:96)
      21:44:12,917 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocat
      ion.java:88)
      21:44:12,917 ERROR [STDERR] at org.jboss.mx.server.AbstractMBeanInvoker.invo
      ke(AbstractMBeanInvoker.java:264)
      21:44:12,917 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MB
      eanServerImpl.java:668)
      21:44:12,917 ERROR [STDERR] at org.jboss.system.microcontainer.ServiceProxy.
      invoke(ServiceProxy.java:206)
      21:44:12,917 ERROR [STDERR] at $Proxy36.start(Unknown Source)
      21:44:12,917 ERROR [STDERR] at org.jboss.system.microcontainer.StartStopLife
      cycleAction.installAction(StartStopLifecycleAction.java:42)
      21:44:12,917 ERROR [STDERR] at org.jboss.system.microcontainer.StartStopLife
      cycleAction.installAction(StartStopLifecycleAction.java:37)
      21:44:12,917 ERROR [STDERR] at org.jboss.dependency.plugins.action.SimpleCon
      trollerContextAction.simpleInstallAction(SimpleControllerContextAction.java:62)
      21:44:12,917 ERROR [STDERR] at org.jboss.dependency.plugins.action.AccessCon
      trollerContextAction.install(AccessControllerContextAction.java:71)
      21:44:12,917 ERROR [STDERR] at org.jboss.dependency.plugins.AbstractControll
      erContextActions.install(AbstractControllerContextActions.java:51)
      21:44:12,917 ERROR [STDERR] at org.jboss.dependency.plugins.AbstractControll
      erContext.install(AbstractControllerContext.java:348)
      21:44:12,917 ERROR [STDERR] at org.jboss.system.microcontainer.ServiceContro
      llerContext.install(ServiceControllerContext.java:286)
      21:44:12,917 ERROR [STDERR] at org.jboss.dependency.plugins.AbstractControll
      er.install(AbstractController.java:1598)
      21:44:12,917 ERROR [STDERR] at org.jboss.dependency.plugins.AbstractControll
      er.incrementState(AbstractController.java:934)
      21:44:12,917 ERROR [STDERR] at org.jboss.dependency.plugins.AbstractControll
      er.resolveContexts(AbstractController.java:1062)
      21:44:12,917 ERROR [STDERR] at org.jboss.dependency.plugins.AbstractControll
      er.resolveContexts(AbstractController.java:984)
      21:44:12,917 ERROR [STDERR] at org.jboss.dependency.plugins.AbstractControll
      er.change(AbstractController.java:822)
      21:44:12,917 ERROR [STDERR] at org.jboss.dependency.plugins.AbstractControll
      er.change(AbstractController.java:553)
      21:44:12,917 ERROR [STDERR] at org.jboss.system.ServiceController.doChange(S
      erviceController.java:688)
      21:44:12,917 ERROR [STDERR] at org.jboss.system.ServiceController.start(Serv
      iceController.java:460)
      21:44:12,917 ERROR [STDERR] at org.jboss.system.deployers.ServiceDeployer.st
      art(ServiceDeployer.java:163)
      21:44:12,917 ERROR [STDERR] at org.jboss.system.deployers.ServiceDeployer.de
      ploy(ServiceDeployer.java:99)
      21:44:12,917 ERROR [STDERR] at org.jboss.system.deployers.ServiceDeployer.de
      ploy(ServiceDeployer.java:46)
      21:44:12,917 ERROR [STDERR] at org.jboss.deployers.spi.deployer.helpers.Abst
      ractSimpleRealDeployer.internalDeploy(AbstractSimpleRealDeployer.java:62)
      21:44:12,917 ERROR [STDERR] at org.jboss.deployers.spi.deployer.helpers.Abst
      ractRealDeployer.deploy(AbstractRealDeployer.java:50)
      21:44:12,917 ERROR [STDERR] at org.jboss.deployers.plugins.deployers.Deploye
      rWrapper.deploy(DeployerWrapper.java:171)
      21:44:12,917 ERROR [STDERR] at org.jboss.deployers.plugins.deployers.Deploye
      rsImpl.doDeploy(DeployersImpl.java:1439)
      21:44:12,917 ERROR [STDERR] at org.jboss.deployers.plugins.deployers.Deploye
      rsImpl.doInstallParentFirst(DeployersImpl.java:1157)
      21:44:12,917 ERROR [STDERR] at org.jboss.deployers.plugins.deployers.Deploye
      rsImpl.doInstallParentFirst(DeployersImpl.java:1178)
      21:44:12,917 ERROR [STDERR] at org.jboss.deployers.plugins.deployers.Deploye
      rsImpl.install(DeployersImpl.java:1098)
      21:44:12,917 ERROR [STDERR] at org.jboss.dependency.plugins.AbstractControll
      erContext.install(AbstractControllerContext.java:348)
      21:44:12,917 ERROR [STDERR] at org.jboss.dependency.plugins.AbstractControll
      er.install(AbstractController.java:1598)
      21:44:12,917 ERROR [STDERR] at org.jboss.dependency.plugins.AbstractControll
      er.incrementState(AbstractController.java:934)
      21:44:12,917 ERROR [STDERR] at org.jboss.dependency.plugins.AbstractControll
      er.resolveContexts(AbstractController.java:1062)
      21:44:12,917 ERROR [STDERR] at org.jboss.dependency.plugins.AbstractControll
      er.resolveContexts(AbstractController.java:984)
      21:44:12,917 ERROR [STDERR] at org.jboss.dependency.plugins.AbstractControll
      er.change(AbstractController.java:822)
      21:44:12,917 ERROR [STDERR] at org.jboss.dependency.plugins.AbstractControll
      er.change(AbstractController.java:553)
      21:44:12,917 ERROR [STDERR] at org.jboss.deployers.plugins.deployers.Deploye
      rsImpl.process(DeployersImpl.java:781)
      21:44:12,917 ERROR [STDERR] at org.jboss.deployers.plugins.main.MainDeployer
      Impl.process(MainDeployerImpl.java:698)
      21:44:12,917 ERROR [STDERR] at org.jboss.system.server.profileservice.hotdep
      loy.HDScanner.scan(HDScanner.java:290)
      21:44:12,917 ERROR [STDERR] at org.jboss.system.server.profileservice.hotdep
      loy.HDScanner.run(HDScanner.java:221)
      21:44:12,917 ERROR [STDERR] at java.util.concurrent.Executors$RunnableAdapte
      r.call(Executors.java:441)
      21:44:12,917 ERROR [STDERR] at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
      21:44:12,917 ERROR [STDERR] at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
      21:44:12,917 ERROR [STDERR] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)
      21:44:12,917 ERROR [STDERR] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:181)
      21:44:12,917 ERROR [STDERR] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:205)
      21:44:12,917 ERROR [STDERR] at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
      21:44:12,917 ERROR [STDERR] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
      21:44:12,917 ERROR [STDERR] at java.lang.Thread.run(Thread.java:619)
      21:44:12,917 ERROR [STDERR] Caused by: java.io.NotSerializableException: org.jboss.cache.invocation.CacheInvocationDelegate
      21:44:12,917 ERROR [STDERR] at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1156)
      21:44:12,917 ERROR [STDERR] at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326)
      21:44:12,917 ERROR [STDERR] at java.rmi.MarshalledObject.<init>(MarshalledObject.java:101)
      21:44:12,917 ERROR [STDERR] at org.jnp.interfaces.MarshalledValuePair.<init>(MarshalledValuePair.java:65)
      21:44:12,933 ERROR [STDERR] at org.jnp.interfaces.NamingContext.createMarsha
      lledValuePair(NamingContext.java:1393)
      21:44:12,933 ERROR [STDERR] at org.jnp.interfaces.NamingContext.bind(NamingContext.java:636)
      21:44:12,933 ERROR [STDERR] ... 69 more
      


      So my question is : is it possible to bind the cache to the jndi. If it not the case, how can i share it between several webapps or application.

      Regards
      --
      Guillaume

        • 1. Re: Bind cache with jndi
          Guillaume Soing Newbie

          Sorry I forgot to precise that I use Jboss 5.0.1 and Jdk1.5.

          Thanks
          --
          Guillaume

          • 2. Re: Bind cache with jndi
            Manik Surtani Master

            Are you binding this to a HA-JNDI instance? There would be little value in that... you do want to bind to local JNDI.

            • 3. Re: Bind cache with jndi
              Mircea Markus Master

               

              So my question is : is it possible to bind the cache to the jndi. If it not the case, how can i share it between several webapps or application.

              If you're using the cache in replicated mode, the way to do it is by creating a replicated cache instance in each JVM that needs to access shared state, each such instance pointing to same jgrousp channel. If you're using the cache in LOCAL mode, one way to do it is by using a central CacheLoader (e.g. FileCacheLoader or JdbcCacheLoader), and all caches to share access to it. Though, making a LOCAL cache bindable to JNDI *might* not be a bad idea, as this is a common practice to share objects between applications - opinions?

              • 4. Re: Bind cache with jndi
                Manik Surtani Master

                @Mircea - you should be able to bind to JNDI. This is useful not only for local mode, but even clustered modes where you want to share 1 cache instance across several webapps/enterprise apps in the same container.

                @gsoing - however, there is no point in putting the cache in a HA-JNDI server since that will attempt to replicate its contents across a cluster. That is unnecessary since each cluster node should have its own (clustered) cache instance in its own local JNDI.

                • 5. Re: Bind cache with jndi
                  Mircea Markus Master

                   

                  @Mircea - you should be able to bind to JNDI. This is useful not only for local mode, but even clustered modes where you want to share 1 cache instance across several webapps/enterprise apps in the same container.

                  You can't put it in JNDI as the CacheInvocationDelegate is not serializable(see stack trace from original post);
                  re:putting clustered caches in JNDI, that's a bit more tricky: between JNDI serailization and deserialization the cache might miss replication events and be in a inconsistent state. On the other hand what's the point of putting a replicated cache in JNDI because you can create an handler to it from any JVM you want to. Perhaps serializing+unserializing is more efficient than creating a new handler, but again there's the advantage of not loosing replication events.

                  • 6. Re: Bind cache with jndi
                    Manik Surtani Master

                    That stack trace should only be for HA-JNDI. Local JNDI should not try and serialize anything (unless I am mistaken).

                    Re: clustered caches, there should be no issue with serialization/deserialization as JNDI should not require this.

                    • 7. Re: Bind cache with jndi
                      Guillaume Soing Newbie

                      Hi,

                      I want my cache shared between several application on the same jboss. And I need this cache to be replicate between different JVM.

                      @manik I do not use HAJNDI but local JNDI and I still have the NotSerializableException, I think the two service have the same interface for compatibility purpose.


                      On the other hand what's the point of putting a replicated cache in JNDI because you can create an handler to it from any JVM you want to. Perhaps serializing+unserializing is more efficient than creating a new handler, but again there's the advantage of not loosing replication events.


                      I don't see what you mean by handler.

                      Thanks for you comments
                      --
                      Guillaume

                      • 8. Re: Bind cache with jndi
                        Mircea Markus Master

                         

                        I don't see what you mean by handler.

                        a org.jboss.cache.Cache instance.

                        • 9. Re: Bind cache with jndi
                          Guillaume Soing Newbie

                          For the moment I have find a solution ... I use a wrapper for my cache which is Serializable with the cache as transiant attribute.

                          I know it's not the best solution, if anyone has a better idea, he will be welcome.

                          Regards
                          --
                          Guillaume

                          • 10. Re: Bind cache with jndi
                            Galder Zamarreño Master

                            Guillaume, we've been discussing best practices for sharing Cache instances between apps and currently, the best way to do so from AS is explained in http://tinyurl.com/lq688t, section 11.2. Paraphrasing Brian Stansberry, the AS Clustering Lead:

                            1) Use the CacheManager to create your cache; the CacheManager is available in JNDI at java:/CacheManager. See Section 11.2.1.

                            2) Use CacheJmxWrapperMBean and it's "cache" mbean attribute. Simplest way is to deploy it via a -service.xml. Section 5.4.2 of JBC 3.1 docs at http://tinyurl.com/m49qen has other methods.


                            Either of those two methods should allow you to access a single Cache instance from any apps deployed in AS. This is recommended instead of your temporary solution. If you go over to the cluster dev list, you'll find a more detailed explanation from Brian himself.

                            • 12. Re: Bind cache with jndi
                              Guillaume Soing Newbie

                              Thanks a lot for the information !! It works fine !

                              Regards
                              --
                              Guillaume