Question

I am new on JBossCache. Reading the user documentation it says that a listener could be added to the Eviction class used, but I wasn't able to found how to do add one to the configuration file, or how that should be added.

I have tried to add an @CacheListener with a method @NodeEvicted, but that method

@CacheListener
public class EvictionListener {

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

and add it to the cache instance

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

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

but the sysout isn't executed. For testing it, I am just running a simple Main value. This is the configuration value I am using:

<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>
Was it helpful?

Solution

The problem was solved because I wasn't reading the XML configuration file.

I was missing:

factory.createCache(file);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top