RegisteredEventListeners hava a question ?!

2009-09-16
2013-05-14
  • ding superman
    ding superman
    2009-09-16

    i use ehcache1.6.2.

    i hava a class implements CacheEventListener :

    ------------CacheEvent.java---------------

    import net.sf.ehcache.CacheException;

    import net.sf.ehcache.Ehcache;

    import net.sf.ehcache.Element;

    import net.sf.ehcache.event.CacheEventListener;

    public class CacheEvent implements CacheEventListener{
    public void dispose()  
        {  
            System.out.println("in dispose");  
        }  
     
        public void notifyElementEvicted(Ehcache cache, Element element)  
        {  
        System.out.println("in notifyElementEvicted" + element);  
        }  
     
        public void notifyElementExpired(Ehcache cache, Element element)  
        {  
        System.out.println("in notifyElementExpired" + element);  
        }  
     
        public void notifyElementPut(Ehcache cache, Element element) throws CacheException  
        {  
        System.out.println("in notifyElementPut" + cache.getName()+"   "+element);
        }  
     
        public void notifyElementRemoved(Ehcache cache, Element element) throws CacheException  
        {  
        System.out.println("in notifyElementRemoved" + element);  
        }  
     
        public void notifyElementUpdated(Ehcache cache, Element element) throws CacheException  
        {  
        System.out.println("in notifyElementUpdated" + element);  
        }  
     
        public void notifyRemoveAll(Ehcache cache)  
        {  
        System.out.println("in notifyRemoveAll");  
        }  
         
        public Object clone() throws CloneNotSupportedException  
        {  
            return super.clone();  
        }     
    }

    i create a cache,i RegisteredEventListeners,but have no effect !

    -------------Demo.java----------------------------------

    import net.sf.ehcache.Cache;

    import net.sf.ehcache.CacheManager;

    import net.sf.ehcache.Element;

    import net.sf.ehcache.event.CacheEventListener;

    import net.sf.ehcache.event.RegisteredEventListeners;

    public class Demo {

    public static void main(String args) {
    CacheManager manager = CacheManager.create();
    Cache ca = new Cache("23", 3000, false, true, 20l, 50l);
    RegisteredEventListeners re = new RegisteredEventListeners(ca);
    CacheEventListener ce = new CacheEvent();
    boolean fl = re.registerListener(ce);
    System.out.println(fl);
    manager.addCache(ca);

    for (int i = 0; i < 100; i++) {
    Element element = new Element(""+i, ""+i);
    ca.put(element);
    System.out.println(ca.getSize());
    }

    }
    }

    why?!
    when i put a element in cache , the CacheEvent.java have no
    effect !

     
  • ding superman
    ding superman
    2009-09-16

    " is "

     
  • ding superman
    ding superman
    2009-09-16

    i must use code . not config file !

     
  • ding superman
    ding superman
    2009-09-18

    Thank you very much ,my english is not good.
    Good Luck!