1 Reply Latest reply on Aug 20, 2008 5:12 AM by Mircea Markus

    Listener gets events twice 2.2.0.CR7

    Marco Brade Newbie

      Hello

      I'm using JBossCache 2.2.0.CR7 with one CacheListener on the Cache. The cache runs fine but my problem is that I get all events twice.

      What I do is:

       Cache cache = ...get the Cache from Spring Context...
       cache.addCacheListener( new KeyEvictionListener() );
       cache.create();
       cache.start();
      


      My CacheListener:
      import org.jboss.cache.notifications.annotation.CacheListener;
      import org.jboss.cache.notifications.annotation.NodeActivated;
      import org.jboss.cache.notifications.annotation.NodeCreated;
      import org.jboss.cache.notifications.annotation.NodeEvicted;
      import org.jboss.cache.notifications.annotation.NodeLoaded;
      import org.jboss.cache.notifications.annotation.NodeMoved;
      import org.jboss.cache.notifications.annotation.NodePassivated;
      import org.jboss.cache.notifications.annotation.NodeRemoved;
      import org.jboss.cache.notifications.event.Event;
      import org.jboss.cache.notifications.event.NodeCreatedEvent;
      import org.jboss.cache.notifications.event.NodeEvictedEvent;
      import org.jboss.cache.notifications.event.NodeRemovedEvent;
      
      @CacheListener
      public class KeyEvictionListener {
      
       @NodeRemoved
       @NodeEvicted
       @NodePassivated
       @NodeCreated
       @NodeMoved
       @NodeActivated
       @NodeLoaded
       public void handleEvent(Event cacheEvent){
       System.out.println("got event: "+cacheEvent.getType().name());
       switch( cacheEvent.getType() ){
       case NODE_REMOVED : {
       NodeRemovedEvent nodeRemovedEvent = (NodeRemovedEvent)cacheEvent;
       System.out.println( nodeRemovedEvent.getFqn() );
       System.out.println( nodeRemovedEvent.getData().toString() );
       break;
       }
       case NODE_EVICTED : {
       NodeEvictedEvent nodeEvictedEvent = (NodeEvictedEvent) cacheEvent;
       System.out.println( nodeEvictedEvent.getFqn() );
       break;
       }
       case NODE_CREATED : {
       NodeCreatedEvent nodeCreatedEvent = (NodeCreatedEvent) cacheEvent;
       System.out.println( nodeCreatedEvent.getFqn() );
       }
       }
       }
      
      }
      


      I'm using two regions one with an EvictionPolicy and one which contains resident Nodes only.

      If I run some TestCode i get the following output:

      got event: NODE_CREATED
      /mc
      got event: NODE_CREATED
      /mc
      got event: NODE_CREATED
      /mc/entries
      got event: NODE_CREATED
      /mc/entries
      got event: NODE_CREATED
      /mc/entries/5f8d866c3800d096698dc48b549e4dd3
      got event: NODE_CREATED
      /mc/entries/5f8d866c3800d096698dc48b549e4dd3
      got event: NODE_CREATED
      /mc/keys
      got event: NODE_CREATED
      /mc/keys
      got event: NODE_CREATED
      /mc/keys/5f8d866c3800d096698dc48b549e4dd3
      got event: NODE_CREATED
      /mc/keys/5f8d866c3800d096698dc48b549e4dd3
      got event: NODE_CREATED
      /mc/entries/5755b475601346aa24776baa12da9dfe
      got event: NODE_CREATED
      /mc/entries/5755b475601346aa24776baa12da9dfe
      got event: NODE_CREATED
      /mc/keys/5755b475601346aa24776baa12da9dfe
      got event: NODE_CREATED
      /mc/keys/5755b475601346aa24776baa12da9dfe
      got event: NODE_EVICTED
      /mc/keys/5f8d866c3800d096698dc48b549e4dd3
      got event: NODE_EVICTED
      /mc/keys/5f8d866c3800d096698dc48b549e4dd3
      got event: NODE_EVICTED
      /mc/keys/5755b475601346aa24776baa12da9dfe
      got event: NODE_EVICTED
      /mc/keys/5755b475601346aa24776baa12da9dfe

      As you can see all Events come twice for the same Fqn.
      Is it a bug or am I doing somthing wrong?

      thanks for the help
      Marco