1 23 package com.sun.enterprise.web.connector.grizzly; 24 25 import java.util.concurrent.ConcurrentHashMap ; 26 import java.util.concurrent.ConcurrentLinkedQueue ; 27 28 import com.sun.enterprise.web.connector.grizzly.FileCache.FileCacheEntry; 29 34 public class FileCacheFactory{ 35 36 37 40 public int secondsMaxAge = -1; 41 42 43 46 public int maxCacheEntries = 1024; 47 48 49 52 public long minEntrySize = 2048; 53 54 55 58 public long maxEntrySize = 537600; 59 60 61 64 public long maxLargeFileCacheSize = 10485760; 65 66 67 70 public long maxSmallFileCacheSize = 1048576; 71 72 73 76 public static boolean isEnabled = true; 77 78 79 82 public boolean isLargeFileCacheEnabled = true; 83 84 85 88 public int port = 8080; 89 90 91 94 private static ConcurrentHashMap <Integer ,FileCacheFactory> cache = 95 new ConcurrentHashMap <Integer ,FileCacheFactory>(); 96 97 98 102 private ConcurrentLinkedQueue cacheManager; 103 104 105 108 private boolean isMonitoringEnabled = false; 109 110 111 114 protected FileCache fileCache; 115 116 117 119 120 private FileCacheFactory(){ 121 } 122 123 124 127 private static FileCacheFactory newInstance(int currentPort){ 128 FileCacheFactory fileCacheFactory= new FileCacheFactory(); 129 130 fileCacheFactory.port = currentPort; 131 cache.put(currentPort, fileCacheFactory); 132 133 ConcurrentLinkedQueue <FileCacheEntry> cacheManager = 134 new ConcurrentLinkedQueue <FileCacheEntry>(); 135 fileCacheFactory.cacheManager = cacheManager; 136 137 return fileCacheFactory; 138 } 139 140 141 144 public static FileCacheFactory getFactory(int currentPort){ 145 146 FileCacheFactory fileCacheFactory = cache.get(currentPort); 147 if ( fileCacheFactory == null ){ 148 fileCacheFactory = newInstance(currentPort); 149 } 150 151 return fileCacheFactory; 152 } 153 154 155 158 public FileCache getFileCache(){ 159 if ( fileCache == null){ 160 fileCache = new FileCache(); 161 fileCache.setIsEnabled(isEnabled); 162 fileCache.setLargeFileCacheEnabled(isLargeFileCacheEnabled); 163 fileCache.setSecondsMaxAge(secondsMaxAge); 164 fileCache.setMaxCacheEntries(maxCacheEntries); 165 fileCache.setMinEntrySize(minEntrySize); 166 fileCache.setMaxEntrySize(maxEntrySize); 167 fileCache.setMaxLargeCacheSize(maxLargeFileCacheSize); 168 fileCache.setMaxSmallCacheSize(maxSmallFileCacheSize); 169 fileCache.setCacheManager(cacheManager); 170 fileCache.setIsMonitoringEnabled(isMonitoringEnabled); 171 } 172 173 return fileCache; 174 } 175 176 177 private void setCacheManager(ConcurrentLinkedQueue cacheManager){ 178 this.cacheManager = cacheManager; 179 } 180 181 182 185 public ConcurrentHashMap getCache(){ 186 if ( fileCache != null ){ 187 return fileCache.getCache(); 188 } else { 189 return null; 190 } 191 } 192 194 195 199 public int getFlagEnabled() { 200 return (isEnabled == true?1:0); 201 } 202 203 204 208 public int getSecondsMaxAge() { 209 return secondsMaxAge; 210 } 211 212 213 217 public long getCountEntries() { 218 if (fileCache == null) return 0L; 219 return fileCache.getCountEntries(); 220 } 221 222 223 227 public long getMaxEntries() { 228 if (fileCache == null) return 0L; 229 return maxCacheEntries; 230 } 231 232 233 237 public long getCountOpenEntries() { 238 if (fileCache == null) return 0L; 239 return fileCache.getCountOpenEntries(); 240 } 241 242 243 247 public long getMaxOpenEntries() { 248 if (fileCache == null) return 0L; 249 return fileCache.getMaxOpenEntries(); 250 } 251 252 253 257 public long getSizeHeapCache() { 258 if (fileCache == null) return 0L; 259 return fileCache.getSizeHeapCache(); 260 } 261 262 263 267 public long getMaxHeapCacheSize() { 268 if (fileCache == null) return 0L; 269 return fileCache.getMaxHeapCacheSize(); 270 } 271 272 273 277 public long getSizeMmapCache() { 278 if (fileCache == null) return 0L; 279 return fileCache.getSizeMmapCache(); 280 } 281 282 283 287 public long getMaxMmapCacheSize() { 288 if (fileCache == null) return 0L; 289 return fileCache.getMaxMmapCacheSize(); 290 } 291 292 293 297 public long getCountHits() { 298 if (fileCache == null) return 0L; 299 return fileCache.getCountHits(); 300 } 301 302 303 307 public long getCountMisses() { 308 if (fileCache == null) return 0L; 309 return fileCache.getCountMisses(); 310 } 311 312 313 317 public long getCountInfoHits() { 318 if (fileCache == null) return 0L; 319 return fileCache.getCountInfoHits(); 320 } 321 322 323 327 public long getCountInfoMisses() { 328 if (fileCache == null) return 0L; 329 return fileCache.getCountInfoMisses(); 330 } 331 332 333 337 public long getCountContentHits() { 338 if (fileCache == null) return 0L; 339 return fileCache.getCountContentHits(); 340 } 341 342 343 347 public long getCountContentMisses() { 348 if (fileCache == null) return 0L; 349 return fileCache.getCountContentMisses(); 350 } 351 352 354 355 358 public void setIsMonitoringEnabled(boolean isMonitoringEnabled){ 359 this.isMonitoringEnabled = isMonitoringEnabled; 360 FileCache.setIsMonitoringEnabled(isMonitoringEnabled); 361 } 362 363 364 368 public void setSecondsMaxAge(int sMaxAges){ 369 secondsMaxAge = sMaxAges; 370 } 371 372 373 376 public void setMaxCacheEntries(int mEntries){ 377 maxCacheEntries = mEntries; 378 } 379 380 381 384 public int getMaxCacheEntries(){ 385 return maxCacheEntries; 386 } 387 388 389 392 public void setMinEntrySize(long mSize){ 393 minEntrySize = mSize; 394 } 395 396 397 400 public long getMinEntrySize(){ 401 return minEntrySize; 402 } 403 404 405 408 public void setMaxEntrySize(long mEntrySize){ 409 maxEntrySize = mEntrySize; 410 } 411 412 413 416 public long getMaxEntrySize(){ 417 return maxEntrySize; 418 } 419 420 421 424 public void setMaxLargeCacheSize(long mCacheSize){ 425 maxLargeFileCacheSize = mCacheSize; 426 } 427 428 429 432 public long getMaxLargeCacheSize(){ 433 return maxLargeFileCacheSize; 434 } 435 436 437 440 public void setMaxSmallCacheSize(long mCacheSize){ 441 maxSmallFileCacheSize = mCacheSize; 442 } 443 444 445 448 public long getMaxSmallCacheSize(){ 449 return maxSmallFileCacheSize; 450 } 451 452 453 456 public static boolean isEnabled(){ 457 return isEnabled; 458 } 459 460 461 464 public static void setIsEnabled(boolean isE){ 465 isEnabled = isE; 466 } 467 468 469 472 public void setLargeFileCacheEnabled(boolean isLargeEnabled){ 473 this.isLargeFileCacheEnabled = isLargeEnabled; 474 } 475 476 477 480 public boolean getLargeFileCacheEnabled(){ 481 return isLargeFileCacheEnabled; 482 } 483 484 } 485 | Popular Tags |