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

Variable Index

 o ATTR_CACHE_FILTER
Attribute index - The cache filter that manages us.
 o ATTR_CONTENT_LENGTH
Attribute index - The resource content length.
 o ATTR_CONTENT_TYPE
Attribute index - The resource content type.
 o ATTR_DATE
Attribute index - The date at which the reply was emited.
 o ATTR_ETAG
Attribute index - The entity tag (if any) associated with the resource.
 o ATTR_EXTRA_HEADERS
Attribute index - The extension headers attribute.
 o ATTR_FILE
Attribute index - The path of the file that has the resource content.
 o ATTR_GENERATION
Attribute index - This cached resource generation.
 o ATTR_INITAGE
Attribute index - The initial age of this resource.
 o ATTR_LAST_MODIFIED
Attribute index - The last modified date of the cached content
 o ATTR_MAXAGE
Attribute index - The resource's max age.
 o ATTR_RESPONSE_TIME
Attribute index - The response time of the cached response.
 o ATTR_REVALIDATE
Attribute index - Does this cached resource should revalidate.
 o ATTR_STATUS
Attribute index - The reply status.
 o COND_FAILED
Condition check return code - Condition existed but failed.
 o COND_OK
Condition check return code - Condition existed and succeeded.
 o DEFAULT_MAXAGE
The default maxage, set to less then 24 hours, as specified in HTTP/1.1

Constructor Index

 o CachedResource()

Method Index

 o cacheContent(InputStream)
Cache this content, then return the corresponding stream.
 o checkIfMatch(Request)
Try to validate an If-Match request.
 o checkIfModifiedSince(Request)
Try to validate an If-Modified-Since request.
 o checkIfNoneMatch(Request)
Try to validate an If-None-Match request.
 o checkIfUnmodifiedSince(Request)
Try to validate an If-Unmodified-Since request.
 o cleanUpload()
Mark that resource as now being loaded.
 o computeCurrentAge()
Compute this cached entry's current age.
 o delete()
Delete this cached entry from the cache.
 o getContentLength()
Get this cached entry content length.
 o getContentType()
Get the content type associated to that cache entry.
 o getDate()
Get the HTTP date of the reply used to created that entry.
 o getETag()
Get the entity tag associated with that cached entry.
 o getExtraHeaders()
Get the extra headers stored for that resource.
 o getFile()
Get the file in which that resource's content is saved.
 o getGeneration()
Get the generation of that cached entry.
 o getInitialAge()
Get this cached entry initial age.
 o getInputStream()
Get the cached data for that cached entry.
 o getLastModified()
Get the last modified time of that entry.
 o getMaxAge()
Get this resource's max age.
 o getResponseTime()
Get the time of the response used to cached that entry.
 o getRevalidate()
Should this cache entry always be revalidated ?
 o getStatus()
Get the HTTP status of that cached entry.
 o handleRangeRequest(Request, HttpRange)
 o initialize(CacheFilter, Request, Reply)
 o initialize(Object[])
Initialization method for attribute holders.
 o isShared()
 o isValid(Request)
Is the currently cached version usable to answer the given request ?
 o notifyTeeFailure()
 o notifyTeeSuccess(int)
 o notifyUploading(int, int)
Is this resource already being loaded from the net.
 o perform(Request)
This cached entry has been checked valid, perform given request.
 o setContentLength(int)
Set the content length of that cached entry.
 o setContentType(MimeType)
Set this cached entry content-type.
 o setDate(long)
Set the HTTP date of the reply used to create or update that entry.
 o setDefaultMaxAge()
Compute a reasonable default value for the max-age of this resource.
 o setETag(String)
Associate an entity tag with that cached enrty.
 o setExtraHeaders(ArrayDictionary)
Set a new set of extra headers for that resource.
 o setFile(File)
Set the file to which that resource's content should be saved into.
 o setGeneration(int)
Set the generation number of that resource.
 o setInitialAge(long)
Set this resource's initial age.
 o setLastModified(long)
Set the last modified time of that cached entry.
 o setMaxAge(long)
Set this cached entry max age.
 o setReplyHeaders(Reply)
Dump all our knowledge about this cached resource into the reply.
 o setRequestValidation(Request)
Update an original request for a revalidation.
 o setResourceHeaders(Request, Reply)
Cache all the headers that can be cached after the given transaction.
 o setResponseTime(long)
Set this cached entry response time.
 o setRevalidate(boolean)
Set the revalidation flag for that cached entry.
 o setStatus(int)
Set the reply status for that entry.
 o setValue(int, Object)
We overide setValue, to mark the resource as modified.
 o tryActiveCacheContent(InputStream)
Try using an active stream to cache the content.
 o updateAges(Request, Reply)
Update this entry's age according to the given HTTP transaction.
 o validate(Request, Reply)
Given an HTTP transaction, validate that cached entry.
 o waitUpload()
Wait for the upload to finish, if needed.

Variables

 o COND_FAILED
 public static final int COND_FAILED
Condition check return code - Condition existed but failed.

 o COND_OK
 public static final int COND_OK
Condition check return code - Condition existed and succeeded.

 o DEFAULT_MAXAGE
 protected static long DEFAULT_MAXAGE
The default maxage, set to less then 24 hours, as specified in HTTP/1.1

 o ATTR_FILE
 protected static int ATTR_FILE
Attribute index - The path of the file that has the resource content.

 o ATTR_CONTENT_TYPE
 protected static int ATTR_CONTENT_TYPE
Attribute index - The resource content type.

 o ATTR_CONTENT_LENGTH
 protected static int ATTR_CONTENT_LENGTH
Attribute index - The resource content length.

 o ATTR_MAXAGE
 protected static int ATTR_MAXAGE
Attribute index - The resource's max age.

 o ATTR_INITAGE
 protected static int ATTR_INITAGE
Attribute index - The initial age of this resource.

 o ATTR_RESPONSE_TIME
 protected static int ATTR_RESPONSE_TIME
Attribute index - The response time of the cached response.

 o ATTR_LAST_MODIFIED
 protected static int ATTR_LAST_MODIFIED
Attribute index - The last modified date of the cached content

 o ATTR_REVALIDATE
 protected static int ATTR_REVALIDATE
Attribute index - Does this cached resource should revalidate.

 o ATTR_CACHE_FILTER
 protected static int ATTR_CACHE_FILTER
Attribute index - The cache filter that manages us.

 o ATTR_DATE
 protected static int ATTR_DATE
Attribute index - The date at which the reply was emited.

 o ATTR_STATUS
 protected static int ATTR_STATUS
Attribute index - The reply status.

 o ATTR_ETAG
 protected static int ATTR_ETAG
Attribute index - The entity tag (if any) associated with the resource.

 o ATTR_GENERATION
 protected static int ATTR_GENERATION
Attribute index - This cached resource generation.

 o ATTR_EXTRA_HEADERS
 protected static int ATTR_EXTRA_HEADERS
Attribute index - The extension headers attribute.

Constructors

 o CachedResource
 public CachedResource()

Methods

 o setValue
 public void setValue(int idx,
                      Object value)
We overide setValue, to mark the resource as modified.

Overrides:
setValue in class Resource
 o isShared
 public boolean isShared()
 o 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.

 o getFile
 public File getFile()
Get the file in which that resource's content is saved.

Returns:
A File instance.
 o 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.
 o getContentType
 public MimeType getContentType()
Get the content type associated to that cache entry.

Returns:
A MimeType instance, or null if undefined.
 o setContentType
 public void setContentType(MimeType type)
Set this cached entry content-type.

Parameters:
type - The new content type for that entry.
 o getContentLength
 public int getContentLength()
Get this cached entry content length.

Returns:
An integer, giving the content length, or -1 if undefined.
 o setContentLength
 public void setContentLength(int length)
Set the content length of that cached entry.

Parameters:
length - The new content length of that entry.
 o 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.
 o 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.
 o 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.
 o 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.
 o 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.
 o 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.
 o 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.
 o 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.
 o 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.
 o setRevalidate
 public void setRevalidate(boolean onoff)
Set the revalidation flag for that cached entry.

Parameters:
A - boolean.
 o 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.
 o 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.
 o getStatus
 public int getStatus()
Get the HTTP status of that cached entry.

Returns:
An integer HTTP status code, or -1 if undefined.
 o 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.
 o getETag
 public String getETag()
Get the entity tag associated with that cached entry.

Returns:
The String encoded entity tag, or null if undefined.
 o 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.
 o getGeneration
 public int getGeneration()
Get the generation of that cached entry.

Returns:
An integer giving the generation number of that resource.
 o setGeneration
 public void setGeneration(int generation)
Set the generation number of that resource.

Parameters:
generation - The new generation number of that resource.
 o getExtraHeaders
 public ArrayDictionary getExtraHeaders()
Get the extra headers stored for that resource.

Returns:
An ArrayDictionary with the extra headers, or null if undefined.
 o setExtraHeaders
 public void setExtraHeaders(ArrayDictionary a)
Set a new set of extra headers for that resource.

Parameters:
headers - The new set of headers.
 o getInputStream
 public synchronized InputStream getInputStream() throws IOException
Get the cached data for that cached entry.

Returns:
A non-buffered output stream.
 o notifyTeeFailure
 public void notifyTeeFailure()
 o notifyTeeSuccess
 public synchronized void notifyTeeSuccess(int size)
 o 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.
 o 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.

 o 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.
 o setReplyHeaders
 public void setReplyHeaders(Reply reply)
Dump all our knowledge about this cached resource into the reply.

Parameters:
reply - The reply we are building.
 o 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.
 o cleanUpload
 protected synchronized void cleanUpload()
Mark that resource as now being loaded.

 o 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.
 o waitUpload
 protected final synchronized void waitUpload()
Wait for the upload to finish, if needed.

 o 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.
 o 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.
 o 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.
 o 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.
 o 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.
 o 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).
 o handleRangeRequest
 public Reply handleRangeRequest(Request request,
                                 HttpRange r)
 o 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.
 o delete
 public synchronized void delete()
Delete this cached entry from the cache.

Overrides:
delete in class Resource
 o computeCurrentAge
 protected long computeCurrentAge()
Compute this cached entry's current age.

Returns:
The age, as a number of milliseconds.
 o 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.
 o initialize
 public void initialize(CacheFilter filter,
                        Request request,
                        Reply reply) throws IOException
 o 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