javax.cache.event.CacheEntryListenerException Java Examples

The following examples show how to use javax.cache.event.CacheEntryListenerException. 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: CacheListenerTestBase.java    From triava with Apache License 2.0 6 votes vote down vote up
@Override
public void onExpired(Iterable<CacheEntryEvent<? extends Integer, ? extends String>> events)
		throws CacheEntryListenerException
{
	String msg = name + ":EXPIRED!";
	int eventCount = countEvents(events, msg);
	expiredListenerFiredCount.addAndGet(eventCount);
	if (printAllEvents)
	{
		Iterator<CacheEntryEvent<? extends Integer, ? extends String>> iterator = events.iterator();
		while (iterator.hasNext() )
		{
			
			CacheEntryEvent<? extends Integer,? extends String> event = iterator.next();
			System.out.println(msg + " Event: " + event.getValue());
			
		}
		
	}
		
}
 
Example #2
Source File: PlatformContinuousQueryImpl.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override public boolean evaluate(CacheEntryEvent evt) throws CacheEntryListenerException {
    if (javaFilter != null)
        return javaFilter.evaluate(evt);

    lock.readLock().lock();

    try {
        if (ptr == 0)
            throw new CacheEntryListenerException("Failed to evaluate the filter because it has been closed.");

        return !hasFilter || PlatformUtils.evaluateContinuousQueryEvent(platformCtx, ptr, evt);
    }
    finally {
        lock.readLock().unlock();
    }
}
 
Example #3
Source File: CacheContinuousQueryOrderingEventTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override public void onUpdated(Iterable<CacheEntryEvent<? extends QueryTestKey,
    ? extends QueryTestValue>> evts) {
    if (delayOp && ThreadLocalRandom.current().nextInt(5) == 1) {
        try {
            U.sleep(10);
        }
        catch (IgniteInterruptedCheckedException ex) {
            throw new CacheEntryListenerException(ex);
        }
    }

    for (CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue> e : evts) {
        queue.add((CacheEntryEvent<QueryTestKey, QueryTestValue>)e);

        cntr.incrementAndGet();
    }
}
 
Example #4
Source File: PlatformUtils.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Evaluate the filter.
 *
 * @param ctx Context.
 * @param filterPtr Native filter pointer.
 * @param evt Event.
 * @return Result.
 * @throws CacheEntryListenerException In case of failure.
 */
public static boolean evaluateContinuousQueryEvent(PlatformContext ctx, long filterPtr, CacheEntryEvent evt)
    throws CacheEntryListenerException {
    assert filterPtr != 0;

    try (PlatformMemory mem = ctx.memory().allocate()) {
        PlatformOutputStream out = mem.output();

        out.writeLong(filterPtr);

        writeCacheEntryEvent(ctx.writer(out), evt);

        out.synchronize();

        return ctx.gateway().continuousQueryFilterApply(mem.pointer()) == 1;
    }
    catch (Exception e) {
        throw toCacheEntryListenerException(e);
    }
}
 
Example #5
Source File: ContinuousQueryRemoteFilterMissingInClassPathSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param cache Ignite cache.
 * @throws Exception If fail.
 */
private void executeContinuousQuery(IgniteCache<Object, Object> cache) throws Exception {
    ContinuousQuery<Integer, String> qry = new ContinuousQuery<>();

    qry.setLocalListener(
        new CacheEntryUpdatedListener<Integer, String>() {
            @Override public void onUpdated(Iterable<CacheEntryEvent<? extends Integer, ? extends String>> events)
                throws CacheEntryListenerException {
                for (CacheEntryEvent<? extends Integer, ? extends String> event : events)
                    System.out.println("Key = " + event.getKey() + ", Value = " + event.getValue());
            }
        }
    );

    Class<CacheEntryEventSerializableFilter> remoteFilterCls = (Class<CacheEntryEventSerializableFilter>)
        extLdr.loadClass(EXT_FILTER_CLASS);

    qry.setRemoteFilterFactory(new ClassFilterFactory(remoteFilterCls));

    cache.query(qry);

    for (int i = 0; i < 100; i++)
        cache.put(i, "Message " + i);
}
 
Example #6
Source File: CacheEntryListenerClient.java    From cache2k with Apache License 2.0 5 votes vote down vote up
@Override
public void onUpdated(Iterable<CacheEntryEvent<? extends K, ? extends V>> cacheEntryEvents)
  throws CacheEntryListenerException {
  if (isDirectCallable()) {
    for (CacheEntryListener<K,V> l : listenerServer.getListeners()) {
      if (l instanceof CacheEntryUpdatedListener) {
        ((CacheEntryUpdatedListener<K,V>) l).onUpdated(cacheEntryEvents);
      }
    }
    return;
  }
  for (CacheEntryEvent<? extends K, ? extends V> event : cacheEntryEvents) {
    getClient().invoke(new OnCacheEntryEventHandler<K, V>(event));
  }
}
 
Example #7
Source File: CacheListenerTestBase.java    From triava with Apache License 2.0 5 votes vote down vote up
@Override
public void onExpired(Iterable<CacheEntryEvent<? extends Integer, ? extends String>> events)
		throws CacheEntryListenerException
{
	String msg = "EXPIRED";
	int eventCount = countEvents(events, msg);
	expiredListenerFiredCount.addAndGet(eventCount);
}
 
Example #8
Source File: CacheListenerTestBase.java    From triava with Apache License 2.0 5 votes vote down vote up
@Override
public void onRemoved(Iterable<CacheEntryEvent<? extends Integer, ? extends String>> events)
		throws CacheEntryListenerException
{
	String msg = "REMOVED";
	int eventCount = countEvents(events, msg);
	removedListenerFiredCount.addAndGet(eventCount);
}
 
Example #9
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 #10
Source File: CacheContinuousWithTransformerReplicatedSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public void onUpdated(Iterable<? extends String> events) throws CacheEntryListenerException {
    for (String evt : events) {
        cnt.incrementAndGet();

        if (evt.startsWith(SARAH_CONNOR))
            cntLatch.countDown();
    }
}
 
Example #11
Source File: CacheContinuousQueryExecuteInPrimaryTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception If failed.
 */
private void doTestWithoutEventsEntries(CacheConfiguration<Integer, String> ccfg) throws Exception {

    try (IgniteCache<Integer, String> cache = grid(0).createCache(ccfg)) {

        int ITERATION_CNT = 100;
        final AtomicBoolean noOneListen = new AtomicBoolean(true);

        for (int i = 0; i < ITERATION_CNT; i++) {
            ContinuousQuery<Integer, String> qry = new ContinuousQuery<>();

            qry.setLocalListener(new CacheEntryUpdatedListener<Integer, String>() {
                @Override public void onUpdated(
                    Iterable<CacheEntryEvent<? extends Integer, ? extends String>> iterable)
                    throws CacheEntryListenerException {
                    noOneListen.set(false);
                }
            });

            qry.setRemoteFilterFactory(FactoryBuilder.factoryOf(
                new CacheEntryEventSerializableFilter<Integer, String>() {
                    @Override public boolean evaluate(
                        CacheEntryEvent<? extends Integer, ? extends String> cacheEntryEvent)
                        throws CacheEntryListenerException {
                        return false;
                    }
                }));

            executeQuery(cache, qry, ccfg.getAtomicityMode() != ATOMIC);
        }

        assertTrue(noOneListen.get());

    }
    finally {
        ignite(0).destroyCache(ccfg.getName());
    }
}
 
Example #12
Source File: CacheEntryListenerClient.java    From cache2k with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreated(Iterable<CacheEntryEvent<? extends K, ? extends V>> cacheEntryEvents) throws CacheEntryListenerException {
  if (isDirectCallable()) {
    for (CacheEntryListener<K,V> l : listenerServer.getListeners()) {
      if (l instanceof CacheEntryCreatedListener) {
        ((CacheEntryCreatedListener<K,V>) l).onCreated(cacheEntryEvents);
      }
    }
    return;
  }
  for (CacheEntryEvent<? extends K, ? extends V> event : cacheEntryEvents) {
    getClient().invoke(new OnCacheEntryEventHandler<K, V>(event));
  }
}
 
Example #13
Source File: CacheContinuousQueryAsyncFilterListenerTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public void onUpdated(Iterable<CacheEntryEvent<? extends QueryTestKey,
    ? extends QueryTestValue>> events)
    throws CacheEntryListenerException {
    for (CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue> e : events)
        clsr.apply(ignite, e);
}
 
Example #14
Source File: CacheContinuousBatchAckTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param ccfg Cache configuration.
 * @throws Exception If failed.
 */
private void checkBackupAcknowledgeMessage(CacheConfiguration<Object, Object> ccfg) throws Exception {
    QueryCursor qry = null;

    IgniteCache<Object, Object> cache = null;

    try {
        ContinuousQuery q = new ContinuousQuery();

        q.setLocalListener(new CacheEntryUpdatedListener() {
            @Override public void onUpdated(Iterable iterable) throws CacheEntryListenerException {
                // No-op.
            }
        });

        cache = grid(SERVER).getOrCreateCache(ccfg);

        qry = cache.query(q);

        for (int i = 0; i < GridTestUtils.SF.applyLB(10000, 1000); i++)
            cache.put(i, i);

        assertFalse(GridTestUtils.waitForCondition(fail::get, 1300L));
    }
    finally {
        if (qry != null)
            qry.close();

        if (cache != null)
            grid(SERVER).destroyCache(cache.getName());
    }
}
 
Example #15
Source File: CacheContinuousQueryFailoverAbstractSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public synchronized void onUpdated(Iterable<CacheEntryEvent<?, ?>> evts)
    throws CacheEntryListenerException {
    try {
        for (CacheEntryEvent<?, ?> evt : evts) {
            Integer key = (Integer)evt.getKey();
            Integer val = (Integer)evt.getValue();

            assertNotNull(key);
            assertNotNull(val);

            Integer prevVal = vals.get(key);

            boolean dup = false;

            if (prevVal != null && prevVal.equals(val))
                dup = true;

            if (!dup) {
                vals.put(key, val);

                List<CacheEntryEvent<?, ?>> keyEvts = this.evts.get(key);

                if (keyEvts == null) {
                    keyEvts = Collections.synchronizedList(new ArrayList<CacheEntryEvent<?, ?>>());

                    this.evts.put(key, keyEvts);
                }

                keyEvts.add(evt);
            }
        }
    }
    catch (Throwable e) {
        err = true;

        log.error("Unexpected error", e);
    }
}
 
Example #16
Source File: JCSListener.java    From commons-jcs with Apache License 2.0 5 votes vote down vote up
public void onCreated(final List<CacheEntryEvent<? extends K, ? extends V>> events) throws CacheEntryListenerException
{
    if (create)
    {
        CacheEntryCreatedListener.class.cast(delegate).onCreated(filter(events));
    }
}
 
Example #17
Source File: CacheContinuousQueryFailoverAbstractSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings("EqualsBetweenInconvertibleTypes")
@Override public void onUpdated(Iterable<CacheEntryEvent<? extends Integer, ? extends Integer>> evts)
    throws CacheEntryListenerException {
    for (CacheEntryEvent<? extends Integer, ? extends Integer> evt : evts) {
        Integer prev = evtMap.put(evt.getKey(), evt.getValue());

        //Atomic cache allows duplicate events if cache update operation fails, e.g. due to topology change.
        if (!atomicModeFlag || prev == null || !prev.equals(evt))
            cntr.incrementAndGet();
    }
}
 
Example #18
Source File: ExpiryListenerTest.java    From commons-jcs with Apache License 2.0 5 votes vote down vote up
@Override
public void onExpired(final Iterable<CacheEntryEvent<? extends String, ? extends String>> cacheEntryEvents)
        throws CacheEntryListenerException {
    for (final CacheEntryEvent<? extends String, ? extends String> cacheEntryEvent : cacheEntryEvents) {
        events.add(cacheEntryEvent);
    }
}
 
Example #19
Source File: CacheContinuousAsyncQueryExample.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public boolean evaluate(CacheEntryEvent<? extends Integer, ? extends String> e)
    throws CacheEntryListenerException {
    // This cache operation is safe because filter has Ignite AsyncCallback annotation.
    if (e.getKey() < 10 && String.valueOf(e.getKey()).equals(e.getValue()))
        ignite.cache(CACHE_NAME).put(e.getKey(), e.getValue() + "_less_than_10");

    return e.getKey() > 10;
}
 
Example #20
Source File: CacheListenersTest.java    From blazingcache with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateListenerSynch() {

    CachingProvider cachingProvider = Caching.getCachingProvider();
    Properties p = new Properties();
    try (CacheManager cacheManager = cachingProvider.getCacheManager(cachingProvider.getDefaultURI(), cachingProvider.getDefaultClassLoader(), p)) {
        Map<String, String> created = new HashMap<>();
        CacheEntryCreatedListener<String, String> listener = new CacheEntryCreatedListener<String, String>() {
            @Override
            public void onCreated(Iterable<CacheEntryEvent<? extends String, ? extends String>> events) throws CacheEntryListenerException {
                for (CacheEntryEvent<? extends String, ? extends String> e : events) {
                    created.put(e.getKey(), e.getValue());
                }
            }
        };

        MutableConfiguration<String, String> config
                = new MutableConfiguration<String, String>()
                .setTypes(String.class, String.class)
                .addCacheEntryListenerConfiguration(new MutableCacheEntryListenerConfiguration<>(
                        new FactoryBuilder.SingletonFactory(listener), null, true, true)
                );

        Cache<String, String> cache = cacheManager.createCache("simpleCache", config);

        String key = "key";
        cache.put(key, "value");
        assertEquals("value", created.get(key));
    }
}
 
Example #21
Source File: CacheListenersTest.java    From blazingcache with Apache License 2.0 5 votes vote down vote up
@Override
public boolean evaluate(
        CacheEntryEvent<? extends Long, ? extends String> event)
        throws CacheEntryListenerException {
    return event.getValue().contains("a")
            || event.getValue().contains("e")
            || event.getValue().contains("i")
            || event.getValue().contains("o")
            || event.getValue().contains("u");
}
 
Example #22
Source File: CacheListenersTest.java    From blazingcache with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreated(Iterable<CacheEntryEvent<? extends K, ? extends V>> events) throws CacheEntryListenerException {
    for (CacheEntryEvent<? extends K, ? extends V> event : events) {
        assertEquals(CREATED.toString(), event.getEventType().toString());
        created.incrementAndGet();

        // added for code coverage.
        event.getKey();
        event.getValue();
        event.getSource();
    }
}
 
Example #23
Source File: JCSListener.java    From commons-jcs with Apache License 2.0 5 votes vote down vote up
public void onUpdated(final List<CacheEntryEvent<? extends K, ? extends V>> events) throws CacheEntryListenerException
{
    if (update)
    {
        CacheEntryUpdatedListener.class.cast(delegate).onUpdated(filter(events));
    }
}
 
Example #24
Source File: CacheListenersTest.java    From blazingcache with Apache License 2.0 5 votes vote down vote up
@Override
public void onRemoved(Iterable<CacheEntryEvent<? extends K, ? extends V>> events) throws CacheEntryListenerException {            
    for (CacheEntryEvent<? extends K, ? extends V> event : events) {
        
        assertEquals(REMOVED.toString(), event.getEventType().toString());
        removed.incrementAndGet();
        event.getKey();
        if (event.isOldValueAvailable()) {
            event.getOldValue();
        }
    }
}
 
Example #25
Source File: CacheListenersTest.java    From blazingcache with Apache License 2.0 5 votes vote down vote up
@Override
public void onUpdated(Iterable<CacheEntryEvent<? extends K, ? extends V>> events) throws CacheEntryListenerException {
    for (CacheEntryEvent<? extends K, ? extends V> event : events) {
        assertEquals(UPDATED.toString(), event.getEventType().toString());
        updated.incrementAndGet();
        event.getKey();
        if (event.isOldValueAvailable()) {
            event.getOldValue();
        }
    }
}
 
Example #26
Source File: CacheListenerTest.java    From cache2k with Apache License 2.0 5 votes vote down vote up
@Override
public void onRemoved(Iterable<CacheEntryEvent<? extends K, ? extends V>> events) throws CacheEntryListenerException {
  for (CacheEntryEvent<? extends K, ? extends V> event : events) {
    assertEquals(REMOVED, event.getEventType());
    throw new IOError(null);
  }
}
 
Example #27
Source File: PolicyCacheUpdateListener.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param event The event just updated.
 * @throws CacheEntryListenerException
 */
@Override
public void entryUpdated(CacheEntryEvent<? extends IdentityCacheKey, ? extends PolicyStatus> event) throws CacheEntryListenerException {
    if(event!=null) {
        PolicyCache.updateLocalPolicyCacheMap(event.getKey(), event.getValue());
    }
}
 
Example #28
Source File: OAuthCacheRemoveListener.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
@Override
public void entryRemoved(CacheEntryEvent<? extends OAuthCacheKey, ? extends CacheEntry> cacheEntryEvent)
        throws CacheEntryListenerException {

    CacheEntry cacheEntry = cacheEntryEvent.getValue();
    if(cacheEntry == null || !(cacheEntry instanceof AccessTokenDO)){
        return;
    }
    AccessTokenDO accessTokenDO = (AccessTokenDO) cacheEntryEvent.getValue();

    if (accessTokenDO != null) {

        if (log.isDebugEnabled()) {
            log.debug("OAuth cache removed for consumer id : " + accessTokenDO.getConsumerKey());
        }

        boolean isUsernameCaseSensitive = IdentityUtil
                .isUserStoreInUsernameCaseSensitive(accessTokenDO.getAuthzUser().getUserName());
        String cacheKeyString;
        if (isUsernameCaseSensitive){
            cacheKeyString = accessTokenDO.getConsumerKey() + ":" + accessTokenDO.getAuthzUser().getUserName() + ":"
                    + OAuth2Util.buildScopeString(accessTokenDO.getScope());
        }else {
            cacheKeyString =
                    accessTokenDO.getConsumerKey() + ":" + accessTokenDO.getAuthzUser().getUserName().toLowerCase()
                            + ":" + OAuth2Util.buildScopeString(accessTokenDO.getScope());
        }

        OAuthCacheKey oauthcacheKey = new OAuthCacheKey(cacheKeyString);
        OAuthCache oauthCache = OAuthCache.getInstance();

        oauthCache.clearCacheEntry(oauthcacheKey);
        oauthcacheKey = new OAuthCacheKey(accessTokenDO.getAccessToken());

        oauthCache.clearCacheEntry(oauthcacheKey);

    }
}
 
Example #29
Source File: EventTypeFilter.java    From caffeine with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("PMD.SwitchStmtsShouldHaveDefault")
private boolean isCompatible(CacheEntryEvent<? extends K, ? extends V> event) {
  switch (event.getEventType()) {
    case CREATED:
      return (listener instanceof CacheEntryCreatedListener<?, ?>);
    case UPDATED:
      return (listener instanceof CacheEntryUpdatedListener<?, ?>);
    case REMOVED:
      return (listener instanceof CacheEntryRemovedListener<?, ?>);
    case EXPIRED:
      return (listener instanceof CacheEntryExpiredListener<?, ?>);
  }
  throw new CacheEntryListenerException("Unknown event type: " + event.getEventType());
}
 
Example #30
Source File: JCacheTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public void onExpired(Iterable<CacheEntryEvent<? extends String, ? extends String>> events)
        throws CacheEntryListenerException {
    CacheEntryEvent<? extends String, ? extends String> entry = events.iterator().next();
    
    assertThat(entry.getKey()).isEqualTo(key);
    assertThat(entry.getValue()).isEqualTo(value);
    latch.countDown();
}