com.sun.grizzly.http
Class FileCache

java.lang.Object
  extended by com.sun.grizzly.http.FileCache
Direct Known Subclasses:
SSLFileCache

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
           
protected static ByteBuffer nullByteBuffer
          A dummy instance of ByteBuffer
static String OK
          HTTP OK header
static int SC_NOT_MODIFIED
          Status code (304) indicating that a conditional GET operation found that the resource was available and not modified.
static int SC_PRECONDITION_FAILED
          Status code (412) indicating that the precondition given in one or more of the request-header fields evaluated to false when it was tested on the server.
 
Constructor Summary
FileCache()
           
 
Method Summary
 void add(String mappedServlet, String baseDir, String requestURI, String host, MimeHeaders headers, boolean xPoweredBy)
          Add a resource to the cache.
protected  void addHeapSize(long size)
           
protected  void addMappedMemorySize(long size)
           
protected  boolean checkIfHeaders(Request request, FileCache.FileCacheEntry entry)
          Check if the conditions specified in the optional If headers are satisfied.
protected  boolean checkIfMatch(Request request, FileCache.FileCacheEntry entry)
          Check if the if-match condition is satisfied.
protected  boolean checkIfUnmodifiedSince(Request request, FileCache.FileCacheEntry entry)
          Check if the if-unmodified-since condition is satisfied.
protected  void countContentHit()
           
protected  void countContentMiss()
           
protected  void countHit()
           
protected  void countInfoHit()
           
protected  void countInfoMiss()
           
protected  void countMiss()
           
protected  void decOpenCacheEntries()
           
 InetAddress getAddress()
           
 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 FileCache.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 FileCache.FileCacheEntry can have.
 int getPort()
           
 int getSecondsMaxAge()
          Return the maximum age of a valid cache entry
 long getSizeHeapCache()
          Return the heap space used for cache
 long getSizeMmapCache()
          Return the size of Mapped memory used for caching
protected  void incOpenCacheEntries()
           
 boolean isEnabled()
          Is the fileCache enabled.
protected  FileCache.FileCacheEntry map(Request request)
          Return true if the file is cached.
protected  void recalcCacheStats(FileCache.FileCacheEntry entry)
           
protected  void recalcCacheStatsIfMonitoring(FileCache.FileCacheEntry entry)
           
 boolean sendCache(Request req)
          Send the cache.
protected  void sendCache(Request request, FileCache.FileCacheEntry entry)
          Send the cached resource.
 void setAddress(InetAddress address)
           Associates the specified network address with this cache instance.
 void setCacheManager(Queue<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.
 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 FileCache.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 FileCache.FileCacheEntry can have.
 void setPort(int port)
           
 void setSecondsMaxAge(int sMaxAges)
          The timeout in seconds before remove a FileCache.FileCacheEntry from the FileCache
protected  void subHeapSize(long size)
           
protected  void subMappedMemorySize(long size)
           
 
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

nullByteBuffer

protected static final ByteBuffer nullByteBuffer
A dummy instance of ByteBuffer


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

SC_NOT_MODIFIED

public static final int SC_NOT_MODIFIED
Status code (304) indicating that a conditional GET operation found that the resource was available and not modified.

See Also:
Constant Field Values

SC_PRECONDITION_FAILED

public static final int SC_PRECONDITION_FAILED
Status code (412) indicating that the precondition given in one or more of the request-header fields evaluated to false when it was tested on the server.

See Also:
Constant Field Values
Constructor Detail

FileCache

public FileCache()
Method Detail

add

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


map

protected final FileCache.FileCacheEntry map(Request request)
Return true if the file is cached.


recalcCacheStatsIfMonitoring

protected void recalcCacheStatsIfMonitoring(FileCache.FileCacheEntry entry)

recalcCacheStats

protected final void recalcCacheStats(FileCache.FileCacheEntry entry)

sendCache

public boolean sendCache(Request req)
Send the cache.


setCacheManager

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


sendCache

protected void sendCache(Request request,
                         FileCache.FileCacheEntry entry)
                  throws IOException
Send the cached resource.

Throws:
IOException

getPort

public int getPort()
Returns:
the port

setPort

public void setPort(int port)
Parameters:
port - the port to set

getAddress

public InetAddress getAddress()
Returns:
the network address associated with this cache instance.

setAddress

public void setAddress(InetAddress address)

Associates the specified network address with this cache instance.

Parameters:
address - the network address

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

incOpenCacheEntries

protected void incOpenCacheEntries()

decOpenCacheEntries

protected void decOpenCacheEntries()

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

addHeapSize

protected void addHeapSize(long size)

subHeapSize

protected void subHeapSize(long size)

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

addMappedMemorySize

protected void addMappedMemorySize(long size)

subMappedMemorySize

protected void subMappedMemorySize(long size)

getSizeMmapCache

public 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

countHit

protected void countHit()

getCountHits

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

Returns:
cache hits

countMiss

protected void countMiss()

getCountMisses

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

Returns:
cache misses

countInfoHit

protected void countInfoHit()

getCountInfoHits

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

Returns:
hits on cached file info

countInfoMiss

protected void countInfoMiss()

getCountInfoMisses

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

Returns:
misses on cache file info

countContentHit

protected void countContentHit()

getCountContentHits

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

Returns:
hits on cache file content

countContentMiss

protected void countContentMiss()

getCountContentMisses

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

Returns:
missed on cached file content

setIsMonitoringEnabled

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


setSecondsMaxAge

public void setSecondsMaxAge(int sMaxAges)
The timeout in seconds before remove a FileCache.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 FileCache.FileCacheEntry can have.


getMinEntrySize

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


setMaxEntrySize

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


getMaxEntrySize

public long getMaxEntrySize()
Get the maximum size a FileCache.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.


checkIfUnmodifiedSince

protected boolean checkIfUnmodifiedSince(Request request,
                                         FileCache.FileCacheEntry entry)
                                  throws IOException
Check if the if-unmodified-since condition is satisfied.

Returns:
boolean true if the resource meets the specified condition, and false if the condition is not satisfied, in which case request processing is stopped
Throws:
IOException

checkIfHeaders

protected boolean checkIfHeaders(Request request,
                                 FileCache.FileCacheEntry entry)
                          throws IOException
Check if the conditions specified in the optional If headers are satisfied.

Returns:
boolean true if the resource meets all the specified conditions, and false if any of the conditions is not satisfied, in which case request processing is stopped
Throws:
IOException

checkIfMatch

protected boolean checkIfMatch(Request request,
                               FileCache.FileCacheEntry entry)
                        throws IOException
Check if the if-match condition is satisfied.

Parameters:
request - The servlet request we are processing
entry - the FileCacheEntry to validate
Returns:
true if the resource meets the specified condition, and false if the condition is not satisfied, in which case request processing is stopped
Throws:
IOException


Copyright © 2012 Oracle Corporation. All Rights Reserved.