KickJava   Java API By Example, From Geeks To Geeks.

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


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.apache.commons.logging.Log;
10 import org.apache.commons.logging.LogFactory;
11 import org.jboss.cache.Region;
12
13 /**
14  * First-in-first-out algorithm used to evict nodes.
15  *
16  * @author Daniel Huang - dhuang@jboss.org
17  * @author Morten Kvistgaard
18  * @version $Revision: 1.7 $
19  */

20 public class FIFOAlgorithm extends BaseEvictionAlgorithm
21 {
22    private static final Log log = LogFactory.getLog(FIFOAlgorithm.class);
23
24
25    public FIFOAlgorithm()
26    {
27       super();
28    }
29
30    protected EvictionQueue setupEvictionQueue(Region region) throws EvictionException
31    {
32       return new FIFOQueue();
33    }
34
35    /**
36     * For FIFO, a node should be evicted if the queue size is >= to the configured maxNodes size.
37     */

38    protected boolean shouldEvictNode(NodeEntry ne)
39    {
40       FIFOConfiguration config = (FIFOConfiguration) region.getEvictionPolicyConfig();
41       if (log.isTraceEnabled())
42       {
43          log.trace("Deciding whether node in queue " + ne.getFqn() + " requires eviction.");
44       }
45
46       int size = this.getEvictionQueue().getNumberOfNodes();
47       return config.getMaxNodes() != 0 && size > config.getMaxNodes();
48
49    }
50
51 }
52
53
Popular Tags