cachedresource.java
来自「很棒的web服务器源代码」· Java 代码 · 共 669 行 · 第 1/2 页
JAVA
669 行
// CachedResource.java// $Id: CachedResource.java,v 1.78 2003/01/24 14:39:59 ylafon Exp $// (c) COPYRIGHT MIT, INRIA and Keio, 1999.// Please first read the full copyright statement in file COPYRIGHT.htmlpackage org.w3c.www.protocol.http.cache;import java.io.File;import org.w3c.util.ArrayDictionary;import org.w3c.util.LRUAble;import org.w3c.tools.resources.Attribute;import org.w3c.tools.resources.AttributeHolder;import org.w3c.tools.resources.AttributeRegistry;import org.w3c.tools.resources.DateAttribute;import org.w3c.tools.resources.FileAttribute;import org.w3c.tools.resources.IntegerAttribute;import org.w3c.tools.resources.PropertiesAttribute;import org.w3c.tools.resources.StringArrayAttribute;import org.w3c.tools.resources.StringAttribute;import org.w3c.www.http.HttpEntityTag;import org.w3c.www.protocol.http.HttpException;import org.w3c.www.protocol.http.Reply;import org.w3c.www.protocol.http.Request;import org.w3c.www.mime.MimeType;import org.w3c.jigsaw.frames.MimeTypeAttribute;public abstract class CachedResource extends AttributeHolder implements TeeMonitor, LRUAble { /** * Condition check return code - Condition existed but failed. */ public static final int COND_FAILED = 1; /** * Condition check return code - Condition existed and succeeded. */ public static final int COND_OK = 2; /** * The download state of the resource, currently not loaded */ public static final int STATE_NOT_LOADED = 0; /** * The download state of the resource, complete content */ public static final int STATE_LOAD_COMPLETE = 1; /** * The download state of the resource, partial content */ public static final int STATE_LOAD_PARTIAL = 2; /** * The download state of the resource, unknown, probably an HTTP/1.0 * reply without the Content-Length. */ public static final int STATE_LOAD_UNKNOWN = 3; /** * The download state of the resource, erroneous, something weird * happened! but at least we know that :) */ public static final int STATE_LOAD_ERROR = 4; /** * Attribute index - The identifier */ protected static int ATTR_IDENTIFIER = -1; /** * Attribute index - The resource content length. */ protected static int ATTR_CONTENT_LENGTH = -1; /** * Attribute index - The resource current length. */ protected static int ATTR_CURRENT_LENGTH = -1; /** * Attribute index - The file */ protected static int ATTR_FILE = -1; /** * Attribute name - The resource content length. */ protected static final String NAME_CONTENT_LENGTH = "content-length"; /** * Attribute name - The resource current length */ protected static final String NAME_CURRENT_LENGTH = "current-length"; /** * Attribute name - The identifier */ protected static final String NAME_IDENTIFIER = "id"; /** * Attribute name - The identifier */ protected static final String NAME_FILE = "file"; /** * Attribute index - The download state */ protected static int ATTR_LOAD_STATE = -1; /** * Attribute index - The entity tag (if any) associated with the resource. */ protected static int ATTR_ETAG = -1; /** * Attribute index - The reply status. */ protected static int ATTR_STATUS = -1; /** * Attribute index - The Last modified of this resource */ protected static int ATTR_REPLY_LAST_MODIFIED = -1; /** * Attribute index - The Date of the resource */ protected static int ATTR_DATE = -1; /** * Attribute index - The Content MD5 of the resource */ protected static int ATTR_CONTENT_MD5 = -1; /** * Attribute index - The Content Encoding of the resource */ protected static int ATTR_CONTENT_ENCODING = -1; /** * Attribute index - The Content Language of the resource */ protected static int ATTR_CONTENT_LANGUAGE = -1; /** * Attribute index - The Location of this resource */ protected static int ATTR_LOCATION = -1; /** * Attribute index - The Vary of this resource */ protected static int ATTR_VARY = -1; /** * Attribute index - The extra headers attribute. */ protected static int ATTR_EXTRA_HEADERS = -1; /** * Attribute index - The request headers used for content negotiation * as set by the reply Vary header. */ protected static int ATTR_CONNEG_HEADERS = -1; static { Attribute a = null; Class c = null; try { c = Class.forName( "org.w3c.www.protocol.http.cache.CachedResource"); } catch (Exception ex) { ex.printStackTrace(); System.exit(1); } // This resource ntity tag: a = new StringAttribute(NAME_IDENTIFIER , null , Attribute.COMPUTED); ATTR_IDENTIFIER = AttributeRegistry.registerAttribute(c, a); // Declare the content length attribuite: a = new IntegerAttribute(NAME_CONTENT_LENGTH , null , Attribute.COMPUTED); ATTR_CONTENT_LENGTH = AttributeRegistry.registerAttribute(c, a); // Declare the currentlength attribuite: a = new IntegerAttribute(NAME_CURRENT_LENGTH , null , Attribute.COMPUTED); ATTR_CURRENT_LENGTH = AttributeRegistry.registerAttribute(c, a); // Declare the file attribute a = new FileAttribute(NAME_FILE , null , Attribute.COMPUTED); ATTR_FILE = AttributeRegistry.registerAttribute(c, a); // Declare the download state value a = new IntegerAttribute("load-state" , null , Attribute.COMPUTED); ATTR_LOAD_STATE = AttributeRegistry.registerAttribute(c, a); // This resource entity tag: a = new StringAttribute("etag" , null , Attribute.COMPUTED); ATTR_ETAG = AttributeRegistry.registerAttribute(c, a); // Declare the status attribute: a = new IntegerAttribute("status" , null , Attribute.COMPUTED); ATTR_STATUS = AttributeRegistry.registerAttribute(c, a); // The last modified attribute: a = new DateAttribute("reply-last-modified", null, Attribute.COMPUTED|Attribute.EDITABLE) ; ATTR_REPLY_LAST_MODIFIED = AttributeRegistry.registerAttribute(c,a); // The last modified attribute: a = new DateAttribute("reply-date", null, Attribute.COMPUTED|Attribute.EDITABLE) ; ATTR_DATE = AttributeRegistry.registerAttribute(c,a); // This resource content-md5 a = new StringAttribute("content-md5" , null , Attribute.COMPUTED); ATTR_CONTENT_MD5 = AttributeRegistry.registerAttribute(c, a); // This resource content encoding a = new StringArrayAttribute("content-encoding" , null , Attribute.COMPUTED); ATTR_CONTENT_ENCODING = AttributeRegistry.registerAttribute(c, a); // This resource content-language a = new StringArrayAttribute("content-language" , null , Attribute.COMPUTED); ATTR_CONTENT_LANGUAGE = AttributeRegistry.registerAttribute(c, a); // This resource location a = new StringAttribute("location" , null , Attribute.COMPUTED); ATTR_LOCATION = AttributeRegistry.registerAttribute(c, a); // This resource location a = new StringArrayAttribute("vary" , null , Attribute.COMPUTED); ATTR_VARY = AttributeRegistry.registerAttribute(c, a); // The extra headers attribute: a = new PropertiesAttribute("headers" , null , Attribute.COMPUTED); ATTR_EXTRA_HEADERS = AttributeRegistry.registerAttribute(c, a); // The extra headers attribute: a = new PropertiesAttribute("conneg" , null , Attribute.COMPUTED); ATTR_CONNEG_HEADERS = AttributeRegistry.registerAttribute(c, a); } /** * The minimal attribute set used to describe a cachedresource without * loading it entirely. */ protected static String ATTR_DESCR[] = { NAME_IDENTIFIER, NAME_CURRENT_LENGTH, NAME_FILE }; // should we revalidate next time? protected boolean invalidated = false; // our generation protected CacheGeneration generation = null; // Cached Entity tag HTTP list value for this resource. HttpEntityTag etags[] = null; // the extra headers protected ArrayDictionary a = null; // are we uploading or not? protected boolean uploading = false; public void notifyTeeFailure(int size) {}; public void notifyTeeSuccess(int size) {}; // the filter that is using this resource protected CacheFilter filter; /** * LRU management - previous entry. */ protected LRUAble prev = null; /** * LRU management - next entry. */ protected LRUAble next = null; /** * LRU management - Get next node. * @return A CvsDirectory instance. */ public LRUAble getNext() { return next; } /** * LRU management - Get previous node. * @return A CvsDirectory instance. */ public LRUAble getPrev() { return prev; } /** * LRU management - Set next node. * @return A CvsDirectory instance. */ public synchronized void setNext(LRUAble next) { this.next = next; } /** * LRU management - Set previous node. * @return A CvsDirectory instance. */ public synchronized void setPrev(LRUAble prev) { this.prev = prev; } /** * overrides the default setValue to invalidate the ETag */ public void setValue(int idx, Object value) { super.setValue(idx, value); if ( idx == ATTR_ETAG ) etags = null; } /** * returns the current age of this cached resource * @return an integer, the current age in seconds */ public abstract int getCurrentAge();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?