Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   *
   * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
   *
   * The contents of this file are subject to the terms of either the GNU
   * General Public License Version 2 only ("GPL") or the Common Development
   * and Distribution License("CDDL") (collectively, the "License").  You
   * may not use this file except in compliance with the License.  You can
  * obtain a copy of the License at
  * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
  * or packager/legal/LICENSE.txt.  See the License for the specific
  * language governing permissions and limitations under the License.
  *
  * When distributing the software, include this License Header Notice in each
  * file and include the License file at packager/legal/LICENSE.txt.
  *
  * GPL Classpath Exception:
  * Oracle designates this particular file as subject to the "Classpath"
  * exception as provided by Oracle in the GPL Version 2 section of the License
  * file that accompanied this code.
  *
  * Modifications:
  * If applicable, add the following below the License Header, with the fields
  * enclosed by brackets [] replaced by your own identifying information:
  * "Portions Copyright [year] [name of copyright owner]"
  *
  * Contributor(s):
  * If you wish your version of this file to be governed by only the CDDL or
  * only the GPL Version 2, indicate your decision by adding "[Contributor]
  * elects to include this software in this distribution under the [CDDL or GPL
  * Version 2] license."  If you don't indicate a single choice of license, a
  * recipient has the option to distribute your version of this file under
  * either the CDDL, the GPL Version 2 or to extend the choice of license to
  * its licensees as provided above.  However, if you add GPL Version 2 code
  * and therefore, elected the GPL Version 2 license, then the option applies
  * only if the new code is made subject to such option by the copyright
  * holder.
  */
 
 package com.sun.enterprise.web.connector.grizzly;
 
 
A factory for creating FileCache instance.

Author(s):
Jeanfrancois Arcand
 
 public class FileCacheFactory{

    
     
Timeout before remove the static resource from the cache.
 
     public int secondsMaxAge = -1;
    
    
    
The maximum entries in the fileCache
 
     public int maxCacheEntries = 1024;
    
 
    
The maximum size of a cached resources.
 
     public long minEntrySize = 2048;
            
               
    
The maximum size of a cached resources.
 
     public long maxEntrySize = 537600;
    
    
    
The maximum cached bytes
 
     public long maxLargeFileCacheSize = 10485760;
 
    
    
The maximum cached bytes
 
     public long maxSmallFileCacheSize = 1048576;
    
    
    
Is the FileCache enabled.
 
     public static boolean isEnabled = true;
    
    
    
Is the large FileCache enabled.
 
    public boolean isLargeFileCacheEnabled = true;    
    
    
    
The port used
    public int port = 8080;
    
    
    
Create a factory per port.
    protected final static ConcurrentHashMap<Integer,FileCacheFactorycache =
            new ConcurrentHashMap<Integer,FileCacheFactory>();
    
    
    
The cache manager used by instance of FileCache created by this factory;
    protected Queue cacheManager;
    
    
    
Is monitoring enabled
    protected boolean isMonitoringEnabled = false;
    
    
    
A list of FileCache instance this Factory is owning.
    protected FileCache fileCache;
    
    
    
The Header ByteBuffer default size.
    private int headerBBSize = 4096;    
    // ---------------------------------------------------------------------//
    
    
    protected FileCacheFactory(){        
    }

    
    
Configure the factory.
    public static FileCacheFactory newInstance(int currentPort){
        FileCacheFactory fileCacheFactorynew FileCacheFactory();
        fileCacheFactory.port = currentPort;
        .put(currentPortfileCacheFactory);
        Queue<FileCacheEntrycacheManager =
            new  ConcurrentQueue<FileCacheEntry>("FileCacheFactory.cacheManager");
        fileCacheFactory.setCacheManager(cacheManager);  
        return fileCacheFactory;
    }
    
    
    
Return an instance of this Factory.
    public static FileCacheFactory getFactory(int currentPort){
                
        FileCacheFactory fileCacheFactory = .get(currentPort);
        if ( fileCacheFactory == null ){
            fileCacheFactory = newInstance(currentPort); 
        }
        return fileCacheFactory;
    }
    
    
    
Return an instance of a FileCache
    public FileCache getFileCache(){
        if (  == null){
             = new FileCache();
            .setIsEnabled();
            .setSecondsMaxAge();
            .setMinEntrySize();
            .setMaxEntrySize();
            .setMaxSmallCacheSize();         
            .setCacheManager();
            .setHeaderBBSize();
        }
        
        return ;
    } 
    
    
    public void setCacheManager(Queue cacheManager){
        this. = cacheManager;
    }
    
    
    
Return the FileCache
    public ConcurrentHashMap getCache(){
        if (  != null ){
            return .getCache();
        } else {
            return null;
        }
    }
    // ---------------------------------------------------- Monitoring --------//
    
    
    
Returns flag indicating whether file cache has been enabled

Returns:
1 if file cache has been enabled, 0 otherwise
    public int getFlagEnabled() {
        return ( == true?1:0);
    }
    
    
    
Return the maximum age of a valid cache entry

Returns:
cache entry maximum age
    public int getSecondsMaxAge() {
        return ;
    }
    
    
    
Return the number of current cache entries.

Returns:
current cache entries
    public long getCountEntries() {      
        if ( == nullreturn 0L;
        return .getCountEntries();          
    }
    
    
    
Return the maximum number of cache entries

Returns:
maximum cache entries
    public long getMaxEntries() {
        if ( == nullreturn 0L;
        return ;
    }
    
    
    
The number of current open cache entries

Returns:
open cache entries
    public long getCountOpenEntries() {     
        if ( == nullreturn 0L;
        return .getCountOpenEntries();      
    }
    
    
    
Return the maximum number of open cache entries

Returns:
maximum open cache entries
    public long getMaxOpenEntries() {
        if ( == nullreturn 0L;
        return .getMaxOpenEntries();
    }
    
    
    
Return the heap space used for cache

Returns:
heap size
    public long getSizeHeapCache() {
        if ( == nullreturn 0L;
        return .getSizeHeapCache();
    }
    
    
    
Return the maximum heap space used for cache

Returns:
maximum heap size
    public long getMaxHeapCacheSize() {
        if ( == nullreturn 0L;
        return .getMaxHeapCacheSize();
    }
    
    
    
Return the size of Mapped memory used for caching

Returns:
Mapped memory size
    public long getSizeMmapCache() {
        if ( == nullreturn 0L;
        return .getSizeMmapCache();  
    }
    
    
    
Return the Maximum Memory Map size to be used for caching

Returns:
maximum Memory Map size
    public long getMaxMmapCacheSize() {
        if ( == nullreturn 0L;
        return .getMaxMmapCacheSize();   
    }
    
    
    
Return the Number of cache lookup hits

Returns:
cache hits
    public long getCountHits() {
        if ( == nullreturn 0L;
        return .getCountHits(); 
    }
    
    
    
Return the Number of cache lookup misses

Returns:
cache misses
    public long getCountMisses() {
        if ( == nullreturn 0L;
        return .getCountMisses();  
    }
    
    
    
The Number of hits on cached file info

Returns:
hits on cached file info
    public long getCountInfoHits() {
        if ( == nullreturn 0L;
        return .getCountInfoHits();
    }
    
    
    
Return the number of misses on cached file info

Returns:
misses on cache file info
    public long getCountInfoMisses() {
        if ( == nullreturn 0L;
        return .getCountInfoMisses(); 
    }
    
    
    
Return the Number of hits on cached file content

Returns:
hits on cache file content
    public long getCountContentHits() {
        if ( == nullreturn 0L;
        return .getCountContentHits();  
    }
    
    
    
Return the Number of misses on cached file content

Returns:
missed on cached file content
    public long getCountContentMisses() {
        if ( == nullreturn 0L;
        return .getCountContentMisses(); 
    }
    
    // ---------------------------------------------------- Properties ----- //
    
    
    
Turn monitoring on/off
    public void setIsMonitoringEnabled(boolean isMonitoringEnabled){
        this. = isMonitoringEnabled;
        FileCache.setIsMonitoringEnabled(isMonitoringEnabled);
    }
    
    
    
The timeout in seconds before remove a FileCacheEntry from the fileCache
    public void setSecondsMaxAge(int sMaxAges){
         = sMaxAges;
    }
    
    
    
Set the maximum entries this cache can contains.
    public void setMaxCacheEntries(int mEntries){
         = mEntries;
    }

    
    
Return the maximum entries this cache can contains.
    
    public int getMaxCacheEntries(){
        return ;
    }
    
    
    
Set the maximum size a FileCacheEntry can have.
    public void setMinEntrySize(long mSize){
         = mSize;
    }
    
    
    
Get the maximum size a FileCacheEntry can have.
    public long getMinEntrySize(){
        return ;
    }
     
    
    
Set the maximum size a FileCacheEntry can have.
    public void setMaxEntrySize(long mEntrySize){
         = mEntrySize;
    }
    
    
    
Get the maximum size a FileCacheEntry can have.
    public long getMaxEntrySize(){
        return ;
    }
    
    
    
Set the maximum cache size
 
    public void setMaxLargeCacheSize(long mCacheSize){
         = mCacheSize;
    }

    
    
Get the maximum cache size
 
    public long getMaxLargeCacheSize(){
        return ;
    }
    
    
    
Set the maximum cache size
 
    public void setMaxSmallCacheSize(long mCacheSize){
         = mCacheSize;
    }
    
    
    
Get the maximum cache size
 
    public long getMaxSmallCacheSize(){
        return ;
    }    

    
    
Is the fileCache enabled.
    public static boolean isEnabled(){
        return ;
    }

    
    
Is the file caching mechanism enabled.
    public static void setIsEnabled(boolean isE){
         = isE;
    }
   
    
    
Is the large file cache support enabled.
    public void setLargeFileCacheEnabled(boolean isLargeEnabled){
        this. = isLargeEnabled;
    }
   
    
    
Is the large file cache support enabled.
    public boolean getLargeFileCacheEnabled(){
        return ;
    } 

    
    
Retunr the header size buffer.
 
    public int getHeaderBBSize() {
        return ;
    }

    
    
Set the size of the header ByteBuffer.
    public void setHeaderBBSize(int headerBBSize) {
        this. = headerBBSize;
    }
New to GrepCode? Check out our FAQ X