1 Reply Latest reply on Sep 18, 2008 10:23 AM by manik

    NEED HELP : JBoss Cache Iterator

    seal_sum

      Hi,

      I am a newcomer in JBoss world and have very little knowledge about JBoss Cache. I am having an Java application that uses JBoss cache (JBoss 4.2.0.GA) to store some information. The application creates different nodes (having different names) inside the cache for keeping different information.

      It is implemented like this way,
      MBeanServer server = MBeanServerLocator.locateJBoss();
      TreeCacheMBean myCache = (TreeCacheMBean) MBeanProxyExt.create(TreeCacheMBean.class, , server);

      String node1 = + "1";
      String node2 = + "2";
      String node3 = + "3";

      myCache.put(node1, <Key1>, <Value1>);
      myCache.put(node2, <Key2>, <Value2>);
      myCache.put(node3, <Key3>, <Value3>);

      Now my question is, do JBoss Cache provides anything like iterator by which I can iterate these nodes inside the cache. Please note that, there may run another thread that will remove one or more of these nodes from the cache. So at the time of iteration my application does not know how many nodes present at that time.

      If there is something like iterator JBoss cache provides, how can I use that and what jar files do I need for that. If such an iterator is not there in JBoss cache, what is the normal practise to implement an iterator like functionality ?

      I need this very urgent. Please help me out regarding this ASAP.

      Thanks,
      Sumanta

        • 1. Re: NEED HELP : JBoss Cache Iterator
          manik

          If you want to iterate over nodes, you can walk the tree. Remember that JBC uses a tree structure.

          
          void doStuff()
          {
           doStuffWithNode(cache.getRoot());
          }
          
          void doStuffWithNode(Node n)
          {
           processNode( n );
           Set<Node> children = n.getChildren();
           for (Node child: children) doStuffWithNode( child );
          }