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

jaysmith do-not-reply at jboss.com
Thu May 19 09:27:50 EDT 2011


jaysmith [http://community.jboss.org/people/jaysmith] created the discussion

"Re: JBoss Cache 3.x Eviction notification"

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

--------------------------------------------------------------
Hi,

you sure the CacheListener didn't work? I have this code for a listener and it works pretty well if memory serves me correctly.

*****import java.text.SimpleDateFormat;
import java.util.Date;

import org.jboss.cache.notifications.annotation.CacheListener;
import org.jboss.cache.notifications.annotation.CacheStarted;
import org.jboss.cache.notifications.annotation.NodeActivated;
import org.jboss.cache.notifications.annotation.NodeCreated;
import org.jboss.cache.notifications.annotation.NodeEvicted;
import org.jboss.cache.notifications.annotation.NodeLoaded;
import org.jboss.cache.notifications.annotation.NodePassivated;
import org.jboss.cache.notifications.annotation.NodeRemoved;
import org.jboss.cache.notifications.annotation.NodeVisited;
import org.jboss.cache.notifications.event.CacheStartedEvent;
import org.jboss.cache.notifications.event.NodeActivatedEvent;
import org.jboss.cache.notifications.event.NodeCreatedEvent;
import org.jboss.cache.notifications.event.NodeEvictedEvent;
import org.jboss.cache.notifications.event.NodeLoadedEvent;
import org.jboss.cache.notifications.event.NodePassivatedEvent;
import org.jboss.cache.notifications.event.NodeRemovedEvent;
import org.jboss.cache.notifications.event.NodeVisitedEvent;

@CacheListener
public class CustomCacheListener {
    @CacheStarted
    public final void cacheStarted(final CacheStartedEvent e) {
        System.out.println(format(new Date()) + " [CustomCacheListener] Cache started");
    }

    private String format(Date date) {
        SimpleDateFormat formatter = new SimpleDateFormat("HH:MM:ss.SSS");
        return formatter.format(date);
    }

    @NodeActivated
    public final void nodeActivated(final NodeActivatedEvent ne) {
        System.out.println(format(new Date()) + " [CustomCacheListener] Activated key: " + ne.getFqn().toString());
    }

    @NodeCreated
    public final void nodeCreated(final NodeCreatedEvent ne) {
        System.out.println(format(new Date()) + " [CustomCacheListener] Created key: " + ne.getFqn().toString());
    }

    @NodeEvicted
    public final void nodeEvicted(final NodeEvictedEvent ne) {
        System.out.println(format(new Date()) + " [CustomCacheListener] Evicted key: " + ne.getFqn().toString());
    }

    @NodeLoaded
    public final void nodeLoaded(final NodeLoadedEvent ne) {
        System.out.println(format(new Date()) + " [CustomCacheListener] Loaded key: " + ne.getFqn().toString());
    }

    @NodePassivated
    public final void nodePassivated(final NodePassivatedEvent ne) {
        System.out.println(format(new Date()) + " [CustomCacheListener] Passivated key: " + ne.getFqn().toString());
    }

    @NodeRemoved
    public final void nodeRemoved(final NodeRemovedEvent cere) {
        System.out.println(format(new Date()) + " [CustomCacheListener] Removed key: " + cere.getFqn().toString());
    }

    @NodeVisited
    public final void nodeVisited(final NodeVisitedEvent ne) {
        System.out.println(format(new Date()) + " [CustomCacheListener] Visited key: " + ne.getFqn().toString());
    }
}
*****
--------------------------------------------------------------

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

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/20110519/9c7367e4/attachment.html 


More information about the jboss-user mailing list