[jboss-user] [JBoss Cache: Core Edition] - Listener gets events twice 2.2.0.CR7

mbrade do-not-reply at jboss.com
Wed Aug 20 03:14:07 EDT 2008


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:
anonymous wrote : 
  | 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


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4171425#4171425

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4171425



More information about the jboss-user mailing list