6 Replies Latest reply on Nov 7, 2006 3:06 AM by Ben Wang

    PojoCache 2.0 (replicate method execution)

    Maxime Leur Newbie


      I use PojoCache 2.0 (get on CVS) and JBoss AOP 1.5.2.
      I works great and better than pojocache 1.4.
      But I need help.

      In fact, I want to replicate method execution of an Object stored in the cache.

      My Object named TimerSessionValidity has a method named public void pingSession().

      The behavior is :
      - When I execute this method of an server, I want pojocache to replicate the execution to all others cache.

      It is possible ???

      To do this I put these lines into pojocache-aop.xml

      <!-- Timer Session -->

      new org.jboss.cache.pojo.observable.SubjectImpl(this)

      And I execute aopc with Ant, it generates a class named TimerSessionValidity$pingSession_N3761175341164052267.class

      But It didn't work, the TimerSessionValidity Object is replicated but when I call pingSession() it never replicate the method execution to others caches....

      Thanks for any help.


        • 1. Re: PojoCache 2.0 (replicate method execution)
          Maxime Leur Newbie

          The code in pojocache-aop.xml is :

          <prepare expr="execution(public void com.gltrade.manager.sessionmanager.TimerSessionValidity->pingSession() )" />
           <introduction class="com.gltrade.manager.sessionmanager.TimerSessionValidity">
           <construction>new org.jboss.cache.pojo.observable.SubjectImpl(this)</construction>

          • 2. Re: PojoCache 2.0 (replicate method execution)
            Ben Wang Master

            What you need is a remote method call instead of simple replication. And this feature is not directly related to PojoCache if I am reading your post correctly. Instead, to do RPC, you can do like:

            CacheSPI s = (CacheSPI)pojoCache.getCache();
            RPCManager m = s.getRPCManager();

            to see how exactly to invoke the callRemoteMethods, you can look into TreeCache implementation.

            • 3. Re: PojoCache 2.0 (replicate method execution)
              Maxime Leur Newbie


              Thanks for your reply...

              But I didn't succeed to do RPC. I execute the code above

              PojoCache cache = PojoCacheFactory.createInstance("cache-config.xml");
               CacheSPI cacheSPI = (CacheSPI)cache.getCache();
               RPCManager rpcManager = cacheSPI.getRPCManager();
               TimerSessionValidity timer = new TimerSessionValidity("maxime","id");
               Method method = timer.getClass().getMethod("pingSession2",new Class[]{String.class});
               cache.attach("timer", timer);
               timer = (TimerSessionValidity)cache.find("timer");
               MethodCall methodCall = MethodCallFactory.create(method,"maxime");
               System.out.println("callRemoteMethods "+methodCall.getMethodId());
               rpcManager.callRemoteMethods(cacheSPI.getMembers(), methodCall,1,false,(long) 1000);

              And I get an Exception :
              java.lang.RuntimeException: failure to marshal argument(s)
              at org.jgroups.blocks.RpcDispatcher.callRemoteMethods(RpcDispatcher.java:174)

              I look at the pojocache & treecache code, and I see that MethodCallFactory call a class named MethodDeclarations which contains all methods names.

              How Can I put my method name in this classes ??
              Or I am not on the good way.. and can you help me please..


              • 4. Re: PojoCache 2.0 (replicate method execution)
                Ben Wang Master

                Oops! Sorry, RPCManager doesn't do what you need to do. As a matter of fact, with JGroups 2.3 multiplexer, you could have created a multiplexer stack and create your own RPCManager and then have both RPCManager and Cache to share the same channel. However, this process is not straightforward for standalone. I will raise an issue to discuss.

                Meanwhile, if don't mind to use separate channel, you can look into org.jboss.cache.rpc.RPCTreeCache. Basically, you can create a separate RPCTreeCache instance (a la TreeCache 1.4 style) and execute your RPC calls there.

                Keep in mind the class is deprecated though.

                • 5. Re: PojoCache 2.0 (replicate method execution)
                  Maxime Leur Newbie


                  Thanks for your response, I tries to create a new RpcTreeCache and call my method... but it doesn't work again with the same exception.

                  XmlConfigurationParser parser = new XmlConfigurationParser();
                   Configuration conf = parser.parseFile( "cache-config.xml" );
                   TimerSessionValidity timer = new TimerSessionValidity("maxime","id");
                   RpcTreeCache rpcCache = new RpcTreeCache();
                   Method method = timer.getClass().getMethod("pingSession2",new Class[]{String.class});
                   rpcCache.registerRPCHandler("timer", timer);
                   rpcCache.callRemoteMethods("timer",rpcCache.getMembers(), method,new Object[]{ "maxime"}, false, false, (long) 1000);

                  Could you give a simple code example of RPC calls ???
                  Because I am lost.

                  Many Thanks

                  • 6. Re: PojoCache 2.0 (replicate method execution)
                    Ben Wang Master

                    Looks like there is no easy way of doing RPC on top of JBC since 1.4. This is the relevant discussion thread there: