KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > eviction > MRUAlgorithm


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.cache.eviction;
8
9 import org.jboss.cache.Fqn;
10 import org.jboss.cache.Region;
11
12 /**
13  * Most Recently Used Algorithm.
14  * <p/>
15  * This algorithm will evict the most recently used cache entries from cache.
16  * <p/>
17  * Note: None of the Eviction classes are thread safe. It is assumed that an individual instance of an EvictionPolicy/
18  * EvictionAlgorithm/EvictionQueue/EvictionConfiguration are only operated on by one thread at any given time.
19  *
20  * @author Daniel Huang (dhuang@jboss.org)
21  * @version $Revision: 1.4 $
22  */

23 public class MRUAlgorithm extends BaseEvictionAlgorithm
24 {
25    protected EvictionQueue setupEvictionQueue(Region region) throws EvictionException
26    {
27       return new MRUQueue();
28    }
29
30    protected boolean shouldEvictNode(NodeEntry ne)
31    {
32       MRUConfiguration config = (MRUConfiguration) region.getEvictionPolicyConfig();
33       return evictionQueue.getNumberOfNodes() > config.getMaxNodes();
34    }
35
36    protected void processVisitedNodes(Fqn fqn) throws EvictionException
37    {
38       super.processVisitedNodes(fqn);
39       ((MRUQueue) evictionQueue).moveToTopOfStack(fqn);
40    }
41 }
42
Popular Tags