KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > config > EvictionConfig


1 /*
2  * JBoss, Home of Professional Open Source.
3  * Copyright 2006, Red Hat Middleware LLC, and individual contributors
4  * as indicated by the @author tags. See the copyright.txt file in the
5  * distribution for a full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.cache.config;
23
24 import org.jboss.cache.RegionManager;
25 import org.jboss.cache.eviction.EvictionPolicy;
26 import org.jboss.cache.eviction.EvictionPolicyConfig;
27
28 import java.util.Collections JavaDoc;
29 import java.util.List JavaDoc;
30
31 public class EvictionConfig extends ConfigurationComponent
32 {
33    /**
34     * The serialVersionUID
35     */

36    private static final long serialVersionUID = -7979639000026975201L;
37
38    public static final String JavaDoc WAKEUP_INTERVAL_SECONDS = "wakeUpIntervalSeconds";
39
40    public static final int WAKEUP_DEFAULT = 5;
41
42    public static final String JavaDoc EVENT_QUEUE_SIZE = "eventQueueSize";
43
44    public static final String JavaDoc EVICTION_POLICY_CLASS = "policyClass";
45
46    public static final int EVENT_QUEUE_SIZE_DEFAULT = 200000;
47
48    private String JavaDoc defaultEvictionPolicyClass;
49
50    private int wakeupIntervalSeconds = WAKEUP_DEFAULT;
51
52    private int defaultEventQueueSize = EVENT_QUEUE_SIZE_DEFAULT;
53
54    // Dynamic to support runtime adds/removes of regions
55
@Dynamic
56    private List JavaDoc<EvictionRegionConfig> evictionRegionConfigs;
57
58    public EvictionConfig()
59    {
60    }
61
62    public EvictionConfig(String JavaDoc defaultEvictionClass)
63    {
64       setDefaultEvictionPolicyClass(defaultEvictionClass);
65    }
66
67    public boolean isValidConfig()
68    {
69       return (defaultEvictionPolicyClass != null && defaultEvictionPolicyClass.length() > 0)
70               || (evictionRegionConfigs != null && evictionRegionConfigs.size() > 0);
71    }
72
73    public String JavaDoc getDefaultEvictionPolicyClass()
74    {
75       return defaultEvictionPolicyClass;
76    }
77
78    public void setDefaultEvictionPolicyClass(String JavaDoc defaultEvictionPolicyClass)
79    {
80       testImmutability("defaultEvictionPolicyClass");
81       this.defaultEvictionPolicyClass = defaultEvictionPolicyClass;
82    }
83
84    public List JavaDoc<EvictionRegionConfig> getEvictionRegionConfigs()
85    {
86       if (evictionRegionConfigs == null && defaultEvictionPolicyClass != null)
87       {
88          // TODO this needs to be refactored obviously ...
89
try
90          {
91             Class JavaDoc<EvictionPolicy> cpolicy = (Class JavaDoc<EvictionPolicy>) Class.forName(defaultEvictionPolicyClass);
92             EvictionPolicy policy;
93             policy = cpolicy.newInstance();
94             EvictionRegionConfig erc = new EvictionRegionConfig();
95             EvictionPolicyConfig epc = policy.getEvictionConfigurationClass().newInstance();
96             // epc.set
97
erc.setEvictionPolicyConfig(epc);
98             erc.setRegionFqn(RegionManager.DEFAULT_REGION);
99             return Collections.singletonList(erc);
100          }
101          catch (Exception JavaDoc e)
102          {
103             throw new ConfigurationException(e);
104          }
105       }
106       return evictionRegionConfigs;
107    }
108
109    public int getDefaultEventQueueSize()
110    {
111       return defaultEventQueueSize;
112    }
113
114    public void setDefaultEventQueueSize(int eventQueueSize)
115    {
116       this.defaultEventQueueSize = eventQueueSize;
117    }
118
119    public void setEvictionRegionConfigs(List JavaDoc<EvictionRegionConfig> evictionRegionConfigs)
120    {
121       testImmutability("evictionRegionConfigs");
122
123       // Make sure region configs built by MC have the event queue size
124
if (evictionRegionConfigs != null)
125       {
126          for (EvictionRegionConfig cfg : evictionRegionConfigs)
127          {
128             cfg.setDefaultEventQueueSize(getDefaultEventQueueSize());
129          }
130       }
131       replaceChildConfigs(this.evictionRegionConfigs, evictionRegionConfigs);
132       this.evictionRegionConfigs = evictionRegionConfigs;
133    }
134
135    public int getWakeupIntervalSeconds()
136    {
137       return wakeupIntervalSeconds;
138    }
139
140    public void setWakeupIntervalSeconds(int wakeupIntervalSeconds)
141    {
142       testImmutability("wakeupIntervalSeconds");
143       this.wakeupIntervalSeconds = wakeupIntervalSeconds;
144    }
145
146    public boolean equals(Object JavaDoc obj)
147    {
148       if (this == obj)
149          return true;
150
151       if (obj instanceof EvictionConfig)
152       {
153          EvictionConfig other = (EvictionConfig) obj;
154          return (this.wakeupIntervalSeconds == other.wakeupIntervalSeconds)
155                  && safeEquals(this.defaultEvictionPolicyClass, other.defaultEvictionPolicyClass)
156                  && safeEquals(this.evictionRegionConfigs, other.evictionRegionConfigs);
157       }
158       return false;
159    }
160
161    public int hashCode()
162    {
163       int result = 17;
164       result = 37 * result + wakeupIntervalSeconds;
165       result = 37 * result + (defaultEvictionPolicyClass == null ? 0 : defaultEvictionPolicyClass.hashCode());
166       result = 37 * result + (evictionRegionConfigs == null ? 0 : evictionRegionConfigs.hashCode());
167       return result;
168    }
169 }
170
Popular Tags