com.sun.grizzly.http
Class FileCache

java.lang.Object
  extended by com.sun.grizzly.http.FileCache

public class FileCache
extends Object

This class implements a file caching mechanism used to cache static resources.

Author:
Jeanfrancois Arcand, Scott Oaks

Nested Class Summary
 class FileCache.FileCacheEntry
           
 
Field Summary
protected static ByteBuffer connectionCloseBB
          A connection: close of ByteBuffer
protected static ByteBuffer connectionKaBB
          A connection: keep-alive of ByteBuffer
static String DEFAULT_SERVLET_NAME
           
static String OK
          HTTP OK header
 
Constructor Summary
FileCache()
           
 
Method Summary
 void add(String mappedServlet, String baseDir, String requestURI, MimeHeaders headers, boolean xPoweredBy)
          Add a resource to the cache.
 ConcurrentHashMap<String,FileCache.FileCacheEntry> getCache()
          Return the FileCache
 long getCountContentHits()
          Return the Number of hits on cached file content
 int getCountContentMisses()
          Return the Number of misses on cached file content
 long getCountEntries()
          Return the number of current cache entries.
 long getCountHits()
          Return the Number of cache lookup hits
 long getCountInfoHits()
          The Number of hits on cached file info
 long getCountInfoMisses()
          Return the number of misses on cached file info
 long getCountMisses()
          Return the Number of cache lookup misses
 long getCountOpenEntries()
          The number of current open cache entries
 int getFlagEnabled()
          Returns flag indicating whether file cache has been enabled
 int getHeaderBBSize()
          Retunr the header size buffer.
 boolean getLargeFileCacheEnabled()
          Is the large file cache support enabled.
 int getMaxCacheEntries()
          Return the maximum entries this cache can contains.
 long getMaxEntries()
          Return the maximum number of cache entries
 long getMaxEntrySize()
          Get the maximum size a FileCacheEntry can have.
 long getMaxHeapCacheSize()
          Return the maximum heap space used for cache
 long getMaxLargeCacheSize()
          Get the maximum cache size
 long getMaxMmapCacheSize()
          Return the Maximum Memory Map size to be used for caching
 long getMaxOpenEntries()
          Return the maximum number of open cache entries
 long getMaxSmallCacheSize()
          Get the maximum cache size
 long getMinEntrySize()
          Get the maximum size a FileCacheEntry can have.
 int getSecondsMaxAge()
          Return the maximum age of a valid cache entry
 long getSizeHeapCache()
          Return the heap space used for cache
static long getSizeMmapCache()
          Return the size of Mapped memory used for caching
 boolean isEnabled()
          Is the fileCache enabled.
 boolean sendCache(byte[] req, int start, int length, SocketChannel socketChannel, boolean keepAlive)
          Send the cache.
protected  void sendCache(SocketChannel socketChannel, FileCache.FileCacheEntry entry, boolean keepAlive)
          Send the cached resource.
 void setCacheManager(ConcurrentLinkedQueue<FileCache.FileCacheEntry> cacheManager)
          Set the cache manager used by this instance.
 void setHeaderBBSize(int headerBBSize)
          Set the size of the header ByteBuffer.
 void setIsEnabled(boolean isEnabled)
          Is the file caching mechanism enabled.
static void setIsMonitoringEnabled(boolean isMe)
          Turn monitoring on/off
 void setLargeFileCacheEnabled(boolean isLargeEnabled)
          Is the large file cache support enabled.
 void setMaxCacheEntries(int mEntries)
          Set the maximum entries this cache can contains.
 void setMaxEntrySize(long mEntrySize)
          Set the maximum size a FileCacheEntry can have.
 void setMaxLargeCacheSize(long mCacheSize)
          Set the maximum cache size
 void setMaxSmallCacheSize(long mCacheSize)
          Set the maximum cache size
 void setMinEntrySize(long mSize)
          Set the maximum size a FileCacheEntry can have.
 void setSecondsMaxAge(int sMaxAges)
          The timeout in seconds before remove a FileCacheEntry from the fileCache
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_SERVLET_NAME

public static final String DEFAULT_SERVLET_NAME
See Also:
Constant Field Values

connectionCloseBB

protected static final ByteBuffer connectionCloseBB
A connection: close of ByteBuffer


connectionKaBB

protected static final ByteBuffer connectionKaBB
A connection: keep-alive of ByteBuffer


OK

public static final String OK
HTTP OK header

See Also:
Constant Field Values
Constructor Detail

FileCache

public FileCache()
Method Detail

add

public void add(String mappedServlet,
                String baseDir,
                String requestURI,
                MimeHeaders headers,
                boolean xPoweredBy)
Add a resource to the cache. Currently, only static resources served by the DefaultServlet can be cached.


sendCache

public boolean sendCache(byte[] req,
                         int start,
                         int length,
                         SocketChannel socketChannel,
                         boolean keepAlive)
Send the cache.


setCacheManager

public void setCacheManager(ConcurrentLinkedQueue<FileCache.FileCacheEntry> cacheManager)
Set the cache manager used by this instance.


sendCache

protected void sendCache(SocketChannel socketChannel,
                         FileCache.FileCacheEntry entry,
                         boolean keepAlive)
                  throws IOException
Send the cached resource.

Throws:
IOException

getFlagEnabled

public int getFlagEnabled()
Returns flag indicating whether file cache has been enabled

Returns:
1 if file cache has been enabled, 0 otherwise

getSecondsMaxAge

public int getSecondsMaxAge()
Return the maximum age of a valid cache entry

Returns:
cache entry maximum age

getCountEntries

public long getCountEntries()
Return the number of current cache entries.

Returns:
current cache entries

getMaxEntries

public long getMaxEntries()
Return the maximum number of cache entries

Returns:
maximum cache entries

getCountOpenEntries

public long getCountOpenEntries()
The number of current open cache entries

Returns:
open cache entries

getMaxOpenEntries

public long getMaxOpenEntries()
Return the maximum number of open cache entries

Returns:
maximum open cache entries

getSizeHeapCache

public long getSizeHeapCache()
Return the heap space used for cache

Returns:
heap size

getMaxHeapCacheSize

public long getMaxHeapCacheSize()
Return the maximum heap space used for cache

Returns:
maximum heap size

getSizeMmapCache

public static long getSizeMmapCache()
Return the size of Mapped memory used for caching

Returns:
Mapped memory size

getMaxMmapCacheSize

public long getMaxMmapCacheSize()
Return the Maximum Memory Map size to be used for caching

Returns:
maximum Memory Map size

getCountHits

public long getCountHits()
Return the Number of cache lookup hits

Returns:
cache hits

getCountMisses

public long getCountMisses()
Return the Number of cache lookup misses

Returns:
cache misses

getCountInfoHits

public long getCountInfoHits()
The Number of hits on cached file info

Returns:
hits on cached file info

getCountInfoMisses

public long getCountInfoMisses()
Return the number of misses on cached file info

Returns:
misses on cache file info

getCountContentHits

public long getCountContentHits()
Return the Number of hits on cached file content

Returns:
hits on cache file content

getCountContentMisses

public int getCountContentMisses()
Return the Number of misses on cached file content

Returns:
missed on cached file content

setIsMonitoringEnabled

public static void setIsMonitoringEnabled(boolean isMe)
Turn monitoring on/off


setSecondsMaxAge

public void setSecondsMaxAge(int sMaxAges)
The timeout in seconds before remove a FileCacheEntry from the fileCache


setMaxCacheEntries

public void setMaxCacheEntries(int mEntries)
Set the maximum entries this cache can contains.


getMaxCacheEntries

public int getMaxCacheEntries()
Return the maximum entries this cache can contains.


setMinEntrySize

public void setMinEntrySize(long mSize)
Set the maximum size a FileCacheEntry can have.


getMinEntrySize

public long getMinEntrySize()
Get the maximum size a FileCacheEntry can have.


setMaxEntrySize

public void setMaxEntrySize(long mEntrySize)
Set the maximum size a FileCacheEntry can have.


getMaxEntrySize

public long getMaxEntrySize()
Get the maximum size a FileCacheEntry can have.


setMaxLargeCacheSize

public void setMaxLargeCacheSize(long mCacheSize)
Set the maximum cache size


getMaxLargeCacheSize

public long getMaxLargeCacheSize()
Get the maximum cache size


setMaxSmallCacheSize

public void setMaxSmallCacheSize(long mCacheSize)
Set the maximum cache size


getMaxSmallCacheSize

public long getMaxSmallCacheSize()
Get the maximum cache size


isEnabled

public boolean isEnabled()
Is the fileCache enabled.


setIsEnabled

public void setIsEnabled(boolean isEnabled)
Is the file caching mechanism enabled.


setLargeFileCacheEnabled

public void setLargeFileCacheEnabled(boolean isLargeEnabled)
Is the large file cache support enabled.


getLargeFileCacheEnabled

public boolean getLargeFileCacheEnabled()
Is the large file cache support enabled.


getCache

public ConcurrentHashMap<String,FileCache.FileCacheEntry> getCache()
Return the FileCache


getHeaderBBSize

public int getHeaderBBSize()
Retunr the header size buffer.


setHeaderBBSize

public void setHeaderBBSize(int headerBBSize)
Set the size of the header ByteBuffer.



Copyright © 2008 SUN Microsystems. All Rights Reserved.