[jboss-user] [JBoss Cache] - Re: JBoss Cache 3.x Eviction notification

Swaminathan Bhaskar do-not-reply at jboss.com
Fri May 20 20:21:38 EDT 2011


Swaminathan Bhaskar [http://community.jboss.org/people/swaminathan.bhaskar] created the discussion

"Re: JBoss Cache 3.x Eviction notification"

To view the discussion, visit: http://community.jboss.org/message/606372#606372

--------------------------------------------------------------
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 ?
--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/606372#606372]

Start a new discussion in JBoss Cache at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2052]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20110520/88207238/attachment-0001.html 


More information about the jboss-user mailing list