1 Reply Latest reply on Feb 22, 2007 11:44 AM by Manik Surtani

    Listener receives both a nodeCreated AND nodeModified for ne

    James McClure Newbie

      Using JBoss AS 4.0.5GA, JBoss Cache 1.4.1 SP1, Java 1.5.0_10, WinXP Pro

      Hi,

      I have created a tree cache instance in which I am adding a node via the method put(fqn, key, value). From the documentation, if that node does not exist, which is the situation in my test, a nodeCreated notification will be emitted. However, this is not the case. My listener receives both a nodeCreated AND nodeModified notification for that single action.

      My listener extends the abstract listener and overrides a couple of methods:

      public class CacheListener extends AbstractTreeCacheListener
      {
       public CacheListener()
       {
       System.err.println("listener created");
       }
      
       @Override
       public void nodeCreated(Fqn fqn)
       {
       System.err.println("node created");
       }
      
       @Override
       public void nodeModified(Fqn fqn)
       {
       System.err.println("node modified");
       }
      }


      My main class creates the cache instance, reigisters the listener and creates a node with data:
      public static void main(String[] args)
       {
       try
       {
       System.err.println("starting test");
       TreeCache tree = new TreeCache();
       CacheListener listener = new CacheListener();
       tree.addTreeCacheListener(listener);
      
       tree.setClusterName("test");
       tree.setClusterProperties("default.xml");
       tree.setCacheMode(TreeCache.LOCAL);
       tree.createService();
       tree.startService();
       tree.put("/a", "name", "James");
       tree.stopService();
       tree.destroyService();
       System.err.println("end of test");
       }
       catch(Exception ex)
       {
       System.err.println("Got an exception: " + ex.getMessage());
       }
       }


      The output is as follows:
      starting test
      listener created
      node created
      node modified
      end of test


      Is this the expected behavior with incorrect documentation? Or am I not utilizing the API properly? Any pointers are appreciated.

      Thanks.
      James