All Packages Class Hierarchy This Package Previous Next Index
Class w3c.www.protocol.http.cache.CachedResource
java.lang.Object
|
+----w3c.tools.store.AttributeHolder
|
+----w3c.tools.store.Resource
|
+----w3c.www.protocol.http.cache.CachedResource
- public class CachedResource
- extends Resource
- implements TeeMonitor
-
ATTR_CACHE_FILTER
- Attribute index - The cache filter that manages us.
-
ATTR_CONTENT_LENGTH
- Attribute index - The resource content length.
-
ATTR_CONTENT_TYPE
- Attribute index - The resource content type.
-
ATTR_DATE
- Attribute index - The date at which the reply was emited.
-
ATTR_ETAG
- Attribute index - The entity tag (if any) associated with the resource.
-
ATTR_EXTRA_HEADERS
- Attribute index - The extension headers attribute.
-
ATTR_FILE
- Attribute index - The path of the file that has the resource content.
-
ATTR_GENERATION
- Attribute index - This cached resource generation.
-
ATTR_INITAGE
- Attribute index - The initial age of this resource.
-
ATTR_LAST_MODIFIED
- Attribute index - The last modified date of the cached content
-
ATTR_MAXAGE
- Attribute index - The resource's max age.
-
ATTR_RESPONSE_TIME
- Attribute index - The response time of the cached response.
-
ATTR_REVALIDATE
- Attribute index - Does this cached resource should revalidate.
-
ATTR_STATUS
- Attribute index - The reply status.
-
COND_FAILED
- Condition check return code - Condition existed but failed.
-
COND_OK
- Condition check return code - Condition existed and succeeded.
-
DEFAULT_MAXAGE
- The default maxage, set to less then 24 hours, as specified in HTTP/1.1
-
CachedResource()
-
-
cacheContent(InputStream)
- Cache this content, then return the corresponding stream.
-
checkIfMatch(Request)
- Try to validate an
If-Match
request.
-
checkIfModifiedSince(Request)
- Try to validate an
If-Modified-Since
request.
-
checkIfNoneMatch(Request)
- Try to validate an
If-None-Match
request.
-
checkIfUnmodifiedSince(Request)
- Try to validate an
If-Unmodified-Since
request.
-
cleanUpload()
- Mark that resource as now being loaded.
-
computeCurrentAge()
- Compute this cached entry's current age.
-
delete()
- Delete this cached entry from the cache.
-
getContentLength()
- Get this cached entry content length.
-
getContentType()
- Get the content type associated to that cache entry.
-
getDate()
- Get the HTTP date of the reply used to created that entry.
-
getETag()
- Get the entity tag associated with that cached entry.
-
getExtraHeaders()
- Get the extra headers stored for that resource.
-
getFile()
- Get the file in which that resource's content is saved.
-
getGeneration()
- Get the generation of that cached entry.
-
getInitialAge()
- Get this cached entry initial age.
-
getInputStream()
- Get the cached data for that cached entry.
-
getLastModified()
- Get the last modified time of that entry.
-
getMaxAge()
- Get this resource's max age.
-
getResponseTime()
- Get the time of the response used to cached that entry.
-
getRevalidate()
- Should this cache entry always be revalidated ?
-
getStatus()
- Get the HTTP status of that cached entry.
-
handleRangeRequest(Request, HttpRange)
-
-
initialize(CacheFilter, Request, Reply)
-
-
initialize(Object[])
- Initialization method for attribute holders.
-
isShared()
-
-
isValid(Request)
- Is the currently cached version usable to answer the given request ?
-
notifyTeeFailure()
-
-
notifyTeeSuccess(int)
-
-
notifyUploading(int, int)
- Is this resource already being loaded from the net.
-
perform(Request)
- This cached entry has been checked valid, perform given request.
-
setContentLength(int)
- Set the content length of that cached entry.
-
setContentType(MimeType)
- Set this cached entry content-type.
-
setDate(long)
- Set the HTTP date of the reply used to create or update that entry.
-
setDefaultMaxAge()
- Compute a reasonable default value for the max-age of this resource.
-
setETag(String)
- Associate an entity tag with that cached enrty.
-
setExtraHeaders(ArrayDictionary)
- Set a new set of extra headers for that resource.
-
setFile(File)
- Set the file to which that resource's content should be saved into.
-
setGeneration(int)
- Set the generation number of that resource.
-
setInitialAge(long)
- Set this resource's initial age.
-
setLastModified(long)
- Set the last modified time of that cached entry.
-
setMaxAge(long)
- Set this cached entry max age.
-
setReplyHeaders(Reply)
- Dump all our knowledge about this cached resource into the reply.
-
setRequestValidation(Request)
- Update an original request for a revalidation.
-
setResourceHeaders(Request, Reply)
- Cache all the headers that can be cached after the given transaction.
-
setResponseTime(long)
- Set this cached entry response time.
-
setRevalidate(boolean)
- Set the revalidation flag for that cached entry.
-
setStatus(int)
- Set the reply status for that entry.
-
setValue(int, Object)
- We overide setValue, to mark the resource as modified.
-
tryActiveCacheContent(InputStream)
- Try using an active stream to cache the content.
-
updateAges(Request, Reply)
- Update this entry's age according to the given HTTP transaction.
-
validate(Request, Reply)
- Given an HTTP transaction, validate that cached entry.
-
waitUpload()
- Wait for the upload to finish, if needed.
COND_FAILED
public static final int COND_FAILED
- Condition check return code - Condition existed but failed.
COND_OK
public static final int COND_OK
- Condition check return code - Condition existed and succeeded.
DEFAULT_MAXAGE
protected static long DEFAULT_MAXAGE
- The default maxage, set to less then 24 hours, as specified in HTTP/1.1
ATTR_FILE
protected static int ATTR_FILE
- Attribute index - The path of the file that has the resource content.
ATTR_CONTENT_TYPE
protected static int ATTR_CONTENT_TYPE
- Attribute index - The resource content type.
ATTR_CONTENT_LENGTH
protected static int ATTR_CONTENT_LENGTH
- Attribute index - The resource content length.
ATTR_MAXAGE
protected static int ATTR_MAXAGE
- Attribute index - The resource's max age.
ATTR_INITAGE
protected static int ATTR_INITAGE
- Attribute index - The initial age of this resource.
ATTR_RESPONSE_TIME
protected static int ATTR_RESPONSE_TIME
- Attribute index - The response time of the cached response.
ATTR_LAST_MODIFIED
protected static int ATTR_LAST_MODIFIED
- Attribute index - The last modified date of the cached content
ATTR_REVALIDATE
protected static int ATTR_REVALIDATE
- Attribute index - Does this cached resource should revalidate.
ATTR_CACHE_FILTER
protected static int ATTR_CACHE_FILTER
- Attribute index - The cache filter that manages us.
ATTR_DATE
protected static int ATTR_DATE
- Attribute index - The date at which the reply was emited.
ATTR_STATUS
protected static int ATTR_STATUS
- Attribute index - The reply status.
ATTR_ETAG
protected static int ATTR_ETAG
- Attribute index - The entity tag (if any) associated with the resource.
ATTR_GENERATION
protected static int ATTR_GENERATION
- Attribute index - This cached resource generation.
ATTR_EXTRA_HEADERS
protected static int ATTR_EXTRA_HEADERS
- Attribute index - The extension headers attribute.
CachedResource
public CachedResource()
setValue
public void setValue(int idx,
Object value)
- We overide setValue, to mark the resource as modified.
- Overrides:
- setValue in class Resource
isShared
public boolean isShared()
setDefaultMaxAge
protected void setDefaultMaxAge()
- Compute a reasonable default value for the max-age of this resource.
This method computes and sets the default max age for this resource,
it should be called as a last resort only.
getFile
public File getFile()
- Get the file in which that resource's content is saved.
- Returns:
- A File instance.
setFile
public void setFile(File file)
- Set the file to which that resource's content should be saved into.
- Parameters:
- file - The file to use.
getContentType
public MimeType getContentType()
- Get the content type associated to that cache entry.
- Returns:
- A MimeType instance, or null if undefined.
setContentType
public void setContentType(MimeType type)
- Set this cached entry content-type.
- Parameters:
- type - The new content type for that entry.
getContentLength
public int getContentLength()
- Get this cached entry content length.
- Returns:
- An integer, giving the content length, or -1
if undefined.
setContentLength
public void setContentLength(int length)
- Set the content length of that cached entry.
- Parameters:
- length - The new content length of that entry.
getMaxAge
public long getMaxAge()
- Get this resource's max age.
- Returns:
- A long number of milliseconds for which that entry will remain
valid, or -1 if undefined.
setMaxAge
public void setMaxAge(long maxage)
- Set this cached entry max age.
- Parameters:
- maxage - A number of milliseconds during which the entry will
remain valid, or -1 to undefine previous setting.
getInitialAge
public long getInitialAge()
- Get this cached entry initial age.
- Returns:
- A long number of milliseconds giving the initial age relative
to Java epoch, or -1 if undefined.
setInitialAge
public void setInitialAge(long initage)
- Set this resource's initial age.
- Parameters:
- initage - The initial age as a number of milliseconds since Java
epoch, or -1 to undefine previous setting.
getResponseTime
public long getResponseTime()
- Get the time of the response used to cached that entry.
- Returns:
- A long number of milliseconds since Java epoch, or
-1 if undefined.
setResponseTime
public void setResponseTime(long responsetime)
- Set this cached entry response time.
- Parameters:
- responsetime - A long number of milliseconds indicating the
response time relative to Java epoch, or -1 to
undefined previous setting.
getLastModified
public long getLastModified()
- Get the last modified time of that entry.
This usually corresponds to the
Last-Modified
HTTP header.
- Returns:
- A long number of milliseconds since java epoch giving the last
modified date of the cached entry, or -1 if undefined.
setLastModified
public void setLastModified(long lastmodified)
- Set the last modified time of that cached entry.
- Parameters:
- lastmodified - The last modification date as a number of
milliseconds since Java epoch, or -1 to undefine
previous setting.
getRevalidate
public boolean getRevalidate()
- Should this cache entry always be revalidated ?
- Returns:
- A boolean, true if revalidation is always
needed before serving it, false otherwise.
setRevalidate
public void setRevalidate(boolean onoff)
- Set the revalidation flag for that cached entry.
- Parameters:
- A - boolean.
getDate
public long getDate()
- Get the HTTP date of the reply used to created that entry.
- Returns:
- The HTTP date encoded as the number of milliseconds relative
to Java epoch, or -1 if undefined.
setDate
public void setDate(long date)
- Set the HTTP date of the reply used to create or update that entry.
- Parameters:
- date - The HTTP date encoded as a number of milliseconds since
Java epoch, or -1 to undefine previous setting.
getStatus
public int getStatus()
- Get the HTTP status of that cached entry.
- Returns:
- An integer HTTP status code, or -1 if
undefined.
setStatus
public void setStatus(int status)
- Set the reply status for that entry.
- Parameters:
- status - The HTTP status code of that entry, or -1
to undefine the previous setting.
getETag
public String getETag()
- Get the entity tag associated with that cached entry.
- Returns:
- The String encoded entity tag, or null if
undefined.
setETag
public void setETag(String etag)
- Associate an entity tag with that cached enrty.
- Parameters:
- etag - The entity tag of the entry, or null
to reset the value.
getGeneration
public int getGeneration()
- Get the generation of that cached entry.
- Returns:
- An integer giving the generation number of that resource.
setGeneration
public void setGeneration(int generation)
- Set the generation number of that resource.
- Parameters:
- generation - The new generation number of that resource.
getExtraHeaders
public ArrayDictionary getExtraHeaders()
- Get the extra headers stored for that resource.
- Returns:
- An ArrayDictionary with the extra headers, or null
if undefined.
setExtraHeaders
public void setExtraHeaders(ArrayDictionary a)
- Set a new set of extra headers for that resource.
- Parameters:
- headers - The new set of headers.
getInputStream
public synchronized InputStream getInputStream() throws IOException
- Get the cached data for that cached entry.
- Returns:
- A non-buffered output stream.
notifyTeeFailure
public void notifyTeeFailure()
notifyTeeSuccess
public synchronized void notifyTeeSuccess(int size)
tryActiveCacheContent
public synchronized InputStream tryActiveCacheContent(InputStream in) throws IOException
- Try using an active stream to cache the content.
Byte size usage is taken care of only at the end of the download
to make sure we get the right sizes (might different from the
advertized ones).
- Returns:
- An InputStream instance if active caching was possible,
null otherwise.
cacheContent
public synchronized InputStream cacheContent(InputStream in) throws IOException
- Cache this content, then return the corresponding stream.
This method is called as a fallback to
tryActiveCacheContent
. At the end of the method, the
cache filter is notified of byte size usage.
setResourceHeaders
public void setResourceHeaders(Request request,
Reply reply)
- Cache all the headers that can be cached after the given transaction.
Most reply headers are cached as attributes, other ones are left over
to a slow, dictionary.
- Parameters:
- request - The request that triggered the reply.
- reply - The origin server's reply.
setReplyHeaders
public void setReplyHeaders(Reply reply)
- Dump all our knowledge about this cached resource into the reply.
- Parameters:
- reply - The reply we are building.
setRequestValidation
public void setRequestValidation(Request request)
- Update an original request for a revalidation.
This method updates the original request to use as much conditionals
as possible.
- Parameters:
- request - The request to update.
cleanUpload
protected synchronized void cleanUpload()
- Mark that resource as now being loaded.
notifyUploading
protected final synchronized boolean notifyUploading(int upoldsize,
int upnewsize)
- Is this resource already being loaded from the net.
If not, mark that resource has currently being uploaded. When that
method returns true, the caller MUST make sure
the
cleanUpload
method gets called latter on.
- Parameters:
- upoldsize - The old size of cache entry (if available)
- upnewsize - The expected size of the entry.
- Returns:
- A boolean, true if that resource is being
loaded, false otherwise.
waitUpload
protected final synchronized void waitUpload()
- Wait for the upload to finish, if needed.
validate
public synchronized Reply validate(Request request,
Reply reply) throws IOException
- Given an HTTP transaction, validate that cached entry.
- Parameters:
- request - The request that we used to validate.
- reply - The origin's server reply.
- Returns:
- A reply instance suitable to emit back to the client.
checkIfModifiedSince
public int checkIfModifiedSince(Request request)
- Try to validate an
If-Modified-Since
request.
- Parameters:
- request - The request to validate.
- Returns:
- An integer,
COND_FAILED
, if the condition was
checked, but failed; COND_OK
of condition was checked
and succeeded, 0 otherwise.
checkIfUnmodifiedSince
public int checkIfUnmodifiedSince(Request request)
- Try to validate an
If-Unmodified-Since
request.
- Parameters:
- request - The request to validate.
- Returns:
- An integer,
COND_FAILED
, if the condition was
checked, but failed; COND_OK
of condition was checked
and succeeded, 0 otherwise.
checkIfMatch
public int checkIfMatch(Request request)
- Try to validate an
If-Match
request.
- Parameters:
- request - The request to validate.
- Returns:
- An integer,
COND_FAILED
, if the condition was
checked, but failed; COND_OK
of condition was checked
and succeeded, 0 otherwise.
checkIfNoneMatch
public int checkIfNoneMatch(Request request)
- Try to validate an
If-None-Match
request.
- Parameters:
- request - The request to validate.
- Returns:
- An integer,
COND_FAILED
, if the condition was
checked, but failed; COND_OK
of condition was checked
and succeeded, 0 otherwise.
isValid
public boolean isValid(Request request)
- Is the currently cached version usable to answer the given request ?
- Returns:
- A boolean, true if we are able to generate
a valid answer to this request by the
perform
method,
false otherwise (the resource needs to be refreshed).
handleRangeRequest
public Reply handleRangeRequest(Request request,
HttpRange r)
perform
public Reply perform(Request request) throws HttpException
- This cached entry has been checked valid, perform given request.
- Parameters:
- request - The request to perform.
- Returns:
- An Reply instance.
- Throws: HTTPException
- If something went wrong.
delete
public synchronized void delete()
- Delete this cached entry from the cache.
- Overrides:
- delete in class Resource
computeCurrentAge
protected long computeCurrentAge()
- Compute this cached entry's current age.
- Returns:
- The age, as a number of milliseconds.
updateAges
public void updateAges(Request request,
Reply reply)
- Update this entry's age according to the given HTTP transaction.
- Parameters:
- request - Our original request.
- reply - The corresponding reply.
initialize
public void initialize(CacheFilter filter,
Request request,
Reply reply) throws IOException
initialize
public void initialize(Object values[])
- Initialization method for attribute holders.
- Overrides:
- initialize in class AttributeHolder
All Packages Class Hierarchy This Package Previous Next Index