JBossCache逐出监听器

时间:2011-09-21 17:15:11

标签: jboss-cache

我是JBossCache的新手。阅读用户文档时,它表示可以将侦听器添加到所使用的Eviction类中,但是我无法找到如何在配置文件中添加一个,或者应该如何添加。

我尝试使用@NodeEvicted方法添加@CacheListener,但该方法

@CacheListener
public class EvictionListener {

    @NodeEvicted
    public void nodeEvicted(NodeEvent ne) {
        System.out.println("Se borro el nodo");
    }
}

并将其添加到缓存实例

CacheFactory factory = new DefaultCacheFactory();
this.cache = factory.createCache();

EvictionListener listener = new EvictionListener();
this.cache.create();
this.cache.addCacheListener(listener);

但未执行sysout。为了测试它,我只是运行一个简单的Main值。 这是我正在使用的配置值:

<jbosscache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:jboss:jbosscache-core:config:3.2">


    <transaction transactionManagerLookupClass="org.jboss.cache.transaction.GenericTransactionManagerLookup"/>


    <eviction wakeUpInterval="20">
        <default algorithmClass="org.jboss.cache.eviction.FIFOAlgorithm" wakeUpInterval="20">
            <property name="maxNodes" value="20" />         
        </default>           
    </eviction>

</jbosscache>

1 个答案:

答案 0 :(得分:0)

问题解决了,因为我没有阅读XML配置文件。

我失踪了:

factory.createCache(file);