001    package org.apache.jcs.auxiliary.disk.indexed;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one
005     * or more contributor license agreements.  See the NOTICE file
006     * distributed with this work for additional information
007     * regarding copyright ownership.  The ASF licenses this file
008     * to you under the Apache License, Version 2.0 (the
009     * "License"); you may not use this file except in compliance
010     * with the License.  You may obtain a copy of the License at
011     *
012     *   http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing,
015     * software distributed under the License is distributed on an
016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017     * KIND, either express or implied.  See the License for the
018     * specific language governing permissions and limitations
019     * under the License.
020     */
021    
022    import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
023    import org.apache.jcs.auxiliary.disk.AbstractDiskCacheAttributes;
024    
025    /**
026     * Configuration class for the Indexed Disk Cache
027     */
028    public class IndexedDiskCacheAttributes
029        extends AbstractDiskCacheAttributes
030    {
031        /** Don't change. */
032        private static final long serialVersionUID = -2190863599358782950L;
033    
034        /** default value */
035        private static final int DEFAULT_maxKeySize = 5000;
036    
037        /** -1 means no limit. */
038        private int maxKeySize = DEFAULT_maxKeySize;
039    
040        /** default value */
041        private static final int DEFAULT_maxRecycleBinSize = 5000;
042    
043        /**
044         * Cannot be larger than the max size. If max is less than 0, this will be 5000
045         */
046        private int maxRecycleBinSize = DEFAULT_maxRecycleBinSize;
047    
048        /** default to -1, i.e., don't optimize until shutdown */
049        private int optimizeAtRemoveCount = -1;
050    
051        /** Should we optimize on shutdown. */
052        public static final boolean DEFAULT_OPTIMIZE_ON_SHUTDOWN = true;
053    
054        /** Should we optimize on shutdown. */
055        private boolean optimizeOnShutdown = DEFAULT_OPTIMIZE_ON_SHUTDOWN;
056    
057        /** Should we clear the disk on startup. */
058        public static final boolean DEFAULT_CLEAR_DISK_ON_STARTUP = false;
059    
060        /** Should we clear the disk on startup. If true the congtents of disk are cleared. */
061        private boolean clearDiskOnStartup = DEFAULT_CLEAR_DISK_ON_STARTUP;
062    
063        /**
064         * Constructor for the DiskCacheAttributes object
065         */
066        public IndexedDiskCacheAttributes()
067        {
068            super();
069        }
070    
071        /**
072         * Gets the maxKeySize attribute of the DiskCacheAttributes object
073         * <p>
074         * @return The maxKeySize value
075         */
076        public int getMaxKeySize()
077        {
078            return this.maxKeySize;
079        }
080    
081        /**
082         * Sets the maxKeySize attribute of the DiskCacheAttributes object
083         * <p>
084         * @param maxKeySize The new maxKeySize value
085         */
086        public void setMaxKeySize( int maxKeySize )
087        {
088            this.maxKeySize = maxKeySize;
089    
090            // make sure the sizes are in accord with our rule.
091            setMaxRecycleBinSize( maxRecycleBinSize );
092        }
093    
094        /**
095         * Gets the optimizeAtRemoveCount attribute of the DiskCacheAttributes object
096         * <p>
097         * @return The optimizeAtRemoveCount value
098         */
099        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        @Override
174        public AuxiliaryCacheAttributes copy()
175        {
176            try
177            {
178                return (AuxiliaryCacheAttributes) this.clone();
179            }
180            catch ( Exception e )
181            {
182                // swallow
183            }
184            return this;
185        }
186    
187        /**
188         * Write out the values for debugging purposes.
189         * <p>
190         * @return String
191         */
192        @Override
193        public String toString()
194        {
195            StringBuffer str = new StringBuffer();
196            str.append( "IndexedDiskCacheAttributes " );
197            str.append( "\n diskPath = " + diskPath );
198            str.append( "\n maxPurgatorySize   = " + maxPurgatorySize );
199            str.append( "\n maxKeySize  = " + maxKeySize );
200            str.append( "\n maxRecycleBinSize  = " + maxRecycleBinSize );
201            str.append( "\n optimizeAtRemoveCount  = " + optimizeAtRemoveCount );
202            str.append( "\n shutdownSpoolTimeLimit  = " + shutdownSpoolTimeLimit );
203            str.append( "\n optimizeOnShutdown  = " + optimizeOnShutdown );
204            str.append( "\n clearDiskOnStartup  = " + clearDiskOnStartup );
205            return str.toString();
206        }
207    }