1 package org.apache.jcs.auxiliary.disk.indexed;
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.auxiliary.AuxiliaryCacheAttributes;
23 import org.apache.jcs.auxiliary.disk.AbstractDiskCacheAttributes;
24
25 /**
26 * Configuration class for the Indexed Disk Cache
27 */
28 public class IndexedDiskCacheAttributes
29 extends AbstractDiskCacheAttributes
30 {
31 /** Don't change. */
32 private static final long serialVersionUID = -2190863599358782950L;
33
34 /** default value */
35 private static final int DEFAULT_maxKeySize = 5000;
36
37 /** -1 means no limit. */
38 private int maxKeySize = DEFAULT_maxKeySize;
39
40 /** default value */
41 private static final int DEFAULT_maxRecycleBinSize = 5000;
42
43 /**
44 * Cannot be larger than the max size. If max is less than 0, this will be 5000
45 */
46 private int maxRecycleBinSize = DEFAULT_maxRecycleBinSize;
47
48 /** default to -1, i.e., don't optimize until shutdown */
49 private int optimizeAtRemoveCount = -1;
50
51 /** Should we optimize on shutdown. */
52 public static final boolean DEFAULT_OPTIMIZE_ON_SHUTDOWN = true;
53
54 /** Should we optimize on shutdown. */
55 private boolean optimizeOnShutdown = DEFAULT_OPTIMIZE_ON_SHUTDOWN;
56
57 /** Should we clear the disk on startup. */
58 public static final boolean DEFAULT_CLEAR_DISK_ON_STARTUP = false;
59
60 /** Should we clear the disk on startup. If true the congtents of disk are cleared. */
61 private boolean clearDiskOnStartup = DEFAULT_CLEAR_DISK_ON_STARTUP;
62
63 /**
64 * Constructor for the DiskCacheAttributes object
65 */
66 public IndexedDiskCacheAttributes()
67 {
68 super();
69 }
70
71 /**
72 * Gets the maxKeySize attribute of the DiskCacheAttributes object
73 * <p>
74 * @return The maxKeySize value
75 */
76 public int getMaxKeySize()
77 {
78 return this.maxKeySize;
79 }
80
81 /**
82 * Sets the maxKeySize attribute of the DiskCacheAttributes object
83 * <p>
84 * @param maxKeySize The new maxKeySize value
85 */
86 public void setMaxKeySize( int maxKeySize )
87 {
88 this.maxKeySize = maxKeySize;
89
90 // make sure the sizes are in accord with our rule.
91 setMaxRecycleBinSize( maxRecycleBinSize );
92 }
93
94 /**
95 * Gets the optimizeAtRemoveCount attribute of the DiskCacheAttributes object
96 * <p>
97 * @return The optimizeAtRemoveCount value
98 */
99 public int getOptimizeAtRemoveCount()
100 {
101 return this.optimizeAtRemoveCount;
102 }
103
104 /**
105 * Sets the optimizeAtRemoveCount attribute of the DiskCacheAttributes object This number
106 * determines how often the disk cache should run real time optimizations.
107 * <p>
108 * @param cnt The new optimizeAtRemoveCount value
109 */
110 public void setOptimizeAtRemoveCount( int cnt )
111 {
112 this.optimizeAtRemoveCount = cnt;
113 }
114
115 /**
116 * This cannot be larger than the maxKeySize. It wouldn't hurt anything, but it makes the config
117 * necessary. The recycle bin entry willbe at least as large as a key.
118 * <p>
119 * If the maxKeySize is -1 this will be set tot he default, which is 5000.
120 * <p>
121 * @param maxRecycleBinSize The maxRecycleBinSize to set.
122 */
123 public void setMaxRecycleBinSize( int maxRecycleBinSize )
124 {
125 this.maxRecycleBinSize = maxRecycleBinSize;
126 }
127
128 /**
129 * @return Returns the maxRecycleBinSize.
130 */
131 public int getMaxRecycleBinSize()
132 {
133 return maxRecycleBinSize;
134 }
135
136 /**
137 * @param optimizeOnShutdown The optimizeOnShutdown to set.
138 */
139 public void setOptimizeOnShutdown( boolean optimizeOnShutdown )
140 {
141 this.optimizeOnShutdown = optimizeOnShutdown;
142 }
143
144 /**
145 * @return Returns the optimizeOnShutdown.
146 */
147 public boolean isOptimizeOnShutdown()
148 {
149 return optimizeOnShutdown;
150 }
151
152 /**
153 * @param clearDiskOnStartup the clearDiskOnStartup to set
154 */
155 public void setClearDiskOnStartup( boolean clearDiskOnStartup )
156 {
157 this.clearDiskOnStartup = clearDiskOnStartup;
158 }
159
160 /**
161 * @return the clearDiskOnStartup
162 */
163 public boolean isClearDiskOnStartup()
164 {
165 return clearDiskOnStartup;
166 }
167
168 /**
169 * Returns a copy of the attributes.
170 * <p>
171 * @return AuxiliaryCacheAttributes
172 */
173 public AuxiliaryCacheAttributes copy()
174 {
175 try
176 {
177 return (AuxiliaryCacheAttributes) this.clone();
178 }
179 catch ( Exception e )
180 {
181 // swallow
182 }
183 return this;
184 }
185
186 /**
187 * Write out the values for debugging purposes.
188 * <p>
189 * @return String
190 */
191 public String toString()
192 {
193 StringBuffer str = new StringBuffer();
194 str.append( "IndexedDiskCacheAttributes " );
195 str.append( "\n diskPath = " + diskPath );
196 str.append( "\n maxPurgatorySize = " + maxPurgatorySize );
197 str.append( "\n maxKeySize = " + maxKeySize );
198 str.append( "\n maxRecycleBinSize = " + maxRecycleBinSize );
199 str.append( "\n optimizeAtRemoveCount = " + optimizeAtRemoveCount );
200 str.append( "\n shutdownSpoolTimeLimit = " + shutdownSpoolTimeLimit );
201 str.append( "\n optimizeOnShutdown = " + optimizeOnShutdown );
202 str.append( "\n clearDiskOnStartup = " + clearDiskOnStartup );
203 return str.toString();
204 }
205 }