2 Replies Latest reply on Aug 17, 2009 10:02 AM by Jeff Sinjem

    Pojo Cache EvictionPolicy event?

    Jeff Sinjem Newbie

      I'm looking for a JBoss Pojo Cache listener event that I can wire in to my code to get called when a timeToLiveSeconds in my EvictionPolicyConfig gets fired.

      I've found the @PojoCacheListener but don't get an event fired when the the node is removed. After my junit test the objects are gone but my event listener is never fired.

      I've added listeners for @NodeEvicted, @NodePssivated, @NodeInvalidated, and @Detached but my method does't get fired when a node is removed based on my local-service.xml eviction policy. The objects are gone but my listener method never gets fired.

      Here's my policy xml:

      <attribute name="EvictionPolicyConfig">
       <attribute name="wakeUpIntervalSeconds">5</attribute>
       <attribute name="policyClass">org.jboss.cache.eviction.LRUPolicy</attribute>
       <!-- JUnit Test Supplied Region -->
       <region name="/_default_">
       <attribute name="maxNodes">5000</attribute>
       <attribute name="timeToLiveSeconds">3</attribute>

      And here's my event listener:
      public class JBossPojoDataStoreListener {
       private static Log log = LogFactory
       public void handleAttachDetach(Event event) {
       if (event instanceof AttachedEvent) {
       log.debug("Attached = " + event.getSource());
       } else if (event instanceof DetachedEvent) {
       log.debug("DetachedEvent = " + event.getSource());
       } else if (event instanceof NodeEvictedEvent) {
       log.debug("NodeEvictedEvent = " + ((NodeEvictedEvent) event).getFqn());
       } else if (event instanceof NodePassivatedEvent) {
       log.debug("NodePassivatedEvent = " + ((NodePassivatedEvent) event).getFqn());
       } else if (event instanceof NodeRemovedEvent) {
       log.debug("NodeRemovedEvent = " + event.getSource());
       } else if (event instanceof NodeInvalidatedEvent) {
       log.debug("NodeInvalidatedEvent = " + ((NodeInvalidatedEvent) event).getFqn());

      Am I missing something insanely obvious? Has anyone had any luck getting this to work?

      Thanks for any experience you can share.

        • 1. Re: Pojo Cache EvictionPolicy event?
          Galder Zamarreño Master

          Did you register the listener with the PojoCache instance?

          • 2. Re: Pojo Cache EvictionPolicy event?
            Jeff Sinjem Newbie

            Thanks for responding as I still can't figure this out. I did register the listener with the PojoCache instance using the addListener() method. I am also receiving events using annotations.

            What I can't get to work is an event to fire when a node is evicted based on an eviction policy defined in the local-service.xml.

            I have a junit test case which validates that the nodes are evicted after a timeToLiveSeconds equal to 3. I can't find an annotation for an event to fire when the node is evicted based on the EvictionPolicyConfig.

            Is there such an annotation? I need to log the fact that a node has been removed from the cache based on the timeToLiveSeconds attribute.

            I appreciate your help!