Infinispan cache listener

113 views
Skip to first unread message

Andrzej Rostkowski

unread,
Oct 7, 2024, 7:21:16 AM10/7/24
to WildFly
Hello, 

I'm migrating from Wildfly 30.0.1 to 33.0.2. I've two Wildflies in standalone mode on different machines in cluster. I've cache with the following listener:

import org.infinispan.notifications.Listener;
import org.infinispan.notifications.cachelistener.annotation.CacheEntryCreated;
import org.infinispan.notifications.cachelistener.annotation.CacheEntryExpired;
import org.infinispan.notifications.cachelistener.annotation.CacheEntryModified;
import org.infinispan.notifications.cachelistener.event.CacheEntryCreatedEvent;
import org.infinispan.notifications.cachelistener.event.CacheEntryExpiredEvent;
import org.infinispan.notifications.cachelistener.event.CacheEntryModifiedEvent;

@Listener
public class ClusterCacheListener {

    UpdaterLocalCache updater;
    String cacheName;

    public ClusterCacheListener (UpdaterLocalCache updater) {
        this.updater = updater;
        this.cacheName = updater.getClass().getSimpleName();
    }

    @CacheEntryCreated
    public void entryCreated(CacheEntryCreatedEvent<ClusterKey, QValue> event) {
        if (event.isPre()) return;
        if (event.isOriginLocal()) {
//...
        } else {
            updater.updateLocalCacheFromClusterCache(event);
        }

    }

    @CacheEntryModified
    public void entryModified(CacheEntryModifiedEvent<ClusterKey, QValue> event) {
        if (event.isPre()) return;
        if (event.isOriginLocal()) {
//...
        } else {
            updater.updateLocalCacheFromClusterCache(event);
        }
    }

    @CacheEntryExpired
    public void entryExpired(CacheEntryExpiredEvent<ClusterKey, QValue> event) {
//...
    }
}

During startup of Wildfly after invoking addLister on cache I get the following error:
00:38:45,800 WARN  [org.infinispan.notifications.cachelistener.CacheNotifierImpl] (ServerService Thread Pool -- 217) ISPN000133: Attempted to register listener of class class ClusterCacheListener, but no valid, public methods annotated with method-level event annotations found! Ignoring listener

I've already tried changing the annotation to clustered, turning of sync. Tried to change the return of the annotated methods to CompletionStage<Void> 
but nothing changed - still the same WARN in logs and the methods are not being invoked.

Please help, any advice would be great. 

Paul Ferraro

unread,
Oct 9, 2024, 4:24:22 AM10/9/24
to WildFly
Can you paste the code that registers your cache listener?

Andrzej Rostkowski

unread,
Oct 9, 2024, 5:10:06 AM10/9/24
to WildFly
Sure,

I've Stateless EJB with the following injection
@Resource(lookup = "java:jboss/infinispan/cache/kartamiejska/dist")
private Cache<
ClusterKeyQValue> cacheKlustra;

and in the method that loads the cache for the first or reload it on demand I have:
cacheKlustra.addListener(QCardStarter.listener);

The QCardStarter is a singleton with static instance of listener:
@Singleton
@Startup
public class QCardStarter implements UpdaterLocalCache {

public static ClusterCacheListener listener = null;

@PostConstruct
@Lock(LockType.WRITE)
public void init() {
listener = new ClusterCacheListener(this);
getCacheMgr().reloadCache(Lists.newArrayList()); // lookups the EJB, inits cache and then addListener
}

...

Paul Ferraro

unread,
Oct 9, 2024, 5:26:50 AM10/9/24
to WildFly
I see no obvious problem there, so I suspect this is a classloader issue.  Can verify that your application does not bundle any Infinispan jars, and instead declares module dependencies on the requisite Infinispan modules?
e.g.
/META-INF/MANIFEST.MF:

Manifest-Version: 1.0
Dependencies: org.infinispan.core, org.infinispan.commons


Paul

Jose Socola

unread,
Oct 9, 2024, 4:19:38 PM10/9/24
to Paul Ferraro, WildFly
I have a question: do you need 4 @annotattions with public scope to remove warnings?

1. @CacheEntryCreated
2. @CacheEntryModified
3. @CacheEntryRemoved
4. @CacheEntryExpired

Regards,
JS


--
You received this message because you are subscribed to the Google Groups "WildFly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wildfly+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/wildfly/95611104-d659-4d11-a78c-980c867a3246n%40googlegroups.com.

Andrzej Rostkowski

unread,
Oct 10, 2024, 8:59:07 AM10/10/24
to WildFly
Hello,

The problem was related to incompatible versions of libs. In the project, I updated Infinispan to version 14.0.29 in maven dependency, but I didn't notice that the module in WF had version with “-jakarta” in the library name 🤦‍♂️
The annotation packages were the same but in the runtime, as I checked with the debugger, the declaredAnnotation list was empty on this method.
Sorry for trouble

Regards
Andrzej
Reply all
Reply to author
Forward
0 new messages