6 Replies Latest reply on Jun 30, 2009 6:01 AM by Galder Zamarreño

    node.getChild() returning inconsistent results

    Dustin Callaway Newbie

      I am getting very strange results when calling node.getChild() in different ways. For instance, I've populated a local cache (using the JDBC cache loader) with the following node:

      /content/timestamp

      This node has a value in its hashmap named "timestamp" that contains a Long. The tricky thing is that I get different values for this node based on how I retrieve it (see below).

      root.getChild("/content/timestamp") - returns null

      root.getChild("content/timestamp") - returns the time stored in the backing database

      root.getChild(Fqn.fromString("content/timestamp")) - returns the time stored in the in-memory cache

      root.getChild(Fqn.fromString("/content/timestamp")) - returns null

      Any thoughts on why this node varies based on how I retrieve it?

      Thanks!

        • 1. Re: node.getChild() returning inconsistent results
          Galder Zamarreño Master

          getChild() takes the fqn of the child, it's a relative method. Root already provides the first /, so the name of the child is without that first /: content/timestamp

          If u used Cache rather than Node, you'd do the following using the absolute path:

          cache.getNode("/content/timestamp");


          • 2. Re: node.getChild() returning inconsistent results
            Dustin Callaway Newbie

             

            "galder.zamarreno@jboss.com" wrote:
            getChild() takes the fqn of the child, it's a relative method. Root already provides the first /, so the name of the child is without that first /: content/timestamp

            If u used Cache rather than Node, you'd do the following using the absolute path:
            cache.getNode("/content/timestamp");


            Thanks Galder. That makes sense but I'm having trouble reconciling your comments with this code right out of the JBoss Cache Users' Guide:

             // Let's get a hold of the root node.
             Node rootNode = cache.getRoot();
            
             // Remember, JBoss Cache stores data in a tree structure.
             // All nodes in the tree structure are identified by Fqn objects.
             Fqn peterGriffinFqn = Fqn.fromString("/griffin/peter");
            
             // Create a new Node
             Node peterGriffin = rootNode.addChild(peterGriffinFqn);
            


            This code uses an absolute value FQN to retrieve a node directly from the root node (not from cache). Perhaps the Users' Guide is incorrect?

            • 3. Re: node.getChild() returning inconsistent results
              Galder Zamarreño Master

              Hi again, actually, I have to apologise because my previous comment was not entirely correct. getChild() takes only the name of the direct child, so root.getChild("content/timestamp") and root.getChild(Fqn.fromString("content/timestamp")) should be return null as well.

              Only, root.getChild(Fqn.fromString("content")) or root.getChild("content") should not be returning null.

              What JBoss Cache version are you using?

              Wrt addChild(), that format is correct. As mentioned in the javadoc, it will take the fqn of the root and combine it with the one passed to it. It doesn't matter if the fqn is /griffin/peter or griffin/peter, both will work the same way: putting a new node under /griffin/peter.

              • 4. Re: node.getChild() returning inconsistent results
                Dustin Callaway Newbie

                 

                "galder.zamarreno@jboss.com" wrote:
                What JBoss Cache version are you using?


                I'm using version 3.1.0.GA and I seem to be able to retrieve fully qualified nodes from the root node just fine (not just the root node's immediate children). Here is some more sample code from the Users' Guide:

                Map lotsOfData = generateData();
                 cache.put("/a/b/c", lotsOfData);
                 cache.getRoot().getChild("/a").setResident(true);
                 cache.getRoot().getChild("/a/b").setResident(true);
                


                This seems to suggest that you can ask the root node for descendents beyond its immediate children. However, I haven't been able to get that to work if I include the beginning slash. Regardless, would I be better off using this:

                cache.getChild(Fqn.fromString("/a/b"))


                Rather than this?

                cache.getRoot().getChild(Fqn.fromString("a/b"))


                • 5. Re: node.getChild() returning inconsistent results
                  Galder Zamarreño Master

                  Hi again, I think I have replicated the issue that you're encountering with the code from the UserGuide. I'm currently investigating it.

                  With regards to your 2nd questions, Cache has no getChild() method, I suppose you're refering to getNode() instead? If so, this is indentical to calling cache.getRoot().getChild(fqn). There's no difference between them two.