%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.jcs.engine.CompositeCacheAttributes |
|
|
1 | package org.apache.jcs.engine; |
|
2 | ||
3 | /* |
|
4 | * Licensed to the Apache Software Foundation (ASF) under one |
|
5 | * or more contributor license agreements. See the NOTICE file |
|
6 | * distributed with this work for additional information |
|
7 | * regarding copyright ownership. The ASF licenses this file |
|
8 | * to you under the Apache License, Version 2.0 (the |
|
9 | * "License"); you may not use this file except in compliance |
|
10 | * with the License. You may obtain a copy of the License at |
|
11 | * |
|
12 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
13 | * |
|
14 | * Unless required by applicable law or agreed to in writing, |
|
15 | * software distributed under the License is distributed on an |
|
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|
17 | * KIND, either express or implied. See the License for the |
|
18 | * specific language governing permissions and limitations |
|
19 | * under the License. |
|
20 | */ |
|
21 | ||
22 | import org.apache.jcs.engine.behavior.ICompositeCacheAttributes; |
|
23 | ||
24 | /** |
|
25 | * The CompositeCacheAttributes defines the general cache region settings. If a region is not |
|
26 | * explicitly defined in the cache.ccf then it inherits the cache default settings. |
|
27 | * <p> |
|
28 | * If all the default attributes are not defined in the default region definition in the cache.ccf, |
|
29 | * the hard coded defaults will be used. |
|
30 | */ |
|
31 | public class CompositeCacheAttributes |
|
32 | implements ICompositeCacheAttributes, Cloneable |
|
33 | { |
|
34 | private static final long serialVersionUID = 6754049978134196787L; |
|
35 | ||
36 | private static final boolean DEFAULT_USE_LATERAL = true; |
|
37 | ||
38 | private static final boolean DEFAULT_USE_REMOTE = true; |
|
39 | ||
40 | private static final boolean DEFAULT_USE_DISK = true; |
|
41 | ||
42 | private static final boolean DEFAULT_USE_SHRINKER = false; |
|
43 | ||
44 | private static final int DEFAULT_MAX_OBJECTS = 100; |
|
45 | ||
46 | private static final int DEFAULT_MAX_MEMORY_IDLE_TIME_SECONDS = 60 * 120; |
|
47 | ||
48 | private static final int DEFAULT_SHRINKER_INTERVAL_SECONDS = 30; |
|
49 | ||
50 | private static final int DEFAULT_MAX_SPOOL_PER_RUN = -1; |
|
51 | ||
52 | private static final String DEFAULT_MEMORY_CACHE_NAME = "org.apache.jcs.engine.memory.lru.LRUMemoryCache"; |
|
53 | ||
54 | 980 | private boolean useLateral = DEFAULT_USE_LATERAL; |
55 | ||
56 | 980 | private boolean useRemote = DEFAULT_USE_REMOTE; |
57 | ||
58 | /** Whether we should use a disk cache if it is configured. */ |
|
59 | 980 | private boolean useDisk = DEFAULT_USE_DISK; |
60 | ||
61 | /** Whether or not we should run the memory shrinker thread. */ |
|
62 | 980 | private boolean useMemoryShrinker = DEFAULT_USE_SHRINKER; |
63 | ||
64 | /** The maximum objects that the memory cache will be allowed to hold. */ |
|
65 | 980 | private int maxObjs = DEFAULT_MAX_OBJECTS; |
66 | ||
67 | /** maxMemoryIdleTimeSeconds */ |
|
68 | 980 | private long maxMemoryIdleTimeSeconds = DEFAULT_MAX_MEMORY_IDLE_TIME_SECONDS; |
69 | ||
70 | /** shrinkerIntervalSeconds */ |
|
71 | 980 | private long shrinkerIntervalSeconds = DEFAULT_SHRINKER_INTERVAL_SECONDS; |
72 | ||
73 | /** The maximum number the shrinker will spool to disk per run. */ |
|
74 | 980 | private int maxSpoolPerRun = DEFAULT_MAX_SPOOL_PER_RUN; |
75 | ||
76 | /** The name of this cache region. */ |
|
77 | private String cacheName; |
|
78 | ||
79 | /** The name of the memory cache implementation class. */ |
|
80 | private String memoryCacheName; |
|
81 | ||
82 | 980 | private short diskUsagePattern = DISK_USAGE_PATTERN_SWAP; |
83 | ||
84 | /** |
|
85 | * Constructor for the CompositeCacheAttributes object |
|
86 | */ |
|
87 | public CompositeCacheAttributes() |
|
88 | { |
|
89 | 980 | super(); |
90 | // set this as the default so the configuration is a bit simpler |
|
91 | 980 | memoryCacheName = DEFAULT_MEMORY_CACHE_NAME; |
92 | 980 | } |
93 | ||
94 | /** |
|
95 | * Sets the maxObjects attribute of the CompositeCacheAttributes object |
|
96 | * <p> |
|
97 | * @param maxObjs The new maxObjects value |
|
98 | */ |
|
99 | public void setMaxObjects( int maxObjs ) |
|
100 | { |
|
101 | 653 | this.maxObjs = maxObjs; |
102 | 653 | } |
103 | ||
104 | /** |
|
105 | * Gets the maxObjects attribute of the CompositeCacheAttributes object |
|
106 | * <p> |
|
107 | * @return The maxObjects value |
|
108 | */ |
|
109 | public int getMaxObjects() |
|
110 | { |
|
111 | 2460969 | return this.maxObjs; |
112 | } |
|
113 | ||
114 | /** |
|
115 | * Sets the useDisk attribute of the CompositeCacheAttributes object |
|
116 | * <p> |
|
117 | * @param useDisk The new useDisk value |
|
118 | */ |
|
119 | public void setUseDisk( boolean useDisk ) |
|
120 | { |
|
121 | 0 | this.useDisk = useDisk; |
122 | 0 | } |
123 | ||
124 | /** |
|
125 | * Gets the useDisk attribute of the CompositeCacheAttributes object |
|
126 | * <p> |
|
127 | * @return The useDisk value |
|
128 | */ |
|
129 | public boolean getUseDisk() |
|
130 | { |
|
131 | 965051 | return useDisk; |
132 | } |
|
133 | ||
134 | /** |
|
135 | * Sets the useLateral attribute of the CompositeCacheAttributes object |
|
136 | * <p> |
|
137 | * @param b The new useLateral value |
|
138 | */ |
|
139 | public void setUseLateral( boolean b ) |
|
140 | { |
|
141 | 0 | this.useLateral = b; |
142 | 0 | } |
143 | ||
144 | /** |
|
145 | * Gets the useLateral attribute of the CompositeCacheAttributes object |
|
146 | * <p> |
|
147 | * @return The useLateral value |
|
148 | */ |
|
149 | public boolean getUseLateral() |
|
150 | { |
|
151 | 46 | return this.useLateral; |
152 | } |
|
153 | ||
154 | /** |
|
155 | * Sets the useRemote attribute of the CompositeCacheAttributes object |
|
156 | * <p> |
|
157 | * @param useRemote The new useRemote value |
|
158 | */ |
|
159 | public void setUseRemote( boolean useRemote ) |
|
160 | { |
|
161 | 0 | this.useRemote = useRemote; |
162 | 0 | } |
163 | ||
164 | /** |
|
165 | * Gets the useRemote attribute of the CompositeCacheAttributes object |
|
166 | * <p> |
|
167 | * @return The useRemote value |
|
168 | */ |
|
169 | public boolean getUseRemote() |
|
170 | { |
|
171 | 0 | return this.useRemote; |
172 | } |
|
173 | ||
174 | /** |
|
175 | * Sets the cacheName attribute of the CompositeCacheAttributes object |
|
176 | * <p> |
|
177 | * @param s The new cacheName value |
|
178 | */ |
|
179 | public void setCacheName( String s ) |
|
180 | { |
|
181 | 5283 | this.cacheName = s; |
182 | 5283 | } |
183 | ||
184 | /** |
|
185 | * Gets the cacheName attribute of the CompositeCacheAttributes object |
|
186 | * <p> |
|
187 | * @return The cacheName value |
|
188 | */ |
|
189 | public String getCacheName() |
|
190 | { |
|
191 | 4351 | return this.cacheName; |
192 | } |
|
193 | ||
194 | /** |
|
195 | * Sets the memoryCacheName attribute of the CompositeCacheAttributes object |
|
196 | * <p> |
|
197 | * @param s The new memoryCacheName value |
|
198 | */ |
|
199 | public void setMemoryCacheName( String s ) |
|
200 | { |
|
201 | 683 | this.memoryCacheName = s; |
202 | 683 | } |
203 | ||
204 | /** |
|
205 | * Gets the memoryCacheName attribute of the CompositeCacheAttributes object |
|
206 | * <p> |
|
207 | * @return The memoryCacheName value |
|
208 | */ |
|
209 | public String getMemoryCacheName() |
|
210 | { |
|
211 | 683 | return this.memoryCacheName; |
212 | } |
|
213 | ||
214 | /** |
|
215 | * Whether the memory cache should perform background memory shrinkage. |
|
216 | * <p> |
|
217 | * @param useShrinker The new UseMemoryShrinker value |
|
218 | */ |
|
219 | public void setUseMemoryShrinker( boolean useShrinker ) |
|
220 | { |
|
221 | 52 | this.useMemoryShrinker = useShrinker; |
222 | 52 | } |
223 | ||
224 | /** |
|
225 | * Whether the memory cache should perform background memory shrinkage. |
|
226 | * <p> |
|
227 | * @return The UseMemoryShrinker value |
|
228 | */ |
|
229 | public boolean getUseMemoryShrinker() |
|
230 | { |
|
231 | 676 | return this.useMemoryShrinker; |
232 | } |
|
233 | ||
234 | /** |
|
235 | * If UseMemoryShrinker is true the memory cache should auto-expire elements to reclaim space. |
|
236 | * <p> |
|
237 | * @param seconds The new MaxMemoryIdleTimeSeconds value |
|
238 | */ |
|
239 | public void setMaxMemoryIdleTimeSeconds( long seconds ) |
|
240 | { |
|
241 | 92 | this.maxMemoryIdleTimeSeconds = seconds; |
242 | 92 | } |
243 | ||
244 | /** |
|
245 | * If UseMemoryShrinker is true the memory cache should auto-expire elements to reclaim space. |
|
246 | * <p> |
|
247 | * @return The MaxMemoryIdleTimeSeconds value |
|
248 | */ |
|
249 | public long getMaxMemoryIdleTimeSeconds() |
|
250 | { |
|
251 | 104 | return this.maxMemoryIdleTimeSeconds; |
252 | } |
|
253 | ||
254 | /** |
|
255 | * If UseMemoryShrinker is true the memory cache should auto-expire elements to reclaim space. |
|
256 | * This sets the shrinker interval. |
|
257 | * <p> |
|
258 | * @param seconds The new ShrinkerIntervalSeconds value |
|
259 | */ |
|
260 | public void setShrinkerIntervalSeconds( long seconds ) |
|
261 | { |
|
262 | 52 | this.shrinkerIntervalSeconds = seconds; |
263 | 52 | } |
264 | ||
265 | /** |
|
266 | * If UseMemoryShrinker is true the memory cache should auto-expire elements to reclaim space. |
|
267 | * This gets the shrinker interval. |
|
268 | * <p> |
|
269 | * @return The ShrinkerIntervalSeconds value |
|
270 | */ |
|
271 | public long getShrinkerIntervalSeconds() |
|
272 | { |
|
273 | 48 | return this.shrinkerIntervalSeconds; |
274 | } |
|
275 | ||
276 | /** |
|
277 | * If UseMemoryShrinker is true the memory cache should auto-expire elements to reclaim space. |
|
278 | * This sets the maximum number of items to spool per run. |
|
279 | * <p> |
|
280 | * If the value is -1, then there is no limit to the number of items to be spooled. |
|
281 | * <p> |
|
282 | * @param maxSpoolPerRun The new maxSpoolPerRun value |
|
283 | */ |
|
284 | public void setMaxSpoolPerRun( int maxSpoolPerRun ) |
|
285 | { |
|
286 | 24 | this.maxSpoolPerRun = maxSpoolPerRun; |
287 | 24 | } |
288 | ||
289 | /** |
|
290 | * If UseMemoryShrinker is true the memory cache should auto-expire elements to reclaim space. |
|
291 | * This gets the maximum number of items to spool per run. |
|
292 | * <p> |
|
293 | * @return The maxSpoolPerRun value |
|
294 | */ |
|
295 | public int getMaxSpoolPerRun() |
|
296 | { |
|
297 | 72 | return this.maxSpoolPerRun; |
298 | } |
|
299 | ||
300 | /** |
|
301 | * By default this is SWAP_ONLY. |
|
302 | * <p> |
|
303 | * @param diskUsagePattern The diskUsagePattern to set. |
|
304 | */ |
|
305 | public void setDiskUsagePattern( short diskUsagePattern ) |
|
306 | { |
|
307 | 56 | this.diskUsagePattern = diskUsagePattern; |
308 | 56 | } |
309 | ||
310 | /** |
|
311 | * Translates the name to the disk usage pattern short value. |
|
312 | * <p> |
|
313 | * The allowed values are SWAP and UPDATE. |
|
314 | * <p> |
|
315 | * @param diskUsagePatternName The diskUsagePattern to set. |
|
316 | */ |
|
317 | public void setDiskUsagePatternName( String diskUsagePatternName ) |
|
318 | { |
|
319 | 14 | if ( diskUsagePatternName != null ) |
320 | { |
|
321 | 14 | diskUsagePatternName = diskUsagePatternName.toUpperCase().trim(); |
322 | 14 | if ( diskUsagePatternName.startsWith( "SWAP" ) ) |
323 | { |
|
324 | 7 | this.setDiskUsagePattern( DISK_USAGE_PATTERN_SWAP ); |
325 | 7 | } |
326 | 7 | else if ( diskUsagePatternName.startsWith( "UPDATE" ) ) |
327 | { |
|
328 | 7 | this.setDiskUsagePattern( DISK_USAGE_PATTERN_UPDATE ); |
329 | } |
|
330 | } |
|
331 | 14 | } |
332 | ||
333 | /** |
|
334 | * @return Returns the diskUsagePattern. |
|
335 | */ |
|
336 | public short getDiskUsagePattern() |
|
337 | { |
|
338 | 1750187 | return diskUsagePattern; |
339 | } |
|
340 | ||
341 | /** |
|
342 | * Description of the Method |
|
343 | * <p> |
|
344 | * @return |
|
345 | */ |
|
346 | public ICompositeCacheAttributes copy() |
|
347 | { |
|
348 | try |
|
349 | { |
|
350 | 3726 | ICompositeCacheAttributes cattr = (CompositeCacheAttributes) this.clone(); |
351 | 3726 | return cattr; |
352 | } |
|
353 | 0 | catch ( Exception e ) |
354 | { |
|
355 | 0 | System.err.println( e.toString() ); |
356 | 0 | return new CompositeCacheAttributes(); |
357 | } |
|
358 | } |
|
359 | ||
360 | /** |
|
361 | * Dumps the core attributes. |
|
362 | * <p> |
|
363 | * @return For debugging. |
|
364 | */ |
|
365 | public String toString() |
|
366 | { |
|
367 | 942 | StringBuffer dump = new StringBuffer(); |
368 | ||
369 | 942 | dump.append( "[ " ); |
370 | 942 | dump.append( "useLateral = " ).append( useLateral ); |
371 | 942 | dump.append( ", useRemote = " ).append( useRemote ); |
372 | 942 | dump.append( ", useDisk = " ).append( useDisk ); |
373 | 942 | dump.append( ", maxObjs = " ).append( maxObjs ); |
374 | 942 | dump.append( ", maxSpoolPerRun = " ).append( maxSpoolPerRun ); |
375 | 942 | dump.append( ", diskUsagePattern = " ).append( diskUsagePattern ); |
376 | 942 | dump.append( " ]" ); |
377 | ||
378 | 942 | return dump.toString(); |
379 | } |
|
380 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |