001package org.apache.commons.jcs3.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
022import org.apache.commons.jcs3.auxiliary.disk.AbstractDiskCacheAttributes;
023
024/**
025 * Configuration class for the Indexed Disk Cache
026 */
027public class IndexedDiskCacheAttributes
028    extends AbstractDiskCacheAttributes
029{
030    /** Don't change. */
031    private static final long serialVersionUID = -2190863599358782950L;
032
033    /** default value */
034    private static final int DEFAULT_maxKeySize = 5000;
035
036    /** -1 means no limit. */
037    private int maxKeySize = DEFAULT_maxKeySize;
038
039    /** default to -1, i.e., don't optimize until shutdown */
040    private int optimizeAtRemoveCount = -1;
041
042    /** Should we optimize on shutdown. */
043    public static final boolean DEFAULT_OPTIMIZE_ON_SHUTDOWN = true;
044
045    /** Should we optimize on shutdown. */
046    private boolean optimizeOnShutdown = DEFAULT_OPTIMIZE_ON_SHUTDOWN;
047
048    /** Should we clear the disk on startup. */
049    public static final boolean DEFAULT_CLEAR_DISK_ON_STARTUP = false;
050
051    /** Should we clear the disk on startup. If true the contents of disk are cleared. */
052    private boolean clearDiskOnStartup = DEFAULT_CLEAR_DISK_ON_STARTUP;
053
054    /**
055     * Constructor for the DiskCacheAttributes object
056     */
057    public IndexedDiskCacheAttributes()
058    {
059    }
060
061    /**
062     * Gets the maxKeySize attribute of the DiskCacheAttributes object
063     * <p>
064     * @return The maxKeySize value
065     */
066    public int getMaxKeySize()
067    {
068        return this.maxKeySize;
069    }
070
071    /**
072     * Sets the maxKeySize attribute of the DiskCacheAttributes object
073     * <p>
074     * @param maxKeySize The new maxKeySize value
075     */
076    public void setMaxKeySize( final int maxKeySize )
077    {
078        this.maxKeySize = maxKeySize;
079    }
080
081    /**
082     * Gets the optimizeAtRemoveCount attribute of the DiskCacheAttributes object
083     * <p>
084     * @return The optimizeAtRemoveCount value
085     */
086    public int getOptimizeAtRemoveCount()
087    {
088        return this.optimizeAtRemoveCount;
089    }
090
091    /**
092     * Sets the optimizeAtRemoveCount attribute of the DiskCacheAttributes object This number
093     * determines how often the disk cache should run real time optimizations.
094     * <p>
095     * @param cnt The new optimizeAtRemoveCount value
096     */
097    public void setOptimizeAtRemoveCount( final int cnt )
098    {
099        this.optimizeAtRemoveCount = cnt;
100    }
101
102    /**
103     * @param optimizeOnShutdown The optimizeOnShutdown to set.
104     */
105    public void setOptimizeOnShutdown( final boolean optimizeOnShutdown )
106    {
107        this.optimizeOnShutdown = optimizeOnShutdown;
108    }
109
110    /**
111     * @return Returns the optimizeOnShutdown.
112     */
113    public boolean isOptimizeOnShutdown()
114    {
115        return optimizeOnShutdown;
116    }
117
118    /**
119     * @param clearDiskOnStartup the clearDiskOnStartup to set
120     */
121    public void setClearDiskOnStartup( final boolean clearDiskOnStartup )
122    {
123        this.clearDiskOnStartup = clearDiskOnStartup;
124    }
125
126    /**
127     * @return the clearDiskOnStartup
128     */
129    public boolean isClearDiskOnStartup()
130    {
131        return clearDiskOnStartup;
132    }
133
134    /**
135     * Write out the values for debugging purposes.
136     * <p>
137     * @return String
138     */
139    @Override
140    public String toString()
141    {
142        final StringBuilder str = new StringBuilder();
143        str.append( "IndexedDiskCacheAttributes " );
144        str.append( "\n diskPath = " + super.getDiskPath() );
145        str.append( "\n maxPurgatorySize   = " + super.getMaxPurgatorySize() );
146        str.append( "\n maxKeySize  = " + maxKeySize );
147        str.append( "\n optimizeAtRemoveCount  = " + optimizeAtRemoveCount );
148        str.append( "\n shutdownSpoolTimeLimit  = " + super.getShutdownSpoolTimeLimit() );
149        str.append( "\n optimizeOnShutdown  = " + optimizeOnShutdown );
150        str.append( "\n clearDiskOnStartup  = " + clearDiskOnStartup );
151        return str.toString();
152    }
153}