1 Reply Latest reply on Mar 15, 2011 6:46 AM by Mircea Markus

    Cache modified event listener impl

    James Cameron Newbie

      Hi,

       

      EventImpl is of type CacheEntryModifiedEvent but why does an exception occur when it is used

      as the single parameter? It seems the parameter has to be a super type of CacheEntryModifiedEvent which

      contradicts Java (if a method accepts type A as its parameter, it will also accept any subtype of A as its paramer). Does

      anyone clarify it? Thanks.

       

      E.g. following definition throws

      org.infinispan.notifications.IncorrectListenerException: Methods annotated with org.infinispan.notifications.cachelistener.annotation.CacheEntryModified must accept exactly

      one parameter, of assignable from type org.infinispan.notifications.cachelistener.event.CacheEntryModifiedEvent

       

      @Listener(sync=false)

      public class CacheListener {

       

          @CacheEntryModified

          public void modified(EventImpl event) {

              System.out.println(">>: cache modified: " + event.isPre() + ":" + event.getKey() + "," + event.getValue());

          }

       

      }

       

      The reason I supply EventImpl as the parameter is that I want to override Event.isPre() method. Thanks.

        • 1. Cache modified event listener impl
          Mircea Markus Master

          EventImpl is of type CacheEntryModifiedEvent but why does an exception occur when it is used

          as the single parameter? It seems the parameter has to be a super type of CacheEntryModifiedEvent which

          contradicts Java (if a method accepts type A as its parameter, it will also accept any subtype of A as its paramer). Does

          anyone clarify it? Thanks.

          Using EventImpl as a method param is not something to encourage. This is an internal structure and we don't want to expose it. 

          What functionality do you miss from event API? Perhaps we can add something to one of the Event objects?

           

          The reason I supply EventImpl as the parameter is that I want to override Event.isPre() method. Thanks.

          Not sure I get this: you would need to create the EventImpl extenssions yourself then, but they are created internally by ISPN. Can you detail your use case?