KickJava   Java API By Example, From Geeks To Geeks.

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


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.config.ConfigurationException;
10 import org.jboss.cache.config.Dynamic;
11
12 /**
13  * Configuration for {@link ElementSizePolicy}.
14  * <p/>
15  * If configured via XML, expects the following:
16  * <p/>
17  * <pre>
18  * <region name="/region/">
19  * <attribute name="maxElementsPerNode">100</attribute>
20  * <attribute name="maxNodes">10000</attribute>
21  * </region>
22  * </pre>
23  *
24  * Requires a positive "maxElementsPerNode" value otherwise a ConfigurationException is thrown.
25  *
26  * @author Daniel Huang
27  * @author Brian Stansberry
28  *
29  * @version $Revision: 1.5 $
30  */

31 public class ElementSizeConfiguration extends EvictionPolicyConfigBase
32 {
33    /** The serialVersionUID */
34    private static final long serialVersionUID = 2510593544656833758L;
35    
36    @Dynamic
37    private int maxElementsPerNode;
38
39    public ElementSizeConfiguration()
40    {
41       setEvictionPolicyClassName();
42       // Force configuration of maxElementsPerNode
43
setMaxElementsPerNode(-1);
44    }
45
46    @Override JavaDoc
47    protected void setEvictionPolicyClassName()
48    {
49       setEvictionPolicyClass(ElementSizePolicy.class.getName());
50    }
51    
52    public int getMaxElementsPerNode()
53    {
54       return maxElementsPerNode;
55    }
56
57    public void setMaxElementsPerNode(int maxElementsPerNode)
58    {
59       testImmutability("maxElementsPerNode");
60       this.maxElementsPerNode = maxElementsPerNode;
61    }
62    
63    /**
64     * Requires a positive maxElementsPerNode value or ConfigurationException
65     * is thrown.
66     */

67    @Override JavaDoc
68    public void validate() throws ConfigurationException
69    {
70       if (maxElementsPerNode < 0) throw new ConfigurationException("maxElementsPerNode must be configured");
71    }
72
73    public String JavaDoc toString()
74    {
75       StringBuffer JavaDoc str = new StringBuffer JavaDoc();
76       str.append("ElementSizeConfiguration: maxElementsPerNode =");
77       str.append(getMaxElementsPerNode()).append(" maxNodes =").append(getMaxNodes());
78       return str.toString();
79    }
80
81    @Override JavaDoc
82    public boolean equals(Object JavaDoc obj)
83    {
84       if (this == obj)
85          return true;
86       if (obj instanceof ElementSizeConfiguration && super.equals(obj))
87       {
88          return this.maxElementsPerNode == ((ElementSizeConfiguration) obj).maxElementsPerNode;
89       }
90       return false;
91    }
92
93    @Override JavaDoc
94    public int hashCode()
95    {
96       int result = super.hashCode();
97       result = 31 * result + maxElementsPerNode;
98       return result;
99    }
100
101    @Override JavaDoc
102    public void reset()
103    {
104       super.reset();
105       setMaxElementsPerNode(-1);
106    }
107 }
108
Popular Tags