View Javadoc

1   package org.apache.jcs.auxiliary.disk;
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.AbstractAuxiliaryCacheAttributes;
23  import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
24  import org.apache.jcs.auxiliary.disk.behavior.IDiskCacheAttributes;
25  
26  /**
27   * This has common attributes that any conceivable disk cache would need.
28   */
29  public abstract class AbstractDiskCacheAttributes
30      extends AbstractAuxiliaryCacheAttributes
31      implements IDiskCacheAttributes
32  {
33      /** Don't change. */
34      private static final long serialVersionUID = 8306631920391711229L;
35  
36      /** path to disk */
37      protected String diskPath;
38  
39      /** if this is false, we will not execute remove all */
40      private boolean allowRemoveAll = true;
41  
42      /** default to 5000 */
43      protected int maxPurgatorySize = MAX_PURGATORY_SIZE_DEFUALT;
44  
45      /** Default amount of time to allow for key persistence on shutdown */
46      private static final int DEFAULT_shutdownSpoolTimeLimit = 60;
47  
48      /**
49       * This default determines how long the shutdown will wait for the key spool and data defrag to
50       * finish.
51       */
52      protected int shutdownSpoolTimeLimit = DEFAULT_shutdownSpoolTimeLimit;
53  
54      /**
55       * Sets the diskPath attribute of the IJISPCacheAttributes object
56       * <p>
57       * @param path The new diskPath value
58       */
59      public void setDiskPath( String path )
60      {
61          this.diskPath = path.trim();
62      }
63  
64      /**
65       * Gets the diskPath attribute of the attributes object
66       * <p>
67       * @return The diskPath value
68       */
69      public String getDiskPath()
70      {
71          return this.diskPath;
72      }
73  
74      /**
75       * Gets the maxKeySize attribute of the DiskCacheAttributes object
76       * <p>
77       * @return The maxPurgatorySize value
78       */
79      public int getMaxPurgatorySize()
80      {
81          return maxPurgatorySize;
82      }
83  
84      /**
85       * Sets the maxPurgatorySize attribute of the DiskCacheAttributes object
86       * <p>
87       * @param maxPurgatorySize The new maxPurgatorySize value
88       */
89      public void setMaxPurgatorySize( int maxPurgatorySize )
90      {
91          this.maxPurgatorySize = maxPurgatorySize;
92      }
93  
94      /**
95       * Get the amount of time in seconds we will wait for elements to move to disk during shutdown
96       * for a particular region.
97       * <p>
98       * @return the time in seconds.
99       */
100     public int getShutdownSpoolTimeLimit()
101     {
102         return this.shutdownSpoolTimeLimit;
103     }
104 
105     /**
106      * Sets the amount of time in seconds we will wait for elements to move to disk during shutdown
107      * for a particular region.
108      * <p>
109      * This is how long we give the event queue to empty.
110      * <p>
111      * The default is 60 seconds.
112      * <p>
113      * @param shutdownSpoolTimeLimit the time in seconds
114      */
115     public void setShutdownSpoolTimeLimit( int shutdownSpoolTimeLimit )
116     {
117         this.shutdownSpoolTimeLimit = shutdownSpoolTimeLimit;
118     }
119 
120     /**
121      * Simple clone.
122      * <p>
123      * @return AuxiliaryCacheAttributes
124      */
125     public AuxiliaryCacheAttributes copy()
126     {
127         try
128         {
129             return (AuxiliaryCacheAttributes) this.clone();
130         }
131         catch ( Exception e )
132         {
133             // swallow
134         }
135         return this;
136     }
137 
138     /**
139      * @param allowRemoveAll The allowRemoveAll to set.
140      */
141     public void setAllowRemoveAll( boolean allowRemoveAll )
142     {
143         this.allowRemoveAll = allowRemoveAll;
144     }
145 
146     /**
147      * @return Returns the allowRemoveAll.
148      */
149     public boolean isAllowRemoveAll()
150     {
151         return allowRemoveAll;
152     }
153 
154     /**
155      * Includes the common attributes for a debug message.
156      * <p>
157      * @return String
158      */
159     @Override
160     public String toString()
161     {
162         StringBuffer str = new StringBuffer();
163         str.append( "AbstractDiskCacheAttributes " );
164         str.append( "\n diskPath = " + getDiskPath() );
165         str.append( "\n maxPurgatorySize   = " + getMaxPurgatorySize() );
166         str.append( "\n allowRemoveAll   = " + isAllowRemoveAll() );
167         str.append( "\n ShutdownSpoolTimeLimit   = " + getShutdownSpoolTimeLimit() );
168         return str.toString();
169     }
170 }