KickJava   Java API By Example, From Geeks To Geeks.

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


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.Region;
10
11
12 /**
13  * @author Daniel Huang
14  * @version $Revision: 1.3 $
15  */

16 public class ElementSizeAlgorithm extends BaseSortedEvictionAlgorithm
17 {
18    protected EvictionQueue setupEvictionQueue(Region region) throws EvictionException
19    {
20       return new ElementSizeQueue();
21    }
22
23    protected boolean shouldEvictNode(NodeEntry ne)
24    {
25       ElementSizeConfiguration config = (ElementSizeConfiguration) region.getEvictionPolicyConfig();
26
27       int size = this.getEvictionQueue().getNumberOfNodes();
28       if (config.getMaxNodes() != 0 && size > config.getMaxNodes())
29       {
30          return true;
31       }
32
33       return ne.getNumberOfElements() > config.getMaxElementsPerNode();
34    }
35
36
37    protected void prune() throws EvictionException
38    {
39       super.prune();
40
41       // clean up the Queue's eviction removals
42
((ElementSizeQueue) this.evictionQueue).prune();
43    }
44
45 }
46
Popular Tags