View Javadoc
1   package org.apache.commons.jcs3.auxiliary.disk.block;
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.commons.jcs3.auxiliary.disk.AbstractDiskCacheAttributes;
23  
24  /**
25   * This holds attributes for Block Disk Cache configuration.
26   */
27  public class BlockDiskCacheAttributes
28      extends AbstractDiskCacheAttributes
29  {
30      /** Don't change */
31      private static final long serialVersionUID = 6568840097657265989L;
32  
33      /** The size per block in bytes. */
34      private int blockSizeBytes;
35  
36      /** Maximum number of keys to be kept in memory */
37      private static final int DEFAULT_MAX_KEY_SIZE = 5000;
38  
39      /** -1 means no limit. */
40      private int maxKeySize = DEFAULT_MAX_KEY_SIZE;
41  
42      /** How often should we persist the keys. */
43      private static final long DEFAULT_KEY_PERSISTENCE_INTERVAL_SECONDS = 5 * 60;
44  
45      /** The keys will be persisted at this interval.  -1 mean never. */
46      private long keyPersistenceIntervalSeconds = DEFAULT_KEY_PERSISTENCE_INTERVAL_SECONDS;
47  
48      /**
49       * The size of the blocks. All blocks are the same size.
50       * <p>
51       * @param blockSizeBytes The blockSizeBytes to set.
52       */
53      public void setBlockSizeBytes( final int blockSizeBytes )
54      {
55          this.blockSizeBytes = blockSizeBytes;
56      }
57  
58      /**
59       * @return Returns the blockSizeBytes.
60       */
61      public int getBlockSizeBytes()
62      {
63          return blockSizeBytes;
64      }
65  
66      /**
67       * @param maxKeySize The maxKeySize to set.
68       */
69      public void setMaxKeySize( final int maxKeySize )
70      {
71          this.maxKeySize = maxKeySize;
72      }
73  
74      /**
75       * @return Returns the maxKeySize.
76       */
77      public int getMaxKeySize()
78      {
79          return maxKeySize;
80      }
81  
82      /**
83       * @param keyPersistenceIntervalSeconds The keyPersistenceIntervalSeconds to set.
84       */
85      public void setKeyPersistenceIntervalSeconds( final long keyPersistenceIntervalSeconds )
86      {
87          this.keyPersistenceIntervalSeconds = keyPersistenceIntervalSeconds;
88      }
89  
90      /**
91       * @return Returns the keyPersistenceIntervalSeconds.
92       */
93      public long getKeyPersistenceIntervalSeconds()
94      {
95          return keyPersistenceIntervalSeconds;
96      }
97  
98      /**
99       * 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 }