001package org.apache.commons.jcs3.auxiliary.disk.block;
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 * This holds attributes for Block Disk Cache configuration.
026 */
027public class BlockDiskCacheAttributes
028    extends AbstractDiskCacheAttributes
029{
030    /** Don't change */
031    private static final long serialVersionUID = 6568840097657265989L;
032
033    /** The size per block in bytes. */
034    private int blockSizeBytes;
035
036    /** Maximum number of keys to be kept in memory */
037    private static final int DEFAULT_MAX_KEY_SIZE = 5000;
038
039    /** -1 means no limit. */
040    private int maxKeySize = DEFAULT_MAX_KEY_SIZE;
041
042    /** How often should we persist the keys. */
043    private static final long DEFAULT_KEY_PERSISTENCE_INTERVAL_SECONDS = 5 * 60;
044
045    /** The keys will be persisted at this interval.  -1 mean never. */
046    private long keyPersistenceIntervalSeconds = DEFAULT_KEY_PERSISTENCE_INTERVAL_SECONDS;
047
048    /**
049     * The size of the blocks. All blocks are the same size.
050     * <p>
051     * @param blockSizeBytes The blockSizeBytes to set.
052     */
053    public void setBlockSizeBytes( final int blockSizeBytes )
054    {
055        this.blockSizeBytes = blockSizeBytes;
056    }
057
058    /**
059     * @return Returns the blockSizeBytes.
060     */
061    public int getBlockSizeBytes()
062    {
063        return blockSizeBytes;
064    }
065
066    /**
067     * @param maxKeySize The maxKeySize to set.
068     */
069    public void setMaxKeySize( final int maxKeySize )
070    {
071        this.maxKeySize = maxKeySize;
072    }
073
074    /**
075     * @return Returns the maxKeySize.
076     */
077    public int getMaxKeySize()
078    {
079        return maxKeySize;
080    }
081
082    /**
083     * @param keyPersistenceIntervalSeconds The keyPersistenceIntervalSeconds to set.
084     */
085    public void setKeyPersistenceIntervalSeconds( final long keyPersistenceIntervalSeconds )
086    {
087        this.keyPersistenceIntervalSeconds = keyPersistenceIntervalSeconds;
088    }
089
090    /**
091     * @return Returns the keyPersistenceIntervalSeconds.
092     */
093    public long getKeyPersistenceIntervalSeconds()
094    {
095        return keyPersistenceIntervalSeconds;
096    }
097
098    /**
099     * Write out the values for debugging purposes.
100     * <p>
101     * @return String
102     */
103    @Override
104    public String toString()
105    {
106        final StringBuilder str = new StringBuilder();
107        str.append( "\nBlockDiskAttributes " );
108        str.append( "\n DiskPath [" + this.getDiskPath() + "]" );
109        str.append( "\n MaxKeySize [" + this.getMaxKeySize() + "]" );
110        str.append( "\n MaxPurgatorySize [" + this.getMaxPurgatorySize() + "]" );
111        str.append( "\n BlockSizeBytes [" + this.getBlockSizeBytes() + "]" );
112        str.append( "\n KeyPersistenceIntervalSeconds [" + this.getKeyPersistenceIntervalSeconds() + "]" );
113        str.append( "\n DiskLimitType [" + this.getDiskLimitType() + "]" );
114        return str.toString();
115    }
116}