1 19 package javax.util.jcache; 20 21 import java.net.InetAddress ; 22 import java.util.Enumeration ; 23 import java.util.Vector ; 24 import org.fjank.jcache.CacheImpl; 25 import org.fjank.jcache.DefaultCacheLogger; 26 27 28 34 public class CacheAttributes implements Cloneable { 35 private CacheImpl cache; 36 37 public void registerCache(CacheImpl cache) { 38 this.cache=cache; 39 } 40 42 private boolean local = false; 43 44 45 48 private String defaultLogFileName = "jcache.log"; 49 50 53 private int cleanInterval = 30; 54 55 58 private int diskSize = 10; 59 60 63 private String diskPath = null; 64 65 68 private int maxObjects = 5000; 69 70 73 private int maxSize = 1; 74 75 78 private CacheLogger logger = new DefaultCacheLogger(); 79 80 83 private CacheAttributes() { 84 } 85 89 public void setLocal() { 90 local = true; 91 } 92 93 102 public void setMaxObjects(int size) { 103 this.maxObjects = size; 104 } 105 106 115 public void setMemoryCacheSize(int size) { 116 this.maxSize = size; 117 } 118 119 124 public void setDiskCacheSize(int size) { 125 this.diskSize = size; 126 127 } 128 129 134 public void setDiskPath(String path) { 135 this.diskPath = path; 136 } 137 138 143 public void setLogger(CacheLogger logger) { 144 this.logger = logger; 145 } 146 147 156 public void setDefaultLogFileName(String pDefaultLogFileName) { 157 this.defaultLogFileName = pDefaultLogFileName; 158 } 159 160 166 public void setCleanInterval(int seconds) { 167 this.cleanInterval = seconds; 168 } 169 170 184 public void addCacheAddr(InetAddress address, int port) { 185 } 187 188 196 public Enumeration getCacheAddr() { 197 if (cache!=null) { 198 return cache.getDistributionEngine().getCacheAddr(); 199 } 200 return new Vector ().elements(); 201 } 202 203 208 public CacheLogger getLogger() { 209 return logger; 210 } 211 212 217 public boolean isDistributed() { 218 return !local; 219 } 220 221 226 public String getDiskPath() { 227 return diskPath; 228 } 229 234 public String toString() { 235 StringBuffer ret = new StringBuffer (128); 236 ret.append("distributed:" + !local); 237 ret.append(", clean interval:" + cleanInterval); 238 ret.append(", memory size:" + maxSize); 239 ret.append(", max number of objects:" + maxObjects); 240 ret.append(", disk size:" + diskSize); 241 ret.append(", disk path:" + diskPath); 242 ret.append(", logger:" + logger); 243 if (!local) { 244 ret.append(", cacheAddresses:" + logger); 245 } 246 return ret.toString(); 247 } 248 253 public int getMemoryCacheSize() { 254 return maxSize; 255 } 256 257 263 264 public CacheAttributes copy() { 265 try { 266 return (CacheAttributes) this.clone(); 267 } catch (CloneNotSupportedException e) { 268 throw new IllegalStateException (this.getClass().getName() 269 + " is not Cloneable."); 270 } 271 } 272 275 public int getCleanInterval() { 276 return cleanInterval; 277 } 278 279 public static CacheAttributes getDefaultCacheAttributes() { 280 CacheAttributes attr = new CacheAttributes(); 281 attr.getLogger().init(attr.defaultLogFileName, CacheLogger.DEFAULT); 282 return attr; 283 284 } 285 286 289 public final int getMaxObjects() { 290 return maxObjects; 291 } 292 296 public final int getDiskSize() { 297 return diskSize; 298 } 299 } 300 | Popular Tags |