Hi Jay,
First off - thank you very much for your response. Much appreciated. Yes, I did try that and it does not work as I would expect. Let me provide you the code:
Here is the listener code:
import org.jboss.cache.notifications.annotation.*;
import org.jboss.cache.notifications.event.*;
@CacheListener
public class MyCacheListener {
@NodeEvicted
public void logNodeEvent(NodeEvictedEvent ne) {
System.out.println("***** Evicted FQN: " + ne.getFqn() + ", Type: " + ne.getType());
}
}
Here is the main code:
import org.jboss.cache.*;
public class MyJBossCacheTest1 {
@SuppressWarnings({ "rawtypes", "unchecked" })
public static void main(String[] args) {
if (args.length != 1) {
System.out.printf("Usage: java %s <config-file>\n", MyJBossCacheTest1.class.getName());
System.exit(1);
}
CacheFactory factory = new DefaultCacheFactory();
Cache cache = factory.createCache(args[0]);
cache.addCacheListener(new MyCacheListener());
cache.start();
Fqn myUserData = Fqn.fromString("/my/data/user");
// Prime Cache with User Data
{
int MAX_USERS = 3;
for (int i = 1; i <= MAX_USERS; i++) {
String user = "u." + i;
String email = "user_" + i +"@nowhere.com";
cache.put(myUserData, user, email);
}
}
// Access User - "u.2"
{
String user = (String) cache.get(myUserData, "u.2");
if (user != null) {
System.out.println("Accessed - " + user);
}
else {
System.out.println("Access of u.2 is null");
}
}
// Access Users after sleep of 30 secs
{
System.out.println("Ready to sleep for 30 secs ...");
try {
Thread.sleep(30000);
}
catch (Exception ex) {
}
System.out.println("Ready to access user(s) ...");
int MAX_USERS = 3;
for (int i = 1; i <= MAX_USERS; i++) {
String user = (String) cache.get(myUserData, "u."+i);
if (user != null) {
System.out.println("Accessed - " + user);
}
else {
System.out.println("Access of u." + i + " is null");
}
}
}
cache.stop();
cache.destroy();
}
}
Was expection to see the FQNs: /my/user/data/u.1, /my/data/user/u.2, and /my/data/user/u.3 to be shown by the listener on eviction. But instead I see the following:
***** Evicted FQN: /my/data/user, Type: NODE_EVICTED
***** Evicted FQN: /my/data/user, Type: NODE_EVICTED
In other words I would not know which keys were evicted ... Any ideas ?