7 Replies Latest reply on Nov 17, 2005 7:03 PM by ben.wang

    JBossCacheAOP synchronization of local variables

    mikeg123

      Hello,
      I'm using JBossCacheAOP with JBoss 3.2.6

      I have defined the following maps in my class

      private Map localSessionMap = new HashMap ();
      private Map proxySessionMap;

      then I added the "localSessionMap" to the cache and retrieve the proxy referene:

      treeCache = new TreeCacheAop();
      PropertyConfigurator config = new PropertyConfigurator();
      config.configure(treeCache, "META-INF/nmsSync-service.xml");

      treeCache.start(); // kick start the cache
      treeCache.putObject(cacheNodeName, this.localSessionMap);

      //get a proxied map
      proxySessionMap= (HashMap)treeCache.getObject(cacheNodeName);

      now when I try to add something to the proxy map "proxySessionMap"
      proxySessionMap.put(sessionId, sessDO);

      it adds the to the cache, but localSessionMap state is not synchronized
      Please help.

        • 1. Re: JBossCacheAOP synchronization of local variables

          1. Have you got JBoss Aop to work under 3.2.6?

          2. What version of JBossCache you are using?

          -Ben

          • 2. Re: JBossCacheAOP synchronization of local variables
            mikeg123

            Hi,
            yes, AOP works fine for other stuff under 3.2.6
            jboss-aop_1.1.2
            JBossCache-1.2.4

            but in my case I'm not defining anything in jboss-aop.xml for the caching stuff because I'm adding Map directly to the cache (see previous post)



            • 3. Re: JBossCacheAOP synchronization of local variables

              OK, by using the proxy, we are not updating the original reference now. So my question is: can you just simply replace localSessionMap with proxySessionMap?

              Otherwise, we will need to open a Jira issue that needs to be fixed in the next release.

              -Ben

              • 4. Re: JBossCacheAOP synchronization of local variables
                mikeg123

                Hello,
                I actually do use proxy for most of the operation, except in some cases I have to iterate over the map values and the proxy version is not clonable. of course I could copy values from proxy to local, clone, iterate and then synch again, but it seems a litte counter intuative because as I understand if you put an instance of a class that references a map into cache then I can directly manipulate the map itself and both local and proxy copy would be synched, correct?

                • 5. Re: JBossCacheAOP synchronization of local variables

                  No, because we can't instrument the local version so anything you do on the local version is not intercepted. However, the other way can be true though provided we keep the original reference. But keeping the original reference may not be strightforward. That is, in this case, we will have a local Map, a proxy map, and also indexed value from cache.

                  It can be done but I have to think about it. Here is the Jira:
                  http://jira.jboss.com/jira/browse/JBCACHE-354


                  • 6. Re: JBossCacheAOP synchronization of local variables
                    mikeg123

                    ok, I see.
                    so in the example from TreeCacheAOP guide

                    Person joe = new Person();
                    joe.setName("Joe Black"); // This is base class attributes
                    ArrayList lang = new ArrayList();
                    lang.add("English");
                    lang.add("Mandarin");
                    joe.setLanguages(lang);
                    // This will map the languages List automatically and swap it out
                    with the proxy reference.
                    tree.putObject("/aop/student/joe", joe);
                    ArrayList lang = joe.getLanguages(); // Note that lang is a
                    proxy reference
                    lang.add("French"); // This will be intercepted by the cache


                    local to joe "lang" would not be in synch with the proxy
                    (local would have values: English, Mandaring and
                    proxy would have values: English, Mandaring, French)? (which might be a little wacky)

                    but what about if "setLanguages" method was defined as "prepare"
                    for interception, so if I called something like
                    joe.setLanguages("Spanish"),
                    would it intercept and update the proxy copy as well and not the local?

                    • 7. Re: JBossCacheAOP synchronization of local variables

                      Yes, it would update the proxy copy because TreeCacheAop has swapped out the local copy with the proxy one.

                      -Ben