All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.infinispan.cdi.event.cache.CacheEntryInvalidatedAdapter Maven / Gradle / Ivy

There is a newer version: 9.1.7.Final
Show newest version
package org.infinispan.cdi.event.cache;

import org.infinispan.Cache;
import org.infinispan.metadata.Metadata;
import org.infinispan.notifications.Listener;
import org.infinispan.notifications.cachelistener.annotation.CacheEntryInvalidated;
import org.infinispan.notifications.cachelistener.event.CacheEntryInvalidatedEvent;
import org.infinispan.transaction.xa.GlobalTransaction;

import javax.enterprise.event.Event;
import javax.enterprise.util.TypeLiteral;

/**
 * Event bridge for {@link org.infinispan.notifications.cachelistener.annotation.CacheEntryInvalidated}.
 *
 * @author Pete Muir
 * @author Sebastian Laskawiec
 * @see org.infinispan.notifications.Listener
 * @see org.infinispan.notifications.cachelistener.annotation.CacheEntryInvalidated
 */
@Listener
public class CacheEntryInvalidatedAdapter extends AbstractAdapter> {

   /**
    * CDI does not allow parametrized type for events (like ). This is why this wrapped needs to be
    * introduced. To ensure type safety, this needs to be linked to parent class (in other words this class can not
    * be static).
    */
   private class CDICacheEntryInvalidatedEvent implements CacheEntryInvalidatedEvent {
      private CacheEntryInvalidatedEvent decoratedEvent;

      private CDICacheEntryInvalidatedEvent(CacheEntryInvalidatedEvent decoratedEvent) {
         this.decoratedEvent = decoratedEvent;
      }

      @Override
      public V getValue() {
         return decoratedEvent.getValue();
      }

      @Override
      public K getKey() {
         return decoratedEvent.getKey();
      }

      @Override
      public Metadata getMetadata() {
         return decoratedEvent.getMetadata();
      }

      @Override
      public GlobalTransaction getGlobalTransaction() {
         return decoratedEvent.getGlobalTransaction();
      }

      @Override
      public boolean isOriginLocal() {
         return decoratedEvent.isOriginLocal();
      }

      @Override
      public Type getType() {
         return decoratedEvent.getType();
      }

      @Override
      public boolean isPre() {
         return decoratedEvent.isPre();
      }

      @Override
      public Cache getCache() {
         return decoratedEvent.getCache();
      }
   }

   public static final CacheEntryInvalidatedEvent EMPTY = new CacheEntryInvalidatedEvent() {

      @Override
      public Type getType() {
         return null;
      }

      @Override
      public Object getKey() {
         return null;
      }

      @Override
      public GlobalTransaction getGlobalTransaction() {
         return null;
      }

      @Override
      public boolean isOriginLocal() {
         return false;
      }

      @Override
      public boolean isPre() {
         return false;
      }

      @Override
      public Cache getCache() {
         return null;
      }

      @Override
      public Object getValue() {
         return null;
      }

      @Override
      public Metadata getMetadata() {
         return null;
      }
   };

   /**
    * Events which will be selected (including generic type information ().
    */
   @SuppressWarnings("serial")
   public static final TypeLiteral> WILDCARD_TYPE = new TypeLiteral>() {
   };

   /**
    * Needed for creating event bridge.
    */
   public CacheEntryInvalidatedAdapter(Event> event) {
      super(event);
   }

   @Override
   @CacheEntryInvalidated
   public void fire(CacheEntryInvalidatedEvent payload) {
      super.fire(new CDICacheEntryInvalidatedEvent(payload));
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy