Class FileCache
java.lang.Object
org.glassfish.grizzly.http.server.filecache.FileCache
- All Implemented Interfaces:
org.glassfish.grizzly.monitoring.MonitoringAware<FileCacheProbe>
public class FileCache
extends Object
implements org.glassfish.grizzly.monitoring.MonitoringAware<FileCacheProbe>
This class implements a file caching mechanism used to cache static resources.
- Author:
- Jeanfrancois Arcand, Scott Oaks
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumstatic enum -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.glassfish.grizzly.monitoring.DefaultMonitoringConfig<FileCacheProbe>File cache probes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd(org.glassfish.grizzly.http.HttpRequestPacket request, long lastModified) Add a resource to the cache.Add aFileresource to the cache.protected FileCache.CacheResultAdd a resource to the cache.protected final longaddHeapSize(long size) protected final longaddMappedMemorySize(long size) protected voidcompressFile(FileCacheEntry entry) Creates a temporary compressed representation of the given cache entry.protected static longconvertToLong(String dateHeader) protected Objectget(org.glassfish.grizzly.http.HttpRequestPacket request) ReturnsFileCacheEntry.Returns the folder to be used to store temporary compressed files.org.glassfish.grizzly.http.CompressionConfigReturns the FileCache compression configuration settings.longReturn the heap space used for cachelongReturn the size of Mapped memory used for cachingintlonglonglonglongorg.glassfish.grizzly.monitoring.MonitoringConfig<FileCacheProbe>intvoidinitialize(org.glassfish.grizzly.utils.DelayedExecutor delayedExecutor) booleanbooleanReturnstrueif File resources may be be sent usingFileChannel.transferTo(long, long, java.nio.channels.WritableByteChannel).protected static voidnotifyProbesEntryAdded(FileCache fileCache, FileCacheEntry entry) Notify registeredFileCacheProbes about the "entry added" event.protected static voidnotifyProbesEntryHit(FileCache fileCache, FileCacheEntry entry) Notify registeredFileCacheProbes about the "entry hit event.protected static voidnotifyProbesEntryMissed(FileCache fileCache, org.glassfish.grizzly.http.HttpRequestPacket request) Notify registeredFileCacheProbes about the "entry missed" event.protected static voidnotifyProbesEntryRemoved(FileCache fileCache, FileCacheEntry entry) Notify registeredFileCacheProbes about the "entry removed" event.protected static voidnotifyProbesError(FileCache fileCache, Throwable error) Notify registeredFileCacheProbes about the error.protected voidremove(FileCacheEntry entry) voidsetCompressedFilesFolder(File compressedFilesFolder) Sets the folder to be used to store temporary compressed files.voidsetEnabled(boolean enabled) Enables/disables theFileCache.voidsetFileSendEnabled(boolean fileSendEnabled) Configure whether or send-file support will enabled which allows sendingFileresources viaFileChannel.transferTo(long, long, java.nio.channels.WritableByteChannel).voidsetMaxCacheEntries(int maxCacheEntries) Sets the maximum number of files that may be cached.voidsetMaxEntrySize(long maxEntrySize) The maximum size, in bytes, a resource may be before it can no longer be considered cacheable.voidsetMaxLargeFileCacheSize(long maxLargeFileCacheSize) Sets the maximum size, in bytes, of the memory mapped cache for large files.voidsetMaxSmallFileCacheSize(long maxSmallFileCacheSize) The maximum size, in bytes, of the heap cache for files below the water mark set bygetMinEntrySize().voidsetMinEntrySize(long minEntrySize) The maximum size, in bytes, a file must be in order to be cached in the heap cache.voidsetSecondsMaxAge(int secondsMaxAge) Sets the maximum time, in seconds, a file may be cached.protected final longsubHeapSize(long size) protected final longsubMappedMemorySize(long size)
-
Field Details
-
monitoringConfig
protected final org.glassfish.grizzly.monitoring.DefaultMonitoringConfig<FileCacheProbe> monitoringConfigFile cache probes
-
-
Constructor Details
-
FileCache
public FileCache()
-
-
Method Details
-
initialize
public void initialize(org.glassfish.grizzly.utils.DelayedExecutor delayedExecutor) -
add
public FileCache.CacheResult add(org.glassfish.grizzly.http.HttpRequestPacket request, long lastModified) Add a resource to the cache. Unlike theadd(org.glassfish.grizzly.http.HttpRequestPacket, java.io.File)this method adds a resource to a cache but is not able to send the resource content to a client if client doesn't have the latest version of this resource. -
add
public FileCache.CacheResult add(org.glassfish.grizzly.http.HttpRequestPacket request, File cacheFile) -
add
protected FileCache.CacheResult add(org.glassfish.grizzly.http.HttpRequestPacket request, File cacheFile, long lastModified) Add a resource to the cache. -
get
ReturnsFileCacheEntry. IfFileCacheEntryhas been found - this method also sets correspondentHttpResponsePacketstatus code and reason phrase. -
remove
-
createJmxManagementObject
-
getSecondsMaxAge
public int getSecondsMaxAge()- Returns:
- the maximum time, in seconds, a file may be cached.
-
setSecondsMaxAge
public void setSecondsMaxAge(int secondsMaxAge) Sets the maximum time, in seconds, a file may be cached.- Parameters:
secondsMaxAge- max age of a cached file, in seconds.
-
getMaxCacheEntries
public int getMaxCacheEntries()- Returns:
- the maximum number of files that may be cached.
-
setMaxCacheEntries
public void setMaxCacheEntries(int maxCacheEntries) Sets the maximum number of files that may be cached.- Parameters:
maxCacheEntries- the maximum number of files that may be cached.
-
getMinEntrySize
public long getMinEntrySize()- Returns:
- the minimum size, in bytes, a file must be in order to be cached in the heap cache.
-
setMinEntrySize
public void setMinEntrySize(long minEntrySize) The maximum size, in bytes, a file must be in order to be cached in the heap cache.- Parameters:
minEntrySize- the maximum size, in bytes, a file must be in order to be cached in the heap cache.
-
getMaxEntrySize
public long getMaxEntrySize()- Returns:
- the maximum size, in bytes, a resource may be before it can no longer be considered cacheable.
-
setMaxEntrySize
public void setMaxEntrySize(long maxEntrySize) The maximum size, in bytes, a resource may be before it can no longer be considered cacheable.- Parameters:
maxEntrySize- the maximum size, in bytes, a resource may be before it can no longer be considered cacheable.
-
getMaxLargeFileCacheSize
public long getMaxLargeFileCacheSize()- Returns:
- the maximum size of the memory mapped cache for large files.
-
setMaxLargeFileCacheSize
public void setMaxLargeFileCacheSize(long maxLargeFileCacheSize) Sets the maximum size, in bytes, of the memory mapped cache for large files.- Parameters:
maxLargeFileCacheSize- the maximum size, in bytes, of the memory mapped cache for large files.
-
getMaxSmallFileCacheSize
public long getMaxSmallFileCacheSize()- Returns:
- the maximum size, in bytes, of the heap cache for files below the water mark set by
getMinEntrySize().
-
setMaxSmallFileCacheSize
public void setMaxSmallFileCacheSize(long maxSmallFileCacheSize) The maximum size, in bytes, of the heap cache for files below the water mark set bygetMinEntrySize().- Parameters:
maxSmallFileCacheSize- the maximum size, in bytes, of the heap cache for files below the water mark set bygetMinEntrySize().
-
isEnabled
public boolean isEnabled()- Returns:
trueif theFileCacheis enabled, otherwisefalse
-
setEnabled
public void setEnabled(boolean enabled) - Parameters:
enabled-trueto enable theFileCache.
-
getCompressionConfig
public org.glassfish.grizzly.http.CompressionConfig getCompressionConfig()Returns the FileCache compression configuration settings. -
getCompressedFilesFolder
Returns the folder to be used to store temporary compressed files. -
setCompressedFilesFolder
Sets the folder to be used to store temporary compressed files. -
isFileSendEnabled
public boolean isFileSendEnabled()Returns
trueif File resources may be be sent usingFileChannel.transferTo(long, long, java.nio.channels.WritableByteChannel).By default, this property will be true, except in the following cases:
- JVM OS is HP-UX
- JVM OS is Linux, and the Oracle JVM in use is 1.6.0_17 or older
Finally, if the connection between endpoints is secure, send file functionality will be disabled regardless of configuration.
- Returns:
trueif resources will be sent usingFileChannel.transferTo(long, long, java.nio.channels.WritableByteChannel).- Since:
- 2.3.5
-
setFileSendEnabled
public void setFileSendEnabled(boolean fileSendEnabled) Configure whether or send-file support will enabled which allows sendingFileresources viaFileChannel.transferTo(long, long, java.nio.channels.WritableByteChannel). If disabled, the more traditional byte[] copy will be used to send content.- Parameters:
fileSendEnabled-trueto enableFileChannel.transferTo(long, long, java.nio.channels.WritableByteChannel)support.- Since:
- 2.3.5
-
compressFile
Creates a temporary compressed representation of the given cache entry. -
addHeapSize
protected final long addHeapSize(long size) -
subHeapSize
protected final long subHeapSize(long size) -
getHeapCacheSize
public long getHeapCacheSize()Return the heap space used for cache- Returns:
- heap size
-
addMappedMemorySize
protected final long addMappedMemorySize(long size) -
subMappedMemorySize
protected final long subMappedMemorySize(long size) -
getMappedCacheSize
public long getMappedCacheSize()Return the size of Mapped memory used for caching- Returns:
- Mapped memory size
-
getMonitoringConfig
- Specified by:
getMonitoringConfigin interfaceorg.glassfish.grizzly.monitoring.MonitoringAware<FileCacheProbe>
-
notifyProbesEntryAdded
Notify registeredFileCacheProbes about the "entry added" event.- Parameters:
fileCache- the FileCache event occurred on.entry- entry been added
-
notifyProbesEntryRemoved
Notify registeredFileCacheProbes about the "entry removed" event.- Parameters:
fileCache- the FileCache event occurred on.entry- entry been removed
-
notifyProbesEntryHit
Notify registeredFileCacheProbes about the "entry hit event.- Parameters:
fileCache- the FileCache event occurred on.entry- entry been hit.
-
notifyProbesEntryMissed
protected static void notifyProbesEntryMissed(FileCache fileCache, org.glassfish.grizzly.http.HttpRequestPacket request) Notify registeredFileCacheProbes about the "entry missed" event.- Parameters:
fileCache- the FileCache event occurred on.request- HTTP request.
-
notifyProbesError
Notify registeredFileCacheProbes about the error.- Parameters:
fileCache- the FileCache event occurred on.
-
convertToLong
-