Top Description Inners Fields Constructors Methods
org.eclipse.jetty.http.content

public Class CachingHttpContentFactory

extends Object
implements Factory
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.http.content.HttpContent.Factory
Known Direct Subclasses
org.eclipse.jetty.http.content.ValidatingCachingHttpContentFactory
Imports
java.io.IOException, java.nio.ByteBuffer, java.nio.channels.ReadableByteChannel, java.time.Instant, java.util.Set, .SortedSet, .TreeSet, java.util.concurrent.ConcurrentHashMap, .ConcurrentMap, java.util.concurrent.atomic.AtomicBoolean, .AtomicLong, org.eclipse.jetty.http.CompressedContentFormat, .HttpField, .HttpHeader, .MimeTypes, .PreEncodedHttpField, org.eclipse.jetty.io.ByteBufferPool, .Retainable, .RetainableByteBuffer, org.eclipse.jetty.util.BufferUtil, .NanoTime, .StringUtil, org.eclipse.jetty.util.resource.Resource, org.slf4j.Logger, .LoggerFactory

HttpContent.Factory implementation that wraps any other HttpContent.Factory instance using it as a caching authority. Only HttpContent instances whose path is not a directory are cached.

No eviction is done by this HttpContent.Factory, once an entry is in the cache it is always assumed to be valid. This class can be extended to implement the validation behaviours on CachingHttpContent which allow entries to be evicted once they become invalid.


The default values for the cache are:
See Also
ValidatingCachingHttpContentFactory

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected class
protected static interface
protected static class

Field Summary

Modifier and TypeField and Description
private final HttpContent.Factory
private final ByteBufferPool
private final ConcurrentHashMap<String, CachingHttpContentFactory.CachingHttpContent>
private final AtomicLong
private int
private int
private long
private boolean
private static final long
private static final int
private static final int
private static final Logger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
protected ConcurrentMap<String, CachingHttpContentFactory.CachingHttpContent>
public int
public long
public HttpContent
getContent(String
The path within the context to the resource
path
)

Implements org.eclipse.jetty.http.content.HttpContent.Factory.getContent.

public int

Returns:

the max number of cached files.
getMaxCachedFiles
()

Get the max number of cached files..

public int
public long
protected boolean

Returns:

whether the HttpContent is cacheable.
isCacheable
(HttpContent
the HttpContent to test.
httpContent
)

Tests whether the given HttpContent is cacheable, and if there is enough room to fit it in the cache.

public boolean
protected CachingHttpContentFactory.CachingHttpContent
protected CachingHttpContentFactory.CachingHttpContent
protected void
public void
setMaxCachedFiles(int
the max number of cached files.
maxCachedFiles
)

Set the max number of cached files..

public void
setMaxCachedFileSize(int maxCachedFileSize)

public void
setMaxCacheSize(long maxCacheSize)

public void
setUseDirectByteBuffers(boolean useDirectByteBuffers)

private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_authorityback to summary
private final HttpContent.Factory _authority
_bufferPoolback to summary
private final ByteBufferPool _bufferPool
_cacheback to summary
private final ConcurrentHashMap<String, CachingHttpContentFactory.CachingHttpContent> _cache
_cachedSizeback to summary
private final AtomicLong _cachedSize
_maxCachedFilesback to summary
private int _maxCachedFiles
_maxCachedFileSizeback to summary
private int _maxCachedFileSize
_maxCacheSizeback to summary
private long _maxCacheSize
_useDirectByteBuffersback to summary
private boolean _useDirectByteBuffers
DEFAULT_MAX_CACHE_SIZEback to summary
private static final long DEFAULT_MAX_CACHE_SIZE
DEFAULT_MAX_CACHED_FILE_SIZEback to summary
private static final int DEFAULT_MAX_CACHED_FILE_SIZE
DEFAULT_MAX_CACHED_FILESback to summary
private static final int DEFAULT_MAX_CACHED_FILES
LOGback to summary
private static final Logger LOG

Constructor Detail

CachingHttpContentFactoryback to summary
public CachingHttpContentFactory(HttpContent.Factory authority, ByteBufferPool bufferPool)

Method Detail

flushCacheback to summary
public void flushCache()
getCacheback to summary
protected ConcurrentMap<String, CachingHttpContentFactory.CachingHttpContent> getCache()
getCachedFilesback to summary
public int getCachedFiles()
getCachedSizeback to summary
public long getCachedSize()
getContentback to summary
public HttpContent getContent(String path) throws IOException

Implements org.eclipse.jetty.http.content.HttpContent.Factory.getContent.

Parameters
path:String

Doc from org.eclipse.jetty.http.content.HttpContent.Factory.getContent.

The path within the context to the resource

Returns:HttpContent

Doc from org.eclipse.jetty.http.content.HttpContent.Factory.getContent.

A HttpContent

Annotations
@Override
Exceptions
IOException:

Doc from org.eclipse.jetty.http.content.HttpContent.Factory.getContent.

if unable to get content

getMaxCachedFilesback to summary
public int getMaxCachedFiles()

Get the max number of cached files..

Returns:int

the max number of cached files.

getMaxCachedFileSizeback to summary
public int getMaxCachedFileSize()
getMaxCacheSizeback to summary
public long getMaxCacheSize()
isCacheableback to summary
protected boolean isCacheable(HttpContent httpContent)

Tests whether the given HttpContent is cacheable, and if there is enough room to fit it in the cache.

Parameters
httpContent:HttpContent

the HttpContent to test.

Returns:boolean

whether the HttpContent is cacheable.

isUseDirectByteBuffersback to summary
public boolean isUseDirectByteBuffers()
newCachedContentback to summary
protected CachingHttpContentFactory.CachingHttpContent newCachedContent(String p, HttpContent httpContent)
newNotFoundContentback to summary
protected CachingHttpContentFactory.CachingHttpContent newNotFoundContent(String p)
removeFromCacheback to summary
protected void removeFromCache(CachingHttpContentFactory.CachingHttpContent content)
setMaxCachedFilesback to summary
public void setMaxCachedFiles(int maxCachedFiles)

Set the max number of cached files..

Parameters
maxCachedFiles:int

the max number of cached files.

setMaxCachedFileSizeback to summary
public void setMaxCachedFileSize(int maxCachedFileSize)
setMaxCacheSizeback to summary
public void setMaxCacheSize(long maxCacheSize)
setUseDirectByteBuffersback to summary
public void setUseDirectByteBuffers(boolean useDirectByteBuffers)
shrinkCacheback to summary
private void shrinkCache()
org.eclipse.jetty.http.content back to summary

protected Class CachingHttpContentFactory.CachedHttpContent

extends Wrapper
implements CachingHttpContent
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.http.content.CachingHttpContentFactory.CachingHttpContent, org.eclipse.jetty.http.content.HttpContent
Known Direct Subclasses
org.eclipse.jetty.http.content.ValidatingCachingHttpContentFactory.ValidatingCachedContent

Field Summary

Modifier and TypeField and Description
private final RetainableByteBuffer
private final long
private final String
private final String
private final Set<CompressedContentFormat>
private final HttpField
private final long
private final HttpField
private final boolean
private volatile long
private final HttpField
private final Instant
private final String
private final MimeTypes.Type
private final Retainable.ReferenceCounter

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public ByteBuffer
public long
public String
public HttpField
public long
public HttpField
public String
public String
public long
public HttpField
public Instant
public String
public MimeTypes.Type
public Set<CompressedContentFormat>
public boolean
public void
public boolean
public void
Inherited from org.eclipse.jetty.http.content.HttpContent.Wrapper:
getContentEncodinggetContentEncodingValuegetContentTypegetContentTypeValuegetResourcegetWrappedtoString

Field Detail

_bufferback to summary
private final RetainableByteBuffer _buffer
_bytesOccupiedback to summary
private final long _bytesOccupied
_cacheKeyback to summary
private final String _cacheKey
_characterEncodingback to summary
private final String _characterEncoding
_compressedFormatsback to summary
private final Set<CompressedContentFormat> _compressedFormats
_contentLengthback to summary
private final HttpField _contentLength
_contentLengthValueback to summary
private final long _contentLengthValue
_etagFieldback to summary
private final HttpField _etagField
_isValidback to summary
private final boolean _isValid
_lastAccessedback to summary
private volatile long _lastAccessed
_lastModifiedback to summary
private final HttpField _lastModified
_lastModifiedInstantback to summary
private final Instant _lastModifiedInstant
_lastModifiedValueback to summary
private final String _lastModifiedValue
_mimeTypeback to summary
private final MimeTypes.Type _mimeType
_referenceCountback to summary
private final Retainable.ReferenceCounter _referenceCount

Constructor Detail

CachedHttpContentback to summary
public CachedHttpContent(String key, HttpContent httpContent)

Method Detail

getByteBufferback to summary
public ByteBuffer getByteBuffer()

Overrides org.eclipse.jetty.http.content.HttpContent.Wrapper.getByteBuffer.

Implements org.eclipse.jetty.http.content.HttpContent.getByteBuffer.

Doc from org.eclipse.jetty.http.content.HttpContent.getByteBuffer.

Get this HTTP content as a ByteBuffer if possible.

Each invocation returns a new ByteBuffer instance that is read-only and contains valid data between the pos and the limit.

Returns:ByteBuffer

a ByteBuffer instance or null.

Annotations
@Override
getBytesOccupiedback to summary
public long getBytesOccupied()

Overrides org.eclipse.jetty.http.content.HttpContent.Wrapper.getBytesOccupied.

Overrides default org.eclipse.jetty.http.content.HttpContent.getBytesOccupied.

Annotations
@Override
getCharacterEncodingback to summary
public String getCharacterEncoding()

Overrides org.eclipse.jetty.http.content.HttpContent.Wrapper.getCharacterEncoding.

Implements org.eclipse.jetty.http.content.HttpContent.getCharacterEncoding.

Annotations
@Override
getContentLengthback to summary
public HttpField getContentLength()

Overrides org.eclipse.jetty.http.content.HttpContent.Wrapper.getContentLength.

Implements org.eclipse.jetty.http.content.HttpContent.getContentLength.

Annotations
@Override
getContentLengthValueback to summary
public long getContentLengthValue()

Overrides org.eclipse.jetty.http.content.HttpContent.Wrapper.getContentLengthValue.

Implements org.eclipse.jetty.http.content.HttpContent.getContentLengthValue.

Annotations
@Override
getETagback to summary
public HttpField getETag()

Overrides org.eclipse.jetty.http.content.HttpContent.Wrapper.getETag.

Implements org.eclipse.jetty.http.content.HttpContent.getETag.

Annotations
@Override
getETagValueback to summary
public String getETagValue()

Overrides org.eclipse.jetty.http.content.HttpContent.Wrapper.getETagValue.

Implements org.eclipse.jetty.http.content.HttpContent.getETagValue.

Annotations
@Override
getKeyback to summary
public String getKey()

Implements org.eclipse.jetty.http.content.CachingHttpContentFactory.CachingHttpContent.getKey.

Annotations
@Override
getLastAccessedNanosback to summary
public long getLastAccessedNanos()

Implements org.eclipse.jetty.http.content.CachingHttpContentFactory.CachingHttpContent.getLastAccessedNanos.

Annotations
@Override
getLastModifiedback to summary
public HttpField getLastModified()

Overrides org.eclipse.jetty.http.content.HttpContent.Wrapper.getLastModified.

Implements org.eclipse.jetty.http.content.HttpContent.getLastModified.

Annotations
@Override
getLastModifiedInstantback to summary
public Instant getLastModifiedInstant()

Overrides org.eclipse.jetty.http.content.HttpContent.Wrapper.getLastModifiedInstant.

Implements org.eclipse.jetty.http.content.HttpContent.getLastModifiedInstant.

Annotations
@Override
getLastModifiedValueback to summary
public String getLastModifiedValue()

Overrides org.eclipse.jetty.http.content.HttpContent.Wrapper.getLastModifiedValue.

Implements org.eclipse.jetty.http.content.HttpContent.getLastModifiedValue.

Annotations
@Override
getMimeTypeback to summary
public MimeTypes.Type getMimeType()

Overrides org.eclipse.jetty.http.content.HttpContent.Wrapper.getMimeType.

Implements org.eclipse.jetty.http.content.HttpContent.getMimeType.

Annotations
@Override
getPreCompressedContentFormatsback to summary
public Set<CompressedContentFormat> getPreCompressedContentFormats()

Overrides org.eclipse.jetty.http.content.HttpContent.Wrapper.getPreCompressedContentFormats.

Implements org.eclipse.jetty.http.content.HttpContent.getPreCompressedContentFormats.

Returns:Set<CompressedContentFormat>

Doc from org.eclipse.jetty.http.content.HttpContent.getPreCompressedContentFormats.

Set of available pre-compressed formats for this content, or null if this has not been checked.

Annotations
@Override
isValidback to summary
public boolean isValid()

Implements org.eclipse.jetty.http.content.CachingHttpContentFactory.CachingHttpContent.isValid.

Annotations
@Override
releaseback to summary
public void release()

Overrides org.eclipse.jetty.http.content.HttpContent.Wrapper.release.

Implements org.eclipse.jetty.http.content.HttpContent.release.

Annotations
@Override
retainback to summary
public boolean retain()

Implements org.eclipse.jetty.http.content.CachingHttpContentFactory.CachingHttpContent.retain.

Annotations
@Override
setLastAccessedNanosback to summary
public void setLastAccessedNanos(long nanosTime)

Implements org.eclipse.jetty.http.content.CachingHttpContentFactory.CachingHttpContent.setLastAccessedNanos.

Annotations
@Override
org.eclipse.jetty.http.content back to summary

protected Interface CachingHttpContentFactory.CachingHttpContent

extends HttpContent
Known Direct Implementers
org.eclipse.jetty.http.content.CachingHttpContentFactory.CachedHttpContent, org.eclipse.jetty.http.content.CachingHttpContentFactory.NotFoundHttpContent

Method Summary

Modifier and TypeMethod and Description
public String
public long
public boolean
public boolean
public void
setLastAccessedNanos(long nanosTime)

Inherited from org.eclipse.jetty.http.content.HttpContent:
getByteBuffergetBytesOccupiedgetCharacterEncodinggetContentEncodinggetContentEncodingValuegetContentLengthgetContentLengthValuegetContentTypegetContentTypeValuegetETaggetETagValuegetLastModifiedgetLastModifiedInstantgetLastModifiedValuegetMimeTypegetPreCompressedContentFormatsgetResourcerelease

Method Detail

getKeyback to summary
public String getKey()
getLastAccessedNanosback to summary
public long getLastAccessedNanos()
isValidback to summary
public boolean isValid()
retainback to summary
public boolean retain()
setLastAccessedNanosback to summary
public void setLastAccessedNanos(long nanosTime)
org.eclipse.jetty.http.content back to summary

protected Class CachingHttpContentFactory.NotFoundHttpContent

extends Object
implements CachingHttpContent
Class Inheritance
  • java.lang.Object
  • org.eclipse.jetty.http.content.CachingHttpContentFactory.NotFoundHttpContent
All Implemented Interfaces
org.eclipse.jetty.http.content.CachingHttpContentFactory.CachingHttpContent, org.eclipse.jetty.http.content.HttpContent
Known Direct Subclasses
org.eclipse.jetty.http.content.ValidatingCachingHttpContentFactory.ValidatingNotFoundContent

Field Summary

Modifier and TypeField and Description
private final String
private volatile long

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public ByteBuffer
getByteBuffer()

Implements org.eclipse.jetty.http.content.HttpContent.getByteBuffer.

Get this HTTP content as a ByteBuffer if possible.

public String
public HttpField
public String
public HttpField
public long
public HttpField
public String
public HttpField
public String
public String
public long
public HttpField
public Instant
public String
public MimeTypes.Type
public Set<CompressedContentFormat>
public Resource
public boolean
public void
public boolean
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_keyback to summary
private final String _key
_lastAccessedback to summary
private volatile long _lastAccessed

Constructor Detail

NotFoundHttpContentback to summary
public NotFoundHttpContent(String key)

Method Detail

getByteBufferback to summary
public ByteBuffer getByteBuffer()

Implements org.eclipse.jetty.http.content.HttpContent.getByteBuffer.

Doc from org.eclipse.jetty.http.content.HttpContent.getByteBuffer.

Get this HTTP content as a ByteBuffer if possible.

Each invocation returns a new ByteBuffer instance that is read-only and contains valid data between the pos and the limit.

Returns:ByteBuffer

a ByteBuffer instance or null.

Annotations
@Override
getCharacterEncodingback to summary
public String getCharacterEncoding()

Implements org.eclipse.jetty.http.content.HttpContent.getCharacterEncoding.

Annotations
@Override
getContentEncodingback to summary
public HttpField getContentEncoding()

Implements org.eclipse.jetty.http.content.HttpContent.getContentEncoding.

Annotations
@Override
getContentEncodingValueback to summary
public String getContentEncodingValue()

Implements org.eclipse.jetty.http.content.HttpContent.getContentEncodingValue.

Annotations
@Override
getContentLengthback to summary
public HttpField getContentLength()

Implements org.eclipse.jetty.http.content.HttpContent.getContentLength.

Annotations
@Override
getContentLengthValueback to summary
public long getContentLengthValue()

Implements org.eclipse.jetty.http.content.HttpContent.getContentLengthValue.

Annotations
@Override
getContentTypeback to summary
public HttpField getContentType()

Implements org.eclipse.jetty.http.content.HttpContent.getContentType.

Annotations
@Override
getContentTypeValueback to summary
public String getContentTypeValue()

Implements org.eclipse.jetty.http.content.HttpContent.getContentTypeValue.

Annotations
@Override
getETagback to summary
public HttpField getETag()

Implements org.eclipse.jetty.http.content.HttpContent.getETag.

Annotations
@Override
getETagValueback to summary
public String getETagValue()

Implements org.eclipse.jetty.http.content.HttpContent.getETagValue.

Annotations
@Override
getKeyback to summary
public String getKey()

Implements org.eclipse.jetty.http.content.CachingHttpContentFactory.CachingHttpContent.getKey.

Annotations
@Override
getLastAccessedNanosback to summary
public long getLastAccessedNanos()

Implements org.eclipse.jetty.http.content.CachingHttpContentFactory.CachingHttpContent.getLastAccessedNanos.

Annotations
@Override
getLastModifiedback to summary
public HttpField getLastModified()

Implements org.eclipse.jetty.http.content.HttpContent.getLastModified.

Annotations
@Override
getLastModifiedInstantback to summary
public Instant getLastModifiedInstant()

Implements org.eclipse.jetty.http.content.HttpContent.getLastModifiedInstant.

Annotations
@Override
getLastModifiedValueback to summary
public String getLastModifiedValue()

Implements org.eclipse.jetty.http.content.HttpContent.getLastModifiedValue.

Annotations
@Override
getMimeTypeback to summary
public MimeTypes.Type getMimeType()

Implements org.eclipse.jetty.http.content.HttpContent.getMimeType.

Annotations
@Override
getPreCompressedContentFormatsback to summary
public Set<CompressedContentFormat> getPreCompressedContentFormats()

Implements org.eclipse.jetty.http.content.HttpContent.getPreCompressedContentFormats.

Returns:Set<CompressedContentFormat>

Doc from org.eclipse.jetty.http.content.HttpContent.getPreCompressedContentFormats.

Set of available pre-compressed formats for this content, or null if this has not been checked.

Annotations
@Override
getResourceback to summary
public Resource getResource()

Implements org.eclipse.jetty.http.content.HttpContent.getResource.

Annotations
@Override
isValidback to summary
public boolean isValid()

Implements org.eclipse.jetty.http.content.CachingHttpContentFactory.CachingHttpContent.isValid.

Annotations
@Override
releaseback to summary
public void release()

Implements org.eclipse.jetty.http.content.HttpContent.release.

Annotations
@Override
retainback to summary
public boolean retain()

Implements org.eclipse.jetty.http.content.CachingHttpContentFactory.CachingHttpContent.retain.

Annotations
@Override
setLastAccessedNanosback to summary
public void setLastAccessedNanos(long nanosTime)

Implements org.eclipse.jetty.http.content.CachingHttpContentFactory.CachingHttpContent.setLastAccessedNanos.

Annotations
@Override