tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/naming/resources ProxyDirContext.java
Date Mon, 07 Oct 2002 08:25:37 GMT
remm        2002/10/07 01:25:37

  Modified:    catalina/src/share/org/apache/naming/resources
                        ProxyDirContext.java
  Log:
  - Port patch.
  - Fix caching bugs.
  
  Revision  Changes    Path
  1.2       +31 -23    jakarta-tomcat-catalina/catalina/src/share/org/apache/naming/resources/ProxyDirContext.java
  
  Index: ProxyDirContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/naming/resources/ProxyDirContext.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ProxyDirContext.java	18 Jul 2002 16:47:34 -0000	1.1
  +++ ProxyDirContext.java	7 Oct 2002 08:25:37 -0000	1.2
  @@ -267,7 +267,6 @@
           if (entry != null) {
               if (entry.resource != null) {
                   // Check content caching.
  -                
                   return entry.resource;
               } else {
                   return entry.context;
  @@ -1375,7 +1374,8 @@
       /**
        * Lookup in cache.
        */
  -    protected CacheEntry cacheLookup(String name) {
  +    protected CacheEntry cacheLookup(String name)
  +        throws NamingException {
           if (cache == null)
               return (null);
           CacheEntry cacheEntry = (CacheEntry) cache.get(name);
  @@ -1383,9 +1383,7 @@
               cacheEntry = new CacheEntry();
               cacheEntry.name = name;
               // Load entry
  -            if (!cacheLoad(cacheEntry))
  -                return null;
  -            return (cacheEntry);
  +            cacheLoad(cacheEntry);
           } else {
               if (!validate(cacheEntry)) {
                   if (!revalidate(cacheEntry)) {
  @@ -1396,8 +1394,11 @@
                           System.currentTimeMillis() + cacheTTL;
                   }
               }
  -            return (cacheEntry);
           }
  +        if (!cacheEntry.exists) {
  +            throw new NamingException("Resource not found");
  +        }
  +        return (cacheEntry);
       }
   
   
  @@ -1405,8 +1406,10 @@
        * Validate entry.
        */
       protected boolean validate(CacheEntry entry) {
  -        if ((entry.resource != null) 
  -            && (entry.resource.getContent() != null) 
  +        if (((!entry.exists)
  +             || (entry.context != null)
  +             || ((entry.resource != null) 
  +                 && (entry.resource.getContent() != null)))
               && (System.currentTimeMillis() < entry.timestamp)) {
               return true;
           }
  @@ -1420,6 +1423,8 @@
       protected boolean revalidate(CacheEntry entry) {
           // Get the attributes at the given path, and check the last 
           // modification date
  +        if (!entry.exists)
  +            return false;
           if (entry.attributes == null)
               return false;
           long lastModified = entry.attributes.getLastModified();
  @@ -1447,14 +1452,12 @@
       /**
        * Load entry into cache.
        */
  -    protected boolean cacheLoad(CacheEntry entry) {
  -
  -        if (cache == null)
  -            return false;
  +    protected void cacheLoad(CacheEntry entry) {
   
           String name = entry.name;
   
           // Retrieve missing info
  +        boolean exists = true;
   
           // Retrieving attributes
           if (entry.attributes == null) {
  @@ -1467,12 +1470,12 @@
                       entry.attributes = (ResourceAttributes) attributes;
                   }
               } catch (NamingException e) {
  -                return false;
  +                exists = false;
               }
           }
   
           // Retriving object
  -        if ((entry.resource == null) && (entry.context == null)) {
  +        if ((exists) && (entry.resource == null) && (entry.context == null))
{
               try {
                   Object object = dirContext.lookup(name);
                   if (object instanceof InputStream) {
  @@ -1486,12 +1489,13 @@
                           (object.toString().getBytes()));
                   }
               } catch (NamingException e) {
  -                return false;
  +                exists = false;
               }
           }
   
           // Load object content
  -        if ((entry.resource != null) && (entry.resource.getContent() == null) 
  +        if ((exists) && (entry.resource != null) 
  +            && (entry.resource.getContent() == null) 
               && (entry.attributes.getContentLength() >= 0)
               && (entry.attributes.getContentLength() < cacheObjectMaxSize)) {
               int length = (int) entry.attributes.getContentLength();
  @@ -1518,15 +1522,16 @@
                   }
               }
           }
  -        
  +
  +        // Set existence flag
  +        entry.exists = exists;
  +
           // Set timestamp
           entry.timestamp = System.currentTimeMillis() + cacheTTL;
   
           // Add new entry to cache
           cache.put(name, entry);
   
  -        return true;
  -
       }
   
   
  @@ -1554,6 +1559,7 @@
           ResourceAttributes attributes = null;
           Resource resource = null;
           DirContext context = null;
  +        boolean exists = true;
   
   
           // ----------------------------------------------------- Public Methods
  @@ -1565,11 +1571,13 @@
               attributes = null;
               resource = null;
               context = null;
  +            exists = true;
           }
   
   
           public String toString() {
               return ("Cache entry: " + name + "\n"
  +                    + "Exists: " + exists + "\n"
                       + "Attributes: " + attributes + "\n"
                       + "Resource: " + resource + "\n"
                       + "Context: " + context);
  
  
  

--
To unsubscribe, e-mail:   <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-dev-help@jakarta.apache.org>


Mime
View raw message