asmuts      02/02/21 22:05:22

  Modified:    src/java/org/apache/stratum/jcs/auxiliary/disk/indexed
                        IndexedDiskCache.java
               src/java/org/apache/stratum/jcs/engine/control Cache.java
  Log:
  cleaned up a bit and added idle time expiration to cache hub
  
  Revision  Changes    Path
  1.3       +7 -34     
jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/disk/indexed/IndexedDiskCache.java
  
  Index: IndexedDiskCache.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/disk/indexed/IndexedDiskCache.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- IndexedDiskCache.java     18 Feb 2002 17:14:23 -0000      1.2
  +++ IndexedDiskCache.java     22 Feb 2002 06:05:22 -0000      1.3
  @@ -271,7 +271,7 @@
       // end loadKeys
   
       /**
  -     * Description of the Method
  +     * Saves key file to disk
        */
       public void saveKeys()
       {
  @@ -366,7 +366,9 @@
   
   
       /**
  -     * Description of the Method
  +     * Update the disk cache. Called from the Queue. Makes sure the Item has not
  +     * been retireved from purgatory while in queue for disk. Remove items from
  +     * purgatory when they go to disk.
        *
        * @param ce
        * @exception IOException
  @@ -393,15 +395,7 @@
                   return;
               }
           }
  -        /*
  -         * if ( ce instanceof IDiskElement ) {
  -         * IDiskElement ide = (IDiskElement)ce;
  -         * if ( !ide.getIsSpoolable() ) {
  -         * it has been plucked from purgatory
  -         * return;
  -         * }
  -         * }
  -         */
  +
           // remove item from purgatory since we are putting it on disk
           // assume that the disk cache will never break
           // disk breakage is akin to an out of memory exception
  @@ -412,8 +406,6 @@
               log.debug( "putting " + ce.getKey() + " on disk, removing from 
purgatory" );
           }
   
  -        //System.out.println( "putting " + ce );
  -
           IndexedDiskElementDescriptor ded = null;
           try
           {
  @@ -431,9 +423,6 @@
                   {
                       return;
                   }
  -                // Presume it's an append.
  -                //DiskElement re = new DiskElement( cacheName, key, value );
  -                //re.init( dataFile.length(), data );
   
                   IndexedDiskElementDescriptor old = ( IndexedDiskElementDescriptor ) 
keyHash.put( ce.getKey(), ded );
   
  @@ -444,21 +433,6 @@
                       ded.pos = old.pos;
                   }
                   dataFile.write( data, ded.pos );
  -                /*
  -                 * Only need to write if the item with the same key and value
  -                 * does not already exist in the file.
  -                 * if (re.equals(old)) {
  -                 * re.pos = old.pos;
  -                 * }
  -                 * else {
  -                 * Item with the same key but different value already exists in 
file.
  -                 * Try to reuse the location if possible.
  -                 * if (old != null && re.len <= old.len) {
  -                 * re.pos = old.pos;
  -                 * }
  -                 * dataFile.write(data, re.pos);
  -                 * }
  -                 */
               }
               finally
               {
  @@ -550,7 +524,7 @@
   
                   obj = dataFile.readObject( ded.pos );
               }
  -            //System.out.println( "got element = " + (CacheElement)obj);
  +
           }
           catch ( NullPointerException e )
           {
  @@ -638,9 +612,8 @@
       }
       // end removeAll
   
  -    // handle error by last resort, force content update, or removeall
       /**
  -     * Description of the Method
  +     * handle error by last resort, force content update, or removeall
        */
       public void reset()
       {
  
  
  
  1.19      +136 -56   
jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/engine/control/Cache.java
  
  Index: Cache.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/engine/control/Cache.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- Cache.java        18 Feb 2002 18:17:20 -0000      1.18
  +++ Cache.java        22 Feb 2002 06:05:22 -0000      1.19
  @@ -93,7 +93,9 @@
   {
       private final static Log log = LogSource.getInstance( Cache.class );
   
  -    /** not used for much */
  +    /**
  +     * not used for much
  +     */
       public final String className;
   
       // Auxiliary caches.
  @@ -106,10 +108,14 @@
       // this is int he cacheAttr, shouldn't be used, remove
       final String cacheName;
   
  -    /** Region Elemental Attributes, default */
  +    /**
  +     * Region Elemental Attributes, default
  +     */
       public IElementAttributes attr;
   
  -    /** Cache Attributes, for hub and memory auxiliary */
  +    /**
  +     * Cache Attributes, for hub and memory auxiliary
  +     */
       public ICompositeCacheAttributes cacheAttr;
   
       private String source_id = "org.apache.stratum.jcs.engine.control.Cache";
  @@ -162,8 +168,6 @@
               this.auxHit = new int[auxCaches.length];
           }
   
  -        // set from props
  -        // also need to add cache attributes
           this.attr = attr;
           this.cacheAttr = cattr;
   
  @@ -185,6 +189,7 @@
        *
        * @deprecated
        * @see this will become protected
  +     * @param ce
        */
       public void add( ICacheElement ce )
       {
  @@ -200,7 +205,14 @@
       }
   
   
  -    /** Will no override existing items. */
  +    /**
  +     * Will no override existing items.
  +     *
  +     * @param key
  +     * @param val
  +     * @exception IOException
  +     * @exception ObjectExistsException
  +     */
       public void putSafe( Serializable key, Serializable val )
           throws IOException, ObjectExistsException
       {
  @@ -216,7 +228,13 @@
       }
   
   
  -    /** Put in cache and configured auxiliaries. */
  +    /**
  +     * Put in cache and configured auxiliaries.
  +     *
  +     * @param key
  +     * @param val
  +     * @exception IOException
  +     */
       public void put( Serializable key, Serializable val )
           throws IOException
       {
  @@ -231,16 +249,11 @@
        * @param key Cache key
        * @param val Value to cache
        * @param attr Element attributes
  +     * @exception IOException
        */
       public void put( Serializable key, Serializable val, IElementAttributes attr )
           throws IOException
       {
  -        //p( "puting in cache" );
  -        // make active after implementing replace
  -        // to slow to justify this feature
  -        //if ( this.get( key ) != null ) {
  -        //  throw new ObjectExistsException( "Object exists for key " + key );
  -        //}
   
           if ( key == null || val == null )
           {
  @@ -271,6 +284,7 @@
        * @param key Cache key
        * @param val Value to cache
        * @param attr Element attributes
  +     * @exception IOException
        */
       protected synchronized void updateCaches( Serializable key, Serializable val, 
IElementAttributes attr )
           throws IOException
  @@ -287,7 +301,15 @@
       }
   
   
  -    /** Description of the Method */
  +    /**
  +     * Description of the Method
  +     *
  +     * @param key
  +     * @param val
  +     * @param attr
  +     * @param updateRemoteCache
  +     * @exception IOException
  +     */
       protected synchronized void updateCaches( Serializable key, Serializable val, 
IElementAttributes attr, boolean updateRemoteCache )
           throws IOException
       {
  @@ -304,7 +326,12 @@
       }
   
   
  -    /** Standard update method */
  +    /**
  +     * Standard update method
  +     *
  +     * @param ce
  +     * @exception IOException
  +     */
       public synchronized void update( ICacheElement ce )
           throws IOException
       {
  @@ -322,6 +349,8 @@
        * Description of the Method
        *
        * @param updateRemoteCache Should the nonlocal caches be updated
  +     * @param ce
  +     * @exception IOException
        */
       public void update( ICacheElement ce, boolean updateRemoteCache )
           throws IOException
  @@ -330,7 +359,13 @@
       }
   
   
  -    /** Description of the Method */
  +    /**
  +     * Description of the Method
  +     *
  +     * @param ce
  +     * @param updateRemoteCache
  +     * @exception IOException
  +     */
       public synchronized void updateExclude( ICacheElement ce, boolean 
updateRemoteCache )
           throws IOException
       {
  @@ -386,7 +421,7 @@
                   {
                       log.debug( "ce.getElementAttributes().getIsRemote() = " + 
ce.getElementAttributes().getIsRemote() );
                   }
  -                //if ( first.ce.getElementAttributes().getIsRemote() && 
updateRemoteCache) {
  +
                   if ( ce.getElementAttributes().getIsRemote() && updateRemoteCache )
                   {
                       try
  @@ -398,7 +433,7 @@
                           {
                               log.debug( "Updated remote store for " + ce.getKey() + 
ce );
                           }
  -                        //p( "Updated remote store for " + ce.getKey() + ce );
  +
                       }
                       catch ( IOException ex )
                       {
  @@ -490,6 +525,9 @@
        * Gets an item from the cache, and make it the first in the link list.
        *
        * @return The cacheElement value
  +     * @param key
  +     * @exception ObjectNotFoundException
  +     * @exception IOException
        */
       public Serializable getCacheElement( Serializable key )
           throws ObjectNotFoundException, IOException
  @@ -498,21 +536,39 @@
       }
       // end get ce
   
  -    /** Description of the Method */
  +    /**
  +     * Description of the Method
  +     *
  +     * @return
  +     * @param key
  +     */
       public Serializable get( Serializable key )
       {
           return get( key, false, this.LOCAL_INVOKATION );
       }
   
   
  -    /** Description of the Method */
  +    /**
  +     * Description of the Method
  +     *
  +     * @return
  +     * @param key
  +     * @param container
  +     */
       public Serializable get( Serializable key, boolean container )
       {
           return get( key, container, this.LOCAL_INVOKATION );
       }
   
   
  -    /** Description of the Method */
  +    /**
  +     * Description of the Method
  +     *
  +     * @return
  +     * @param key
  +     * @param container
  +     * @param invocation
  +     */
       public Serializable get( Serializable key, boolean container, boolean 
invocation )
       {
           if ( log.isDebugEnabled() )
  @@ -631,19 +687,38 @@
           try
           {
   
  -            // Cache item found in memory.  See if it has expired.
  -            // If shrinking is on this will be a second level of protection
  -            if ( !ce.getElementAttributes().getIsEternal() && ( ( 
System.currentTimeMillis() - ce.getElementAttributes().getCreateTime() ) > ( 
ce.getElementAttributes().getMaxLifeSeconds() * 1000 ) ) )
  +            if ( !ce.getElementAttributes().getIsEternal() )
               {
  -                if ( log.isInfoEnabled() )
  +
  +                long now = System.currentTimeMillis();
  +
  +                // Exceeded maxLifeSeconds
  +                if ( ( ce.getElementAttributes().getMaxLifeSeconds() != -1 ) && ( 
now - ce.getElementAttributes().getCreateTime() ) > ( 
ce.getElementAttributes().getMaxLifeSeconds() * 1000 ) )
                   {
  -                    log.info( ce.getKey() + " expired" );
  +                    if ( log.isInfoEnabled() )
  +                    {
  +                        log.info( "Exceeded maxLifeSeconds -- " + ce.getKey() );
  +                    }
  +                    this.remove( key );
  +                    //cache.remove( me.ce.getKey() );
  +                    return null;
  +                }
  +                else
  +                // NOT SURE IF THIS REALLY BELONGS HERE.  WHAT IS THE
  +                // POINT OF IDLE TIME?  SEEMS OK
  +                // Exceeded maxIdleTime, removal
  +                    if ( ( ce.getElementAttributes().getIdleTime() != -1 ) && ( now 
- ce.getElementAttributes().getLastAccessTime() ) > ( 
ce.getElementAttributes().getIdleTime() * 1000 ) )
  +                {
  +                    if ( log.isInfoEnabled() )
  +                    {
  +                        log.info( "Exceeded maxIdleTime [ 
ce.getElementAttributes().getIdleTime() = " + ce.getElementAttributes().getIdleTime() 
+ " ]-- " + ce.getKey() );
  +                    }
  +                    this.remove( key );
  +                    //cache.remove( me.ce.getKey() );
  +                    return null;
                   }
  -
  -                this.remove( key );
  -                //throw new ObjectNotFoundException( key + " expired from cache" );
  -                return null;
               }
  +
           }
           catch ( Exception e )
           {
  @@ -663,17 +738,14 @@
       }
       // end get
   
  -    /** Lateral removal */
  -    public void removeLateralDirect( Serializable key )
  -    {
  -        // can't expect a lateral aux cache.  This is a removal tool.
  -
  -        //DeleteLateralCacheMulticaster dlcm = new DeleteLateralCacheMulticaster( 
cacheName, (String)key, cacheAttr.getLateralCacheAddrs(), 
cacheAttr.getLateralDeleteServlet()  );
  -        //dlcm.multicast();
  -    }
   
   
  -    /** Removes an item from the cache. */
  +    /**
  +     * Removes an item from the cache.
  +     *
  +     * @return
  +     * @param key
  +     */
       public boolean remove( Serializable key )
       {
           return remove( key, LOCAL_INVOKATION );
  @@ -694,8 +766,11 @@
        * configured, only laterally propagated then they would go out of synch.
        * The same could happen for multiple remotes. If this looks necessary we
        * will need to build in an identifier to specify the source of a removal.
  +     *
  +     * @return
  +     * @param key
  +     * @param nonLocal
        */
  -    // invoked by CacheManager.
       // can't be protected because groupcache method needs to be called from access
       public synchronized boolean remove( Serializable key, boolean nonLocal )
       {
  @@ -705,7 +780,6 @@
               log.debug( "remove> key=" + key + ", nonLocal=" + nonLocal );
           }
   
  -        //p("remove> key="+key+", nonLocal="+nonLocal);
           boolean removed = false;
   
           try
  @@ -737,7 +811,7 @@
               try
               {
                   boolean b = aux.remove( key );
  -                //p( "removed aux.getCacheType() = " + aux.getCacheType() );
  +
                   // Don't take the remote removal into account.
                   if ( !removed && cacheType != REMOTE_CACHE )
                   {
  @@ -753,11 +827,13 @@
       }
       // end remove
   
  -    /** Removes all cached items. */
  +    /**
  +     * Removes all cached items.
  +     */
       public synchronized void removeAll()
       {
   
  -        //map = new HashMap();
  +
           try
           {
               memCache.removeAll();
  @@ -798,8 +874,11 @@
       }
   
   
  -    // invoked only by CacheManager.
  -    /** Description of the Method */
  +    /**
  +     * invoked only by CacheManager.
  +     *
  +     * @param fromRemote
  +     */
       protected void dispose( boolean fromRemote )
       {
           if ( !alive )
  @@ -960,7 +1039,6 @@
        */
       public int getSize()
       {
  -        //return map.size();
           return memCache.getSize();
       }
   
  @@ -987,7 +1065,11 @@
       }
   
   
  -    /** Description of the Method */
  +    /**
  +     * Description of the Method
  +     *
  +     * @param ex
  +     */
       private void handleException( IOException ex )
       {
           ex.printStackTrace();
  @@ -1042,6 +1124,9 @@
        * Gets the elementAttributes attribute of the Cache object
        *
        * @return The elementAttributes value
  +     * @param key
  +     * @exception CacheException
  +     * @exception IOException
        */
       public IElementAttributes getElementAttributes( Serializable key )
           throws CacheException, IOException
  @@ -1060,6 +1145,9 @@
        * making this an auxiliary, despite its close tie to the CacheHub. TODO:
        * might want to create a memory cache config file separate from that of the
        * hub -- ICompositeCacheAttributes
  +     *
  +     * @return
  +     * @param cattr
        */
       private IMemoryCache createMemoryCache( ICompositeCacheAttributes cattr )
       {
  @@ -1088,13 +1176,5 @@
       }
       // end createMemoryCache
   
  -//  ////////////////////////////////////
  -//  public void dumpMap() {
  -//    memCache.dumpMap();
  -//  }
  -//  //////////////////////////////////////
  -//  public void dumpCacheEntries() {
  -//    memCache.dumpCacheEntries();
  -//  }
   
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to