1 package org.apache.commons.jcs3.engine;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.commons.jcs3.engine.behavior.ICompositeCacheAttributes;
23
24
25
26
27
28
29
30
31 public class CompositeCacheAttributes
32 implements ICompositeCacheAttributes
33 {
34
35 private static final long serialVersionUID = 6754049978134196787L;
36
37
38 private static final boolean DEFAULT_USE_LATERAL = true;
39
40
41 private static final boolean DEFAULT_USE_REMOTE = true;
42
43
44 private static final boolean DEFAULT_USE_DISK = true;
45
46
47 private static final boolean DEFAULT_USE_SHRINKER = false;
48
49
50 private static final int DEFAULT_MAX_OBJECTS = 100;
51
52
53 private static final int DEFAULT_MAX_MEMORY_IDLE_TIME_SECONDS = 60 * 120;
54
55
56 private static final int DEFAULT_SHRINKER_INTERVAL_SECONDS = 30;
57
58
59 private static final int DEFAULT_MAX_SPOOL_PER_RUN = -1;
60
61
62 private static final String DEFAULT_MEMORY_CACHE_NAME = "org.apache.commons.jcs3.engine.memory.lru.LRUMemoryCache";
63
64
65 private static final int DEFAULT_CHUNK_SIZE = 2;
66
67
68 private boolean useLateral = DEFAULT_USE_LATERAL;
69
70
71 private boolean useRemote = DEFAULT_USE_REMOTE;
72
73
74 private boolean useDisk = DEFAULT_USE_DISK;
75
76
77 private boolean useMemoryShrinker = DEFAULT_USE_SHRINKER;
78
79
80 private int maxObjs = DEFAULT_MAX_OBJECTS;
81
82
83 private long maxMemoryIdleTimeSeconds = DEFAULT_MAX_MEMORY_IDLE_TIME_SECONDS;
84
85
86 private long shrinkerIntervalSeconds = DEFAULT_SHRINKER_INTERVAL_SECONDS;
87
88
89 private int maxSpoolPerRun = DEFAULT_MAX_SPOOL_PER_RUN;
90
91
92 private String cacheName;
93
94
95 private String memoryCacheName;
96
97
98 private DiskUsagePattern diskUsagePattern = DiskUsagePattern.SWAP;
99
100
101 private int spoolChunkSize = DEFAULT_CHUNK_SIZE;
102
103
104
105
106 public CompositeCacheAttributes()
107 {
108
109 memoryCacheName = DEFAULT_MEMORY_CACHE_NAME;
110 }
111
112
113
114
115
116
117 @Override
118 public void setMaxObjects( final int maxObjs )
119 {
120 this.maxObjs = maxObjs;
121 }
122
123
124
125
126
127
128 @Override
129 public int getMaxObjects()
130 {
131 return this.maxObjs;
132 }
133
134
135
136
137
138
139 @Override
140 public void setUseDisk( final boolean useDisk )
141 {
142 this.useDisk = useDisk;
143 }
144
145
146
147
148
149
150 @Override
151 public boolean isUseDisk()
152 {
153 return useDisk;
154 }
155
156
157
158
159
160
161 @Override
162 public void setUseLateral( final boolean b )
163 {
164 this.useLateral = b;
165 }
166
167
168
169
170
171
172 @Override
173 public boolean isUseLateral()
174 {
175 return this.useLateral;
176 }
177
178
179
180
181
182
183 @Override
184 public void setUseRemote( final boolean useRemote )
185 {
186 this.useRemote = useRemote;
187 }
188
189
190
191
192
193
194 @Override
195 public boolean isUseRemote()
196 {
197 return this.useRemote;
198 }
199
200
201
202
203
204
205 @Override
206 public void setCacheName( final String s )
207 {
208 this.cacheName = s;
209 }
210
211
212
213
214
215
216 @Override
217 public String getCacheName()
218 {
219 return this.cacheName;
220 }
221
222
223
224
225
226
227 @Override
228 public void setMemoryCacheName( final String s )
229 {
230 this.memoryCacheName = s;
231 }
232
233
234
235
236
237
238 @Override
239 public String getMemoryCacheName()
240 {
241 return this.memoryCacheName;
242 }
243
244
245
246
247
248
249 @Override
250 public void setUseMemoryShrinker( final boolean useShrinker )
251 {
252 this.useMemoryShrinker = useShrinker;
253 }
254
255
256
257
258
259
260 @Override
261 public boolean isUseMemoryShrinker()
262 {
263 return this.useMemoryShrinker;
264 }
265
266
267
268
269
270
271 @Override
272 public void setMaxMemoryIdleTimeSeconds( final long seconds )
273 {
274 this.maxMemoryIdleTimeSeconds = seconds;
275 }
276
277
278
279
280
281
282 @Override
283 public long getMaxMemoryIdleTimeSeconds()
284 {
285 return this.maxMemoryIdleTimeSeconds;
286 }
287
288
289
290
291
292
293
294 @Override
295 public void setShrinkerIntervalSeconds( final long seconds )
296 {
297 this.shrinkerIntervalSeconds = seconds;
298 }
299
300
301
302
303
304
305
306 @Override
307 public long getShrinkerIntervalSeconds()
308 {
309 return this.shrinkerIntervalSeconds;
310 }
311
312
313
314
315
316
317
318
319
320 @Override
321 public void setMaxSpoolPerRun( final int maxSpoolPerRun )
322 {
323 this.maxSpoolPerRun = maxSpoolPerRun;
324 }
325
326
327
328
329
330
331
332 @Override
333 public int getMaxSpoolPerRun()
334 {
335 return this.maxSpoolPerRun;
336 }
337
338
339
340
341
342
343 @Override
344 public void setDiskUsagePattern( final DiskUsagePattern diskUsagePattern )
345 {
346 this.diskUsagePattern = diskUsagePattern;
347 }
348
349
350
351
352
353
354
355
356 @Override
357 public void setDiskUsagePatternName( final String diskUsagePatternName )
358 {
359 if ( diskUsagePatternName != null )
360 {
361 final String name = diskUsagePatternName.toUpperCase().trim();
362 if ( name.startsWith( "SWAP" ) )
363 {
364 this.setDiskUsagePattern( DiskUsagePattern.SWAP );
365 }
366 else if ( name.startsWith( "UPDATE" ) )
367 {
368 this.setDiskUsagePattern( DiskUsagePattern.UPDATE );
369 }
370 }
371 }
372
373
374
375
376
377
378 @Override
379 public int getSpoolChunkSize()
380 {
381 return spoolChunkSize;
382 }
383
384
385
386
387
388
389 @Override
390 public void setSpoolChunkSize( final int spoolChunkSize )
391 {
392 this.spoolChunkSize = spoolChunkSize;
393 }
394
395
396
397
398 @Override
399 public DiskUsagePattern getDiskUsagePattern()
400 {
401 return diskUsagePattern;
402 }
403
404
405
406
407
408
409 @Override
410 public String toString()
411 {
412 final StringBuilder dump = new StringBuilder();
413
414 dump.append( "[ " );
415 dump.append( "useLateral = " ).append( useLateral );
416 dump.append( ", useRemote = " ).append( useRemote );
417 dump.append( ", useDisk = " ).append( useDisk );
418 dump.append( ", maxObjs = " ).append( maxObjs );
419 dump.append( ", maxSpoolPerRun = " ).append( maxSpoolPerRun );
420 dump.append( ", diskUsagePattern = " ).append( diskUsagePattern );
421 dump.append( ", spoolChunkSize = " ).append( spoolChunkSize );
422 dump.append( " ]" );
423
424 return dump.toString();
425 }
426
427
428
429
430 @Override
431 public ICompositeCacheAttributes clone()
432 {
433 try
434 {
435 return (ICompositeCacheAttributes)super.clone();
436 }
437 catch (final CloneNotSupportedException e)
438 {
439 throw new RuntimeException("Clone not supported. This should never happen.", e);
440 }
441 }
442 }