avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sylv...@apache.org
Subject cvs commit: avalon-excalibur/store/src/java/org/apache/excalibur/store/impl AbstractReadWriteStore.java MRUMemoryStore.java
Date Thu, 11 Dec 2003 14:19:19 GMT
sylvain     2003/12/11 06:19:19

  Modified:    store    project.xml
               store/src/java/org/apache/excalibur/store Store.java
               store/src/java/org/apache/excalibur/store/impl
                        AbstractReadWriteStore.java MRUMemoryStore.java
  Log:
  Distinguish ROLE from TRANSIENT_STORE, instrument implementations
  
  Revision  Changes    Path
  1.3       +5 -0      avalon-excalibur/store/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/store/project.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- project.xml	9 Nov 2003 13:34:40 -0000	1.2
  +++ project.xml	11 Dec 2003 14:19:19 -0000	1.3
  @@ -23,6 +23,11 @@
               <groupId>framework</groupId>
           </dependency>
           <dependency>
  +            <id>excalibur-instrument</id>
  +            <version>1.0</version>
  +            <groupId>excalibur-instrument</groupId>
  +        </dependency>
  +        <dependency>
               <id>jisp</id>
               <version>2.5.1</version>
           </dependency>
  
  
  
  1.2       +5 -5      avalon-excalibur/store/src/java/org/apache/excalibur/store/Store.java
  
  Index: Store.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/store/src/java/org/apache/excalibur/store/Store.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Store.java	9 Nov 2003 12:47:17 -0000	1.1
  +++ Store.java	11 Dec 2003 14:19:19 -0000	1.2
  @@ -61,8 +61,7 @@
    * your data is in the store (of course unless noone else did remove it).
    * In some cases (like for example a cache) the data needs not to be
    * persistent. Therefore with the two role TRANSIENT_STORE and
  - * PERSISTENT_STORE you get a store with exactly that behaviour. (The
  - * PERSISTENT_STORE is only an alias for ROLE).
  + * PERSISTENT_STORE you get a store with exactly that behaviour.
    *
    * @author <a href="mailto:scoobie@betaversion.org">Federico Barbieri</a>
    *         (Betaversion Productions)
  @@ -80,8 +79,9 @@
   
       /** The role for a transient store */
       String TRANSIENT_STORE = ROLE + "/TransientStore";
  -    /** The role for a persistent store (this is an alias for ROLE) */
  -    String PERSISTENT_STORE = ROLE;
  +    
  +    /** The role for a persistent store */
  +    String PERSISTENT_STORE = ROLE + "/PersistentStore";
   
       /**
        * Get the object associated to the given unique key.
  
  
  
  1.2       +48 -5     avalon-excalibur/store/src/java/org/apache/excalibur/store/impl/AbstractReadWriteStore.java
  
  Index: AbstractReadWriteStore.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/store/src/java/org/apache/excalibur/store/impl/AbstractReadWriteStore.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractReadWriteStore.java	9 Nov 2003 12:47:17 -0000	1.1
  +++ AbstractReadWriteStore.java	11 Dec 2003 14:19:19 -0000	1.2
  @@ -59,6 +59,10 @@
   
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
   import org.apache.avalon.framework.thread.ThreadSafe;
  +import org.apache.excalibur.instrument.CounterInstrument;
  +import org.apache.excalibur.instrument.Instrument;
  +import org.apache.excalibur.instrument.Instrumentable;
  +import org.apache.excalibur.instrument.ValueInstrument;
   import org.apache.excalibur.store.Store;
   
   /**
  @@ -72,6 +76,12 @@
   extends AbstractLogEnabled
   implements Store, ThreadSafe {
   
  +    private ValueInstrument m_sizeInstrument = new ValueInstrument("size");
  +    private CounterInstrument m_hitsInstrument = new CounterInstrument("hits");
  +    private CounterInstrument m_missesInstrument = new CounterInstrument("misses");
  +
  +    private String m_instrumentableName;
  +
       /** The lock */
       protected ReadWriteLock lock = new FIFOReadWriteLock();
       
  @@ -90,7 +100,7 @@
               sync.acquire();
               try 
               {
  -                this.doGet(key);
  +                value = this.doGet(key);
               }
               finally 
               {
  @@ -101,6 +111,15 @@
           {
           } 
           
  +        if ( null == value )
  +        {
  +            m_missesInstrument.increment();
  +        }
  +        else
  +        {
  +            m_hitsInstrument.increment();
  +        }
  +        
           return value;
       }
   
  @@ -122,6 +141,7 @@
               try 
               {
                   this.doStore(key, value);
  +                m_sizeInstrument.setValue( doGetSize() );
               } 
               finally 
               {
  @@ -130,7 +150,8 @@
           }
           catch (InterruptedException ignore)
           {
  -        } 
  +        }
  +        
       }
   
       /**
  @@ -146,6 +167,7 @@
               try 
               {
                   this.doFree();
  +                m_sizeInstrument.setValue( doGetSize() );
               } 
               finally 
               {
  @@ -175,6 +197,7 @@
               try 
               {
                   this.doClear();
  +                m_sizeInstrument.setValue( 0 );
               }
               finally 
               {
  @@ -183,7 +206,7 @@
           }
           catch (InterruptedException ignore)
           {
  -        } 
  +        }
       }
   
       /**
  @@ -200,6 +223,7 @@
               try 
               {
                   this.doRemove(key);
  +                m_sizeInstrument.setValue( doGetSize() );
               }
               finally 
               {
  @@ -208,7 +232,7 @@
           }
           catch (InterruptedException ignore)
           {
  -        } 
  +        }
       }
   
       /**
  @@ -283,6 +307,25 @@
           {
               return 0;
           } 
  +    }
  +
  +    public void setInstrumentableName(String name)
  +    {
  +        m_instrumentableName = name;    
  +    }
  +
  +    public String getInstrumentableName()
  +    {
  +        return m_instrumentableName;
  +    }
  +
  +    public Instrument[] getInstruments()
  +    {
  +        return new Instrument[] { m_sizeInstrument, m_hitsInstrument, m_missesInstrument
};
  +    }
  +
  +    public Instrumentable[] getChildInstrumentables() {
  +        return Instrumentable.EMPTY_INSTRUMENTABLE_ARRAY;
       }
   
       /**
  
  
  
  1.2       +40 -5     avalon-excalibur/store/src/java/org/apache/excalibur/store/impl/MRUMemoryStore.java
  
  Index: MRUMemoryStore.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/store/src/java/org/apache/excalibur/store/impl/MRUMemoryStore.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MRUMemoryStore.java	9 Nov 2003 12:47:17 -0000	1.1
  +++ MRUMemoryStore.java	11 Dec 2003 14:19:19 -0000	1.2
  @@ -64,6 +64,10 @@
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.avalon.framework.service.Serviceable;
   import org.apache.avalon.framework.thread.ThreadSafe;
  +import org.apache.excalibur.instrument.CounterInstrument;
  +import org.apache.excalibur.instrument.Instrument;
  +import org.apache.excalibur.instrument.Instrumentable;
  +import org.apache.excalibur.instrument.ValueInstrument;
   import org.apache.excalibur.store.Store;
   import org.apache.excalibur.store.StoreJanitor;
   
  @@ -82,10 +86,11 @@
    * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
    * @version CVS $Id$
    */
  -public final class MRUMemoryStore
  +public class MRUMemoryStore
       extends AbstractLogEnabled
  -    implements Store, Parameterizable, Serviceable, Disposable, ThreadSafe
  +    implements Store, Parameterizable, Serviceable, Disposable, ThreadSafe, Instrumentable
   {
  +    private String m_instrumentableName;
       private int m_maxobjects;
       private boolean m_persistent;
       private Hashtable m_cache;
  @@ -93,6 +98,10 @@
       private Store m_persistentStore;
       private StoreJanitor m_storeJanitor;
       private ServiceManager m_manager;
  +    
  +    private ValueInstrument m_sizeInstrument = new ValueInstrument("size");
  +    private CounterInstrument m_hitsInstrument = new CounterInstrument("hits");
  +    private CounterInstrument m_missesInstrument = new CounterInstrument("misses");
   
       /**
        * Get components of the ComponentLocator
  @@ -242,6 +251,7 @@
           m_cache.put( key, value );
           m_mrulist.remove( key );
           m_mrulist.addFirst( key );
  +        m_sizeInstrument.setValue( m_mrulist.size() );
       }
   
       /**
  @@ -262,6 +272,7 @@
               {
                   getLogger().debug( "Found key: " + key.toString() );
               }
  +            m_hitsInstrument.increment();
               return value;
           }
   
  @@ -282,16 +293,16 @@
                       {
                           hold( key, value );
                       }
  +                    m_hitsInstrument.increment();
                       return value;
                   }
                   catch( Exception e )
                   {
                       getLogger().error( "Error in get()!", e );
  -                    return null;
                   }
               }
           }
  -
  +        m_missesInstrument.increment();
           return null;
       }
   
  @@ -309,6 +320,8 @@
           }
           m_cache.remove( key );
           m_mrulist.remove( key );
  +        m_sizeInstrument.setValue( m_mrulist.size() );
  +        
           if( m_persistent && key != null )
           {
               m_persistentStore.remove( key );
  @@ -330,6 +343,7 @@
               }
               remove( key );
           }
  +        m_sizeInstrument.setValue( 0 );
       }
   
       /**
  @@ -409,6 +423,8 @@
                           }
                       }
                   }
  +                
  +                m_sizeInstrument.setValue( m_mrulist.size() );
               }
           }
           catch( NoSuchElementException e )
  @@ -433,6 +449,25 @@
           if( object == null ) return false;
   
           return ( object instanceof java.io.Serializable );
  +    }
  +
  +    public void setInstrumentableName(String name)
  +    {
  +        m_instrumentableName = name;    
  +    }
  +
  +    public String getInstrumentableName()
  +    {
  +        return m_instrumentableName;
  +    }
  +
  +    public Instrument[] getInstruments()
  +    {
  +        return new Instrument[] { m_sizeInstrument, m_hitsInstrument, m_missesInstrument
};
  +    }
  +
  +    public Instrumentable[] getChildInstrumentables() {
  +        return Instrumentable.EMPTY_INSTRUMENTABLE_ARRAY;
       }
   }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org


Mime
View raw message