9 Replies Latest reply on Jun 15, 2005 10:39 PM by ben.wang

    HashMap get method - invocation time

    Yossi Dantes Newbie

      I'm using replicated cache and I noticed that if I put HashMap in the TreeCacheAOP and then invoke the get method, in each get invocation the callRemoteMethods is called.
      I can't understand why in "get" operation there is a call to the network why isn't it just return the object from the local cache...?



        • 1. Re: HashMap get method - invocation time
          Bela Ban Master

          This is almost certainly a bug, can you create a JIRA bug report ?

          • 2. Re: HashMap get method - invocation time

            Do you mean each getObject() call? If it is, then I have created a Jira issue for that.

            But pojo.getxxx() should not trigger a network call though.

            Can you elbaorate?


            • 3. Re: HashMap get method - invocation time
              Yossi Dantes Newbie

              Because CachedMapInterceptor get method calls to cache.getObject... yes I ment each getObject call...

              you right pojo.getxxx is not trigger a network call.



              • 4. Re: HashMap get method - invocation time
                Yossi Dantes Newbie


                I'm a programmer from the same group, and I would like to elaborate more, as this is a pressing issue for us. So I'm sorry in advance for the length of the response ( - :

                We currently are using a system that has an implementation
                of a cache that uses several static hashmaps in order to manage all in-memory static objects. We're trying to use jbosscache (AOP) behind the scenes to make the move to a distributed application. We chose jbosscache because it offers (or at least claims to offer) a way to work with distributed applications with very little added code.

                The idea was to put all our hashmaps on an instance of treecacheAOP,
                and to let the cacheMapInterceptor (and of course all aspectized sub POJOs) do all the distributed work behind the scenes. Our module includes a load which consists of non-frequent put actions, but a very heavy load of get actions.

                We joined two servers as a cluster and ran the following test: Server number 1 performed a put of a hashmap on the cache once in the initialization stage of the server. It also ran a thread that changed a member of the map every 30 seconds (just to add some noise). Server 2 did map = cahce.cache.getObject on its initialization routine and then performed a map.get(object) on each transaction.

                After debugging the code we learned that the MapInterceptor.get calls getObject which goes to the network each time. As we need to perform for each user transaction several get operations on diffrent hash maps, this is not acceptable.

                The question is: why does getObject goes to the network each time?
                And, if this is a bug, what can we do? (A side from dropping jbosscache). We thought about creating our own implementation of a cached map, which holds all aspectized pojos localy, and performs getObject only if the local key does not exist. But then we will have to deal with the removal of objects from the cache (Unless the POJO reference itself will become null?).

                Any suggestions (Please)?

                • 5. Re: HashMap get method - invocation time

                  Two options:

                  1. I don't quite understand why do you need to do getObject all the time? Once you get the pojo reference, you should not bother with getObject again.

                  2. If you are willing to try out development release, I can fix and check it in.


                  • 6. Re: HashMap get method - invocation time
                    Yossi Dantes Newbie

                    Please keep in mind that what we PUT in the cahce is a HashMap and we hold the reference to it (activate the GET method) in the system startup as a static memeber.

                    Here is the code we are using:

                    private static HashMap map;
                    private static final Fqn fqn = new Fqn("OGCache");
                    public static void init()
                    try {
                    TreeCacheAop cache = new TreeCacheAop();
                    PropertyConfigurator config = new PropertyConfigurator();
                    config.configure(cache, "replSync-service.xml");
                    //if the cache is empty --> init it
                    if ( cache.getObject(fqn) == null){
                    cache.putObject(fqn, new HashMap());
                    map = (HashMap)cache.getObject(fqn);
                    catch (Exception e) {
                    Debugger.error("error while init cache: " ,e);
                    public static HashMap getCache(){ return map; }

                    The init() method is called once just when the servers starts and then we have a reference to the proxy HashMap class.

                    Now, the question is... why when we activate the getCache().get(id) method there is a network trigger? Can we prevent it from going to the network? how?



                    • 7. Re: HashMap get method - invocation time
                      good chiller Newbie


                      Which version do you use?
                      I got the problem that objects of type 'Map' and 'List' would not became replicated to new nodes if I start the nodes after the insertion of the objects...
                      other way around it works fine!?

                      Did you ever get an "NotSerializeableException: CachedMapInterceptor" when you've worked with TreeCacheAop?

                      • 8. Re: HashMap get method - invocation time
                        Yoav Sivan Newbie



                        I'm working with Yosi (yos_titi), and we kind of
                        being going around this subject for a while now. So just to explain
                        again: We want use several static maps to hold all our
                        cached data (We use them now locally). We thought that we could put the maps on the jbosscache at server startup time (See the code published above by Yosi), and then handle the maps as usual, allowing the mapinterceptor to do all the dirty work (handling changes among all nodes). The static maps will be reused across all transactions, where map.get() will be invoked several times for each user transaction (heavy loads are expected) and map.put/remove will be called much less frequently.

                        Ben - thanks for the replies. To make things clear, We don't need specifically cache.getObject() for each transaction. We just call map.get() several times on several maps for each transaction (as we are trying to use the distributed map as we would regular maps), and we noticed that the mapinterceptor calls cache.getObject(), which invokes network calls.

                        The basic question is: can't we use collection classes (The new release u suggested / Implementing our own map) that do not go to the network on each object get, but rather maintain for each proxy class it's correct state locally (as well as being aware that a proxy object has been removed from the map in antoher node).

                        Are we missing something?



                        • 9. Re: HashMap get method - invocation time

                          I don't understand why getCache().get(id) will trigger the network traffic, since you are only doing getObject once in init().

                          Can you create a Junit test case for me so I can take a look at the problem? Please send it to ben.wang at jboss.com.

                          And maybe I will need to fix this in 1.2.4alpha so you can try it out.