javax.cache.event.CacheEntryEventFilter Java Examples

The following examples show how to use javax.cache.event.CacheEntryEventFilter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JCSListener.java    From commons-jcs with Apache License 2.0 6 votes vote down vote up
public JCSListener(final CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration)
{
    oldValue = cacheEntryListenerConfiguration.isOldValueRequired();
    synchronous = cacheEntryListenerConfiguration.isSynchronous();

    final Factory<CacheEntryEventFilter<? super K, ? super V>> filterFactory = cacheEntryListenerConfiguration
            .getCacheEntryEventFilterFactory();
    if (filterFactory == null)
    {
        filter = NoFilter.INSTANCE;
    }
    else
    {
        filter = filterFactory.create();
    }

    delegate = cacheEntryListenerConfiguration.getCacheEntryListenerFactory().create();
    remove = CacheEntryRemovedListener.class.isInstance(delegate);
    expire = CacheEntryExpiredListener.class.isInstance(delegate);
    update = CacheEntryUpdatedListener.class.isInstance(delegate);
    create = CacheEntryCreatedListener.class.isInstance(delegate);
}
 
Example #2
Source File: EventDispatcher.java    From caffeine with Apache License 2.0 6 votes vote down vote up
/**
 * Registers a cache entry listener based on the supplied configuration.
 *
 * @param configuration the listener's configuration.
 */
@SuppressWarnings("PMD.CloseResource")
public void register(CacheEntryListenerConfiguration<K, V> configuration) {
  if (configuration.getCacheEntryListenerFactory() == null) {
    return;
  }
  EventTypeAwareListener<K, V> listener = new EventTypeAwareListener<>(
      configuration.getCacheEntryListenerFactory().create());

  CacheEntryEventFilter<K, V> filter = event -> true;
  if (configuration.getCacheEntryEventFilterFactory() != null) {
    filter = new EventTypeFilter<>(listener,
        configuration.getCacheEntryEventFilterFactory().create());
  }

  Registration<K, V> registration = new Registration<>(configuration, filter, listener);
  dispatchQueues.putIfAbsent(registration, CompletableFuture.completedFuture(null));
}
 
Example #3
Source File: TypesafeConfigurator.java    From caffeine with Apache License 2.0 6 votes vote down vote up
/** Adds the entry listeners settings. */
private void addListeners() {
  for (String path : merged.getStringList("listeners")) {
    Config listener = root.getConfig(path);

    Factory<? extends CacheEntryListener<? super K, ? super V>> listenerFactory =
        factoryCreator.factoryOf(listener.getString("class"));
    Factory<? extends CacheEntryEventFilter<? super K, ? super V>> filterFactory = null;
    if (listener.hasPath("filter")) {
      filterFactory = factoryCreator.factoryOf(listener.getString("filter"));
    }
    boolean oldValueRequired = listener.getBoolean("old-value-required");
    boolean synchronous = listener.getBoolean("synchronous");
    configuration.addCacheEntryListenerConfiguration(
        new MutableCacheEntryListenerConfiguration<>(
            listenerFactory, filterFactory, oldValueRequired, synchronous));
  }
}
 
Example #4
Source File: EventListenerAdaptors.java    From ehcache3 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
static <K, V> List<EventListenerAdaptor<K, V>> ehListenersFor(CacheEntryListener<? super K, ? super V> listener,
    CacheEntryEventFilter<? super K, ? super V> filter, Cache<K, V> source, boolean requestsOld) {
  List<EventListenerAdaptor<K, V>> rv = new ArrayList<>();

  if (listener instanceof CacheEntryUpdatedListener) {
    rv.add(new UpdatedAdaptor<>(source, (CacheEntryUpdatedListener<K, V>) listener,
      (CacheEntryEventFilter<K, V>) filter, requestsOld));
  }
  if (listener instanceof CacheEntryCreatedListener) {
    rv.add(new CreatedAdaptor<>(source, (CacheEntryCreatedListener<K, V>) listener,
      (CacheEntryEventFilter<K, V>) filter, requestsOld));
  }
  if (listener instanceof CacheEntryRemovedListener) {
    rv.add(new RemovedAdaptor<>(source, (CacheEntryRemovedListener<K, V>) listener,
      (CacheEntryEventFilter<K, V>) filter, requestsOld));
  }
  if (listener instanceof CacheEntryExpiredListener) {
    rv.add(new ExpiredAdaptor<>(source, (CacheEntryExpiredListener<K, V>) listener,
      (CacheEntryEventFilter<K, V>) filter, requestsOld));
  }

  return rv;
}
 
Example #5
Source File: GridCacheContinuousQueryNodesFilteringTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override public CacheEntryEventFilter<Integer, Integer> create() {
    try {
        Class<?> filterCls = clsLdr.loadClass(ENTRY_FILTER_CLS_NAME);

        assert CacheEntryEventFilter.class.isAssignableFrom(filterCls);

        return ((Class<CacheEntryEventFilter>)filterCls).newInstance();
    }
    catch (ClassNotFoundException e) {
        throw new IgniteException("Class not found for continuous query remote filter [name=" +
            e.getMessage() + "]");
    }
    catch (Exception e) { // We really don't expect anything else fancy here.
        throw new AssertionError("Unexpected exception", e);
    }
}
 
Example #6
Source File: CacheContinuousQueryManager.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param locLsnr Local listener.
 * @param rmtFilter Remote filter.
 * @param rmtFilterFactory Remote filter factory
 * @param bufSize Buffer size.
 * @param timeInterval Time interval.
 * @param autoUnsubscribe Auto unsubscribe flag.
 * @param loc Local flag.
 * @return Continuous routine ID.
 * @throws IgniteCheckedException In case of error.
 */
public UUID executeQuery(@Nullable final CacheEntryUpdatedListener locLsnr,
    @Nullable final EventListener locTransLsnr,
    @Nullable final CacheEntryEventSerializableFilter<K, V> rmtFilter,
    @Nullable final Factory<CacheEntryEventFilter<K, V>> rmtFilterFactory,
    @Nullable final Factory<IgniteClosure<K, V>> rmtTransFactory,
    int bufSize,
    long timeInterval,
    boolean autoUnsubscribe,
    boolean loc,
    final boolean keepBinary,
    final boolean includeExpired) throws IgniteCheckedException
{
    IgniteOutClosure<CacheContinuousQueryHandler> clsr;

    if (rmtTransFactory != null) {
        clsr = new IgniteOutClosure<CacheContinuousQueryHandler>() {
            @Override public CacheContinuousQueryHandler apply() {
                return new CacheContinuousQueryHandlerV3(
                    cctx.name(),
                    TOPIC_CACHE.topic(topicPrefix, cctx.localNodeId(), seq.getAndIncrement()),
                    locTransLsnr,
                    securityAwareFilterFactory(rmtFilterFactory),
                    securityAwareTransformerFactory(rmtTransFactory),
                    true,
                    false,
                    !includeExpired,
                    false);
            }
        };
    }
    else if (rmtFilterFactory != null) {
        clsr = new IgniteOutClosure<CacheContinuousQueryHandler>() {
 
Example #7
Source File: CacheContinuousQueryHandlerV3.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected CacheEntryEventFilter getEventFilter0() {
    if (rmtFilterFactory == null)
        return null;

    return super.getEventFilter0();
}
 
Example #8
Source File: CacheContinuousQueryHandlerV2.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected CacheEntryEventFilter getEventFilter0() {
    if (filter == null) {
        assert rmtFilterFactory != null;

        Factory<? extends CacheEntryEventFilter> factory = rmtFilterFactory;

        filter = factory.create();

        if (types != 0)
            filter = new JCacheQueryRemoteFilter(filter, types);
    }

    return filter;
}
 
Example #9
Source File: CacheContinuousQueryHandlerV2.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor.
 *
 * @param cacheName Cache name.
 * @param topic Topic for ordered messages.
 * @param locLsnr Local listener.
 * @param rmtFilterFactory Remote filter factory.
 * @param oldValRequired Old value required flag.
 * @param sync Synchronous flag.
 * @param ignoreExpired Ignore expired events flag.
 * @param types Event types.
 */
public CacheContinuousQueryHandlerV2(
    String cacheName,
    Object topic,
    @Nullable CacheEntryUpdatedListener<K, V> locLsnr,
    @Nullable Factory<? extends CacheEntryEventFilter<K, V>> rmtFilterFactory,
    boolean oldValRequired,
    boolean sync,
    boolean ignoreExpired,
    boolean ignoreClsNotFound,
    @Nullable Byte types) {
    super(cacheName,
        topic,
        locLsnr,
        null,
        oldValRequired,
        sync,
        ignoreExpired,
        ignoreClsNotFound);
    this.rmtFilterFactory = rmtFilterFactory;

    if (types != null) {
        assert types != 0;

        this.types = types;
    }
}
 
Example #10
Source File: CacheContinuousQueryManager.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param impl Filter.
 * @param types Types.
 */
JCacheQueryRemoteFilter(@Nullable CacheEntryEventFilter impl, byte types) {
    assert types != 0;

    this.impl = impl;
    this.types = types;
}
 
Example #11
Source File: CacheManagerTest.java    From cache2k with Apache License 2.0 5 votes vote down vote up
@Test(expected=UnsupportedOperationException.class)
public void no_online_listener_attachment_with_cache2k_defaults() {
  CachingProvider p = Caching.getCachingProvider();
  CacheManager cm = p.getCacheManager();
  MutableConfiguration cfg = ExtendedMutableConfiguration.of(new Cache2kBuilder<Long, Double>(){});
  Cache cache = cm.createCache("mute",  cfg);
  cache.registerCacheEntryListener(new CacheEntryListenerConfiguration() {
    @Override
    public Factory<CacheEntryListener> getCacheEntryListenerFactory() {
      fail("not expected to be called");
      return null;
    }

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

    @Override
    public Factory<CacheEntryEventFilter> getCacheEntryEventFilterFactory() {
      return null;
    }

    @Override
    public boolean isSynchronous() {
      return false;
    }
  });
  cache.close();
}
 
Example #12
Source File: PlatformContinuousQueryImpl.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the Java filter if present.
 *
 * @param filter Filter object.
 * @param ctx Context.
 * @return Java filter or null.
 */
private static CacheEntryEventFilter getJavaFilter(Object filter, GridKernalContext ctx) {
    if (filter instanceof BinaryObjectImpl) {
        BinaryObjectImpl bo = (BinaryObjectImpl)filter;

        if (bo.typeId() == GridBinaryMarshaller.PLATFORM_JAVA_OBJECT_FACTORY_PROXY) {
            PlatformJavaObjectFactoryProxy prx = bo.deserialize();

            return (CacheEntryEventFilter)prx.factory(ctx).create();
        }
    }

    return null;
}
 
Example #13
Source File: CacheContinuousQueryHandlerV3.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param cacheName Cache name.
 * @param topic Topic.
 * @param locTransLsnr Local listener of transformed events
 * @param rmtFilterFactory Remote filter factory.
 * @param rmtTransFactory Remote transformer factory.
 * @param oldValRequired OldValRequired flag.
 * @param sync Sync flag.
 * @param ignoreExpired IgnoreExpired flag.
 * @param ignoreClsNotFound IgnoreClassNotFoundException flag.
 */
public CacheContinuousQueryHandlerV3(
    String cacheName,
    Object topic,
    EventListener<?> locTransLsnr,
    @Nullable Factory<? extends CacheEntryEventFilter<K, V>> rmtFilterFactory,
    Factory<? extends IgniteClosure<CacheEntryEvent<? extends K, ? extends V>, ?>> rmtTransFactory,
    boolean oldValRequired,
    boolean sync,
    boolean ignoreExpired,
    boolean ignoreClsNotFound) {
    super(
        cacheName,
        topic,
        null,
        rmtFilterFactory,
        oldValRequired,
        sync,
        ignoreExpired,
        ignoreClsNotFound,
        null);

    assert rmtTransFactory != null;

    this.locTransLsnr = locTransLsnr;
    this.rmtTransFactory = rmtTransFactory;
}
 
Example #14
Source File: CacheContinuousQueryHandler.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Performs resource injection and checks asynchrony for the provided remote filter.
 *
 * @param filter Remote filter.
 * @param ctx Kernal context.
 * @throws IgniteCheckedException If failed to perform resource injection.
 */
protected void initRemoteFilter(CacheEntryEventFilter filter, GridKernalContext ctx) throws IgniteCheckedException {
    CacheEntryEventFilter impl =
        filter instanceof JCacheQueryRemoteFilter
            ? ((JCacheQueryRemoteFilter)filter).impl
            : filter;

    if (impl != null) {
        ctx.resource().injectGeneric(impl);

        if (!asyncCb)
            asyncCb = U.hasAnnotation(impl, IgniteAsyncCallback.class);
    }
}
 
Example #15
Source File: GridCacheContinuousQueryMultiNodesFilteringTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public CacheEntryEventFilter create() {
    return new CacheEntryEventFilter() {
        /** {@inheritDoc} */
        @Override public boolean evaluate(CacheEntryEvent evt) throws CacheEntryListenerException {
            int evtNodeIdx = (Integer)(ignite.cluster().localNode().attributes().get("idx"));

            assertTrue(evtNodeIdx % 2 == idx % 2);

            return true;
        }
    };
}
 
Example #16
Source File: DiscoveryDataDeserializationFailureHanderTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @return Continuous query with a remote filter from an external class loader.
 */
private ContinuousQuery<Integer, Integer> continuousQuery() throws Exception {
    final Class<Factory<CacheEntryEventFilter<Integer, Integer>>> evtFilterFactory =
        (Class<Factory<CacheEntryEventFilter<Integer, Integer>>>)getExternalClassLoader().
            loadClass("org.apache.ignite.tests.p2p.CacheDeploymentEntryEventFilterFactory");

    ContinuousQuery<Integer, Integer> qry = new ContinuousQuery<>();

    qry.setLocalListener(evts -> {});

    qry.setRemoteFilterFactory(evtFilterFactory.newInstance());

    return qry;
}
 
Example #17
Source File: CacheContinuousQueryLongP2PTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @return Continuous query with remote filter from an external class loader.
 * @throws Exception If failed.
 */
private ContinuousQuery<Integer, Integer> continuousQuery() throws Exception {
    final Class<Factory<CacheEntryEventFilter>> evtFilterFactoryCls =
        (Class<Factory<CacheEntryEventFilter>>)getExternalClassLoader().
            loadClass("org.apache.ignite.tests.p2p.CacheDeploymentEntryEventFilterFactory");

    ContinuousQuery<Integer, Integer> qry = new ContinuousQuery<>();

    qry.setLocalListener((evt) -> {});

    qry.setRemoteFilterFactory(
        (Factory<? extends CacheEntryEventFilter<Integer, Integer>>)(Object)evtFilterFactoryCls.newInstance());

    return qry;
}
 
Example #18
Source File: CacheContinuousQueryOperationP2PTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param ccfg Cache configuration.
 * @param isClient Client.
 * @throws Exception If failed.
 */
protected void testContinuousQuery(CacheConfiguration<Object, Object> ccfg, boolean isClient)
    throws Exception {

    ignite(0).createCache(ccfg);

    final Class<Factory<CacheEntryEventFilter>> evtFilterFactoryCls =
        (Class<Factory<CacheEntryEventFilter>>)getExternalClassLoader().
            loadClass("org.apache.ignite.tests.p2p.CacheDeploymentEntryEventFilterFactory");

    testContinuousQuery(ccfg, isClient, false, evtFilterFactoryCls);
    testContinuousQuery(ccfg, isClient, true, evtFilterFactoryCls);
}
 
Example #19
Source File: CacheContinuousQueryHandler.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Fires continuous query execution event.
 * @see org.apache.ignite.events.EventType#EVT_CACHE_QUERY_EXECUTED
 */
private void sendQueryExecutedEvent() {
    GridCacheContext<K, V> cctx = cacheContext(ctx);

    CacheEntryEventFilter filter;
    try {
        filter = getEventFilter();
    }
    catch (IgniteCheckedException e) {
        if (log.isDebugEnabled()) {
            log.debug("Failed to trigger the continuoue query executed event. " +
                "[routineId=" + routineId + ", cacheName=" + cacheName + ", err=" + e + "]");
        }

        return;
    }

    if (cctx != null && cctx.events().isRecordable(EVT_CACHE_QUERY_EXECUTED)) {
        //noinspection unchecked
        ctx.event().record(new CacheQueryExecutedEvent<K, V>(
            ctx.discovery().localNode(),
            "Continuous query executed.",
            EVT_CACHE_QUERY_EXECUTED,
            CacheQueryType.CONTINUOUS.name(),
            cacheName,
            null,
            null,
            null,
            filter instanceof CacheEntryEventSerializableFilter ?
                (CacheEntryEventSerializableFilter)filter : null,
            null,
            nodeId,
            taskName()
        ));
    }
}
 
Example #20
Source File: BlazingCacheCacheEntryListenerWrapper.java    From blazingcache with Apache License 2.0 5 votes vote down vote up
BlazingCacheCacheEntryListenerWrapper(boolean synchronous, boolean oldValueRequired, CacheEntryListener<K, V> listener, CacheEntryEventFilter<K, V> filter, CacheEntryListenerConfiguration<K, V> configuration, BlazingCacheCache<K, V> parent) {
    this.synchronous = synchronous;
    this.parent = parent;
    this.oldValueRequired = oldValueRequired;
    this.listener = listener;
    this.filter = filter;
    this.configuration = configuration;
    this.onCreate = listener instanceof CacheEntryCreatedListener;
    this.onUpdate = listener instanceof CacheEntryUpdatedListener;
    this.onRemove = listener instanceof CacheEntryRemovedListener;
    this.needPreviousValue = oldValueRequired || onRemove || onUpdate;
}
 
Example #21
Source File: EventListenerAdaptors.java    From ehcache3 with Apache License 2.0 4 votes vote down vote up
ExpiredAdaptor(Cache<K, V> source, CacheEntryExpiredListener<K, V> listener, CacheEntryEventFilter<K, V> filter,
    boolean requestsOld) {
  super(source, filter, requestsOld);
  this.listener = listener;
}
 
Example #22
Source File: Registration.java    From caffeine with Apache License 2.0 4 votes vote down vote up
/** @return the registered filter */
public CacheEntryEventFilter<K, V> getCacheEntryFilter() {
  return filter;
}
 
Example #23
Source File: EventListenerAdaptors.java    From ehcache3 with Apache License 2.0 4 votes vote down vote up
UpdatedAdaptor(Cache<K, V> source, CacheEntryUpdatedListener<K, V> listener, CacheEntryEventFilter<K, V> filter,
    boolean requestsOld) {
  super(source, filter, requestsOld);
  this.listener = listener;
}
 
Example #24
Source File: EventListenerAdaptors.java    From ehcache3 with Apache License 2.0 4 votes vote down vote up
EventListenerAdaptor(Cache<K, V> source, CacheEntryEventFilter<K, V> filter, boolean requestsOld) {
  this.source = source;
  this.filter = filter;
  this.requestsOld = requestsOld;
}
 
Example #25
Source File: EventListenerAdaptors.java    From ehcache3 with Apache License 2.0 4 votes vote down vote up
RemovedAdaptor(Cache<K, V> source, CacheEntryRemovedListener<K, V> listener, CacheEntryEventFilter<K, V> filter,
    boolean requestsOld) {
  super(source, filter, requestsOld);
  this.listener = listener;
}
 
Example #26
Source File: ListenerResources.java    From ehcache3 with Apache License 2.0 4 votes vote down vote up
CacheEntryEventFilter<? super K, ? super V> getFilter() {
  return filter;
}
 
Example #27
Source File: ConfigurationMergerTest.java    From ehcache3 with Apache License 2.0 4 votes vote down vote up
@Override
public Factory<CacheEntryEventFilter<? super Object, ? super Object>> getCacheEntryEventFilterFactory() {
  throw new UnsupportedOperationException("BOOM");
}
 
Example #28
Source File: CacheContinuousQueryHandler.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @return Cache entry event filter.
 *
 * @throws IgniteCheckedException If P2P unmarshalling failed.
 */
public CacheEntryEventFilter getEventFilter() throws IgniteCheckedException {
    initFut.get();

    return getEventFilter0();
}
 
Example #29
Source File: Registration.java    From caffeine with Apache License 2.0 4 votes vote down vote up
public Registration(CacheEntryListenerConfiguration<K, V> configuration,
    CacheEntryEventFilter<K, V> filter, EventTypeAwareListener<K, V> listener) {
  this.configuration = requireNonNull(configuration);
  this.listener = requireNonNull(listener);
  this.filter = requireNonNull(filter);
}
 
Example #30
Source File: ListenerResources.java    From ehcache3 with Apache License 2.0 4 votes vote down vote up
ListenerResources(CacheEntryListener<? super K, ? super V> listener,
                  CacheEntryEventFilter<? super K, ? super V> filter) {
  this.listener = listener;
  this.filter = filter;
}