vgritsenko    02/02/01 05:27:33

  Modified:    .        changes.xml
               src/java/org/apache/cocoon/components/store
                        FilesystemStore.java MRUMemoryStore.java
                        MemoryStore.java Store.java StoreJanitorImpl.java
               src/scratchpad/src/org/apache/cocoon/jispstore
                        JispFilesystemStore.java MRUMemoryStore.java
  Log:
  Add size() to the Store interface
  
  Revision  Changes    Path
  1.91      +4 -1      xml-cocoon2/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/changes.xml,v
  retrieving revision 1.90
  retrieving revision 1.91
  diff -u -r1.90 -r1.91
  --- changes.xml       31 Jan 2002 19:42:41 -0000      1.90
  +++ changes.xml       1 Feb 2002 13:27:32 -0000       1.91
  @@ -4,7 +4,7 @@
   
   <!--
     History of Cocoon changes
  -  $Id: changes.xml,v 1.90 2002/01/31 19:42:41 stefano Exp $
  +  $Id: changes.xml,v 1.91 2002/02/01 13:27:32 vgritsenko Exp $
   -->
   
   <changes title="History of Changes">
  @@ -31,6 +31,9 @@
    </devs>
   
    <release version="@version@" date="@date@">
  +  <action dev="VG" type="add">
  +    Added size() method to the Store interface.
  +  </action>
     <action dev="GP" type="fixed">
       Prevent PostInputStream from looping if the available() method of the base 
       InputStream is returning 0.
  
  
  
  1.3       +25 -4     
xml-cocoon2/src/java/org/apache/cocoon/components/store/FilesystemStore.java
  
  Index: FilesystemStore.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/store/FilesystemStore.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FilesystemStore.java      22 Jan 2002 00:17:12 -0000      1.2
  +++ FilesystemStore.java      1 Feb 2002 13:27:32 -0000       1.3
  @@ -169,23 +169,44 @@
       /**
        * Returns the list of stored files as an Enumeration of Files
        */
  -   public Enumeration keys() {
  +    public Enumeration keys() {
           final FSEnumeration enum = new FSEnumeration();
           this.addKeys(enum, this.directoryFile);
           return enum;
       }
   
  -    protected void addKeys(FSEnumeration enum,
  -                           File  directory) {
  +    /**
  +     * Returns count of the objects in the store, or -1 if could not be
  +     * obtained.
  +     */
  +    public int size() {
  +        return countKeys(this.directoryFile);
  +    }
  +
  +    protected void addKeys(FSEnumeration enum, File directory) {
           final int subStringBegin = this.directoryFile.getAbsolutePath().length() + 
1;
           final File[] files = directory.listFiles();
  -        for(int i=0; i<files.length; i++) {
  +        for (int i=0; i<files.length; i++) {
               if (files[i].isDirectory()) {
                   this.addKeys(enum, files[i]);
               } else {
                   enum.add(files[i].getAbsolutePath().substring(subStringBegin));
               }
           }
  +    }
  +
  +    protected int countKeys(File directory) {
  +        int count = 0;
  +        final int subStringBegin = this.directoryFile.getAbsolutePath().length() + 
1;
  +        final File[] files = directory.listFiles();
  +        for (int i=0; i<files.length; i++) {
  +            if (files[i].isDirectory()) {
  +                count += this.countKeys(files[i]);
  +            } else {
  +                count ++;
  +            }
  +        }
  +        return count;
       }
   
       final class FSEnumeration implements Enumeration {
  
  
  
  1.6       +9 -0      
xml-cocoon2/src/java/org/apache/cocoon/components/store/MRUMemoryStore.java
  
  Index: MRUMemoryStore.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/store/MRUMemoryStore.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- MRUMemoryStore.java       29 Jan 2002 19:39:54 -0000      1.5
  +++ MRUMemoryStore.java       1 Feb 2002 13:27:32 -0000       1.6
  @@ -286,6 +286,15 @@
       }
   
       /**
  +     * Returns count of the objects in the store, or -1 if could not be
  +     * obtained.
  +     */
  +    public int size()
  +    {
  +        return this.cache.size();
  +    }
  +
  +    /**
        * Frees some of the fast memory used by this store.
        * It removes the last element in the store.
        */
  
  
  
  1.2       +10 -1     
xml-cocoon2/src/java/org/apache/cocoon/components/store/MemoryStore.java
  
  Index: MemoryStore.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/store/MemoryStore.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MemoryStore.java  3 Jan 2002 12:31:14 -0000       1.1
  +++ MemoryStore.java  1 Feb 2002 13:27:32 -0000       1.2
  @@ -20,7 +20,7 @@
    *         (Apache Software Foundation)
    * @author <a href="mailto:[EMAIL PROTECTED]";>Pierpaolo Fumagalli</a>
    *         (Apache Software Foundation, Exoffice Technologies)
  - * @version CVS $Revision: 1.1 $ $Date: 2002/01/03 12:31:14 $
  + * @version CVS $Revision: 1.2 $ $Date: 2002/02/01 13:27:32 $
    */
   public class MemoryStore implements Store, ThreadSafe {
       /* WARNING: Hashtable is threadsafe, whereas HashMap is not.
  @@ -82,5 +82,14 @@
        */
       public Enumeration keys() {
           return(table.keys());
  +    }
  +
  +    /**
  +     * Returns count of the objects in the store, or -1 if could not be
  +     * obtained.
  +     */
  +    public int size()
  +    {
  +        return table.size();
       }
   }
  
  
  
  1.2       +6 -1      
xml-cocoon2/src/java/org/apache/cocoon/components/store/Store.java
  
  Index: Store.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/store/Store.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Store.java        3 Jan 2002 12:31:14 -0000       1.1
  +++ Store.java        1 Feb 2002 13:27:32 -0000       1.2
  @@ -20,7 +20,7 @@
    *         (Apache Software Foundation)
    * @author <a href="mailto:[EMAIL PROTECTED]";>Pierpaolo Fumagalli</a>
    *         (Apache Software Foundation, Exoffice Technologies)
  - * @version CVS $Revision: 1.1 $ $Date: 2002/01/03 12:31:14 $
  + * @version CVS $Revision: 1.2 $ $Date: 2002/02/01 13:27:32 $
    */
   public interface Store extends Component {
   
  @@ -62,4 +62,9 @@
        */
       Enumeration keys();
   
  +    /**
  +     * Returns count of the objects in the store, or -1 if could not be
  +     * obtained.
  +     */
  +    int size();
   }
  
  
  
  1.7       +8 -21     
xml-cocoon2/src/java/org/apache/cocoon/components/store/StoreJanitorImpl.java
  
  Index: StoreJanitorImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/store/StoreJanitorImpl.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- StoreJanitorImpl.java     28 Jan 2002 19:57:52 -0000      1.6
  +++ StoreJanitorImpl.java     1 Feb 2002 13:27:32 -0000       1.7
  @@ -44,7 +44,7 @@
       private ArrayList storelist;
       private int index = -1;
       private static boolean doRun = false;
  -    private int m_percent;
  +    private double fraction;
   
       /**
        * Initialize the StoreJanitorImpl.
  @@ -71,7 +71,7 @@
           
this.setCleanupthreadinterval(params.getParameterAsInteger("cleanupthreadinterval",10));
           this.setPriority(params.getParameterAsInteger( "threadpriority",
                                           Thread.currentThread().getPriority()));
  -        this.m_percent = params.getParameterAsInteger( "percent_to_free",10);
  +        int percent = params.getParameterAsInteger("percent_to_free", 10);
   
           if ((this.getFreememory() < 1)) {
               throw new ConfigurationException("StoreJanitorImpl freememory parameter 
has to be greater then 1");
  @@ -85,10 +85,11 @@
           if ((this.getPriority() < 1)) {
               throw new ConfigurationException("StoreJanitorImpl threadpriority has 
to be greater then 1");
           }
  -        if ((this.m_percent > 100 && this.m_percent < 1)) {
  +        if ((percent > 100 && percent < 1)) {
               throw new ConfigurationException("StoreJanitorImpl percent_to_free, has 
to be between 1 and 100");
           }
   
  +        this.fraction = percent / 100.0;
           this.setStoreList(new ArrayList());
       }
   
  @@ -281,26 +282,12 @@
        * @return number of elements to be removed!
        */
       private int calcToFree(Store store) {
  -        int cnt = 0;
  -        try {
  -            this.getLogger().debug("Calculating percentage!");
  -            Enumeration enum = store.keys();
  -            
  -            while(enum.hasMoreElements()) {
  -                cnt++; 
  -                enum.nextElement(); 
  -            }
  -            
  -            this.getLogger().debug("Counted: " + cnt);
  -            double fac = new Integer(this.m_percent).doubleValue() / 100;
  -            double dcnt = new Integer(cnt).doubleValue();
  -            this.getLogger().debug("Calculated: " + new Double(dcnt * 
fac).intValue());
  -            
  -            return new Double(dcnt * fac).intValue();
  -        } catch (Exception e) {
  -            this.getLogger().error("",e);
  +        int cnt = store.size();
  +        if (cnt < 0) {
  +            getLogger().debug("Unknown size of the store: " + store);
               return 0;
           }
  +        return (int)(cnt * fraction);
       }
       
       /**
  
  
  
  1.5       +5 -0      
xml-cocoon2/src/scratchpad/src/org/apache/cocoon/jispstore/JispFilesystemStore.java
  
  Index: JispFilesystemStore.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/jispstore/JispFilesystemStore.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JispFilesystemStore.java  15 Jan 2002 18:16:16 -0000      1.4
  +++ JispFilesystemStore.java  1 Feb 2002 13:27:32 -0000       1.5
  @@ -337,6 +337,11 @@
           return null;
       }
   
  +    public int size() {
  +        //TODO: Implementation
  +        return 0;
  +    }
  +
       /**
        * This method wraps around the key Object a Jisp KeyObject.
        * 
  
  
  
  1.5       +4 -0      
xml-cocoon2/src/scratchpad/src/org/apache/cocoon/jispstore/MRUMemoryStore.java
  
  Index: MRUMemoryStore.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/jispstore/MRUMemoryStore.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- MRUMemoryStore.java       15 Jan 2002 18:16:16 -0000      1.4
  +++ MRUMemoryStore.java       1 Feb 2002 13:27:32 -0000       1.5
  @@ -235,6 +235,10 @@
           return this.mCache.keys();
       }
   
  +    public int size() {
  +        return this.mCache.size();
  +    }
  +
       /**
        *  Frees some of the fast memory used by this store. It removes the last
        *  element in the store.
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to