| 1 |
package org.apache.commons.jcs3.auxiliary.disk; |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
import java.io.File; |
| 23 |
|
| 24 |
import org.apache.commons.jcs3.auxiliary.AbstractAuxiliaryCacheAttributes; |
| 25 |
import org.apache.commons.jcs3.auxiliary.disk.behavior.IDiskCacheAttributes; |
| 26 |
import org.apache.commons.jcs3.log.Log; |
| 27 |
import org.apache.commons.jcs3.log.LogManager; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
public abstract class AbstractDiskCacheAttributes extends AbstractAuxiliaryCacheAttributes implements IDiskCacheAttributes |
| 33 |
{ |
| 34 |
|
| 35 |
private static final long serialVersionUID = 8306631920391711229L; |
| 36 |
|
| 37 |
|
| 38 |
private static final Log log = LogManager.getLog(AbstractDiskCacheAttributes.class); |
| 39 |
|
| 40 |
|
| 41 |
private File diskPath; |
| 42 |
|
| 43 |
|
| 44 |
private boolean allowRemoveAll = true; |
| 45 |
|
| 46 |
|
| 47 |
private int maxPurgatorySize = MAX_PURGATORY_SIZE_DEFAULT; |
| 48 |
|
| 49 |
|
| 50 |
private static final int DEFAULT_shutdownSpoolTimeLimit = 60; |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
private int shutdownSpoolTimeLimit = DEFAULT_shutdownSpoolTimeLimit; |
| 57 |
|
| 58 |
|
| 59 |
private DiskLimitType diskLimitType = DiskLimitType.COUNT; |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
@Override |
| 69 |
public void setDiskPath(final String path) |
| 70 |
{ |
| 71 |
setDiskPath(new File(path)); |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
public void setDiskPath(final File diskPath) |
| 82 |
{ |
| 83 |
this.diskPath = diskPath; |
| 84 |
boolean result = this.diskPath.isDirectory(); |
| 85 |
|
| 86 |
if (!result) |
| 87 |
{ |
| 88 |
result = this.diskPath.mkdirs(); |
| 89 |
} |
| 90 |
if (!result) |
| 91 |
{ |
| 92 |
log.error("Failed to create directory {0}", diskPath); |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
@Override |
| 103 |
public File getDiskPath() |
| 104 |
{ |
| 105 |
return this.diskPath; |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
@Override |
| 115 |
public int getMaxPurgatorySize() |
| 116 |
{ |
| 117 |
return maxPurgatorySize; |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
@Override |
| 128 |
public void setMaxPurgatorySize(final int maxPurgatorySize) |
| 129 |
{ |
| 130 |
this.maxPurgatorySize = maxPurgatorySize; |
| 131 |
} |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
@Override |
| 141 |
public int getShutdownSpoolTimeLimit() |
| 142 |
{ |
| 143 |
return this.shutdownSpoolTimeLimit; |
| 144 |
} |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
@Override |
| 159 |
public void setShutdownSpoolTimeLimit(final int shutdownSpoolTimeLimit) |
| 160 |
{ |
| 161 |
this.shutdownSpoolTimeLimit = shutdownSpoolTimeLimit; |
| 162 |
} |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
@Override |
| 169 |
public void setAllowRemoveAll(final boolean allowRemoveAll) |
| 170 |
{ |
| 171 |
this.allowRemoveAll = allowRemoveAll; |
| 172 |
} |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
@Override |
| 178 |
public boolean isAllowRemoveAll() |
| 179 |
{ |
| 180 |
return allowRemoveAll; |
| 181 |
} |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
@Override |
| 190 |
public String toString() |
| 191 |
{ |
| 192 |
final StringBuilder str = new StringBuilder(); |
| 193 |
str.append("AbstractDiskCacheAttributes "); |
| 194 |
str.append("\n diskPath = " + getDiskPath()); |
| 195 |
str.append("\n maxPurgatorySize = " + getMaxPurgatorySize()); |
| 196 |
str.append("\n allowRemoveAll = " + isAllowRemoveAll()); |
| 197 |
str.append("\n ShutdownSpoolTimeLimit = " + getShutdownSpoolTimeLimit()); |
| 198 |
return str.toString(); |
| 199 |
} |
| 200 |
|
| 201 |
@Override |
| 202 |
public void setDiskLimitType(final DiskLimitType diskLimitType) |
| 203 |
{ |
| 204 |
this.diskLimitType = diskLimitType; |
| 205 |
} |
| 206 |
|
| 207 |
@Override |
| 208 |
public void setDiskLimitTypeName(final String diskLimitTypeName) |
| 209 |
{ |
| 210 |
if (diskLimitTypeName != null) |
| 211 |
{ |
| 212 |
diskLimitType = DiskLimitType.valueOf(diskLimitTypeName.trim()); |
| 213 |
} |
| 214 |
} |
| 215 |
|
| 216 |
@Override |
| 217 |
public DiskLimitType getDiskLimitType() |
| 218 |
{ |
| 219 |
return diskLimitType; |
| 220 |
} |
| 221 |
} |