cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From froehl...@apache.org
Subject cvs commit: xml-cocoon2/scratchpad/src/org/apache/cocoon/jispstore JispStringKey.java MRUMemoryStore.java JispFilesystemStore.java JispKey.java
Date Sat, 15 Dec 2001 14:29:04 GMT
froehlich    01/12/15 06:29:04

  Modified:    scratchpad/src/org/apache/cocoon/jispstore
                        MRUMemoryStore.java JispFilesystemStore.java
  Added:       scratchpad/src/org/apache/cocoon/jispstore
                        JispStringKey.java
  Removed:     scratchpad/src/org/apache/cocoon/jispstore JispKey.java
  Log:
  renamed Key class and optimized code
  
  Revision  Changes    Path
  1.5       +40 -14    xml-cocoon2/scratchpad/src/org/apache/cocoon/jispstore/MRUMemoryStore.java
  
  Index: MRUMemoryStore.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/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	2001/12/14 15:02:32	1.4
  +++ MRUMemoryStore.java	2001/12/15 14:29:04	1.5
  @@ -59,11 +59,17 @@
        */
       public void compose(ComponentManager manager) throws ComponentException {
           this.mComponetManager = manager;
  -        getLogger().debug("Looking up " + Store.ROLE + "/JispFilesystemStore");
  +        if (getLogger().isDebugEnabled()) {
  +            getLogger().debug("Looking up " + Store.ROLE + "/JispFilesystemStore");
  +        }
           this.mFsstore = (Store)manager.lookup(Store.ROLE + "/JispFilesystemStore");
  -        getLogger().debug("Looking up " + StoreJanitor.ROLE);
  +        if (getLogger().isDebugEnabled()) {
  +            getLogger().debug("Looking up " + StoreJanitor.ROLE);
  +        }
           this.mStorejanitor = (StoreJanitor)manager.lookup(StoreJanitor.ROLE);
  -        getLogger().debug("Looking up " + FilesystemQueue.ROLE);
  +        if (getLogger().isDebugEnabled()) {
  +            getLogger().debug("Looking up " + FilesystemQueue.ROLE);
  +        }
           this.mFilesystemQueue = (FilesystemQueue)manager.lookup(FilesystemQueue.ROLE);
       }
   
  @@ -94,7 +100,9 @@
        * Dispose the component
        */
       public void dispose() {
  -        this.getLogger().debug("dispose()");
  +        if (getLogger().isDebugEnabled()) {
  +            this.getLogger().debug("dispose()");
  +        }
   
           if (this.mComponetManager != null) {
               this.mComponetManager.release(this.mStorejanitor);
  @@ -127,8 +135,10 @@
        * @param the object to be stored
        */
       public void hold(Object key, Object value) {
  -        getLogger().debug("Holding object in memory. key: " + key);
  -        getLogger().debug("Holding object in memory. value: " + value);
  +        if (getLogger().isDebugEnabled()) {
  +            getLogger().debug("Holding object in memory. key: " + key);
  +            getLogger().debug("Holding object in memory. value: " + value);
  +        }
   
           /** ...first test if the max. objects in cache is reached... */
           while (this.mMRUList.size() >= this.mMaxobjects) {
  @@ -140,7 +150,9 @@
           if(this.mFilesystem) {
               if(this.checkSerializable(value) &&
                  !this.mFsstore.containsKey(key)) {
  -                this.getLogger().debug("Storing object on fs");
  +                if (getLogger().isDebugEnabled()) {
  +                    this.getLogger().debug("Storing object on fs");
  +                }
                   try {
                       this.store(key,value);
                   } catch(Exception e) {
  @@ -152,7 +164,9 @@
           this.mCache.put(key, value);
           this.mMRUList.remove(key);
           this.mMRUList.addFirst(key);
  -        this.getLogger().debug("Cache size=" + mCache.size());
  +        if (getLogger().isDebugEnabled()) {
  +            this.getLogger().debug("Cache size=" + mCache.size());
  +        }
       }
   
       /**
  @@ -162,7 +176,9 @@
        * @return the requested object
        */
       public Object get(Object key) {
  -        this.getLogger().debug("Getting object from memory. Key: " + key);
  +        if (getLogger().isDebugEnabled()) {
  +            this.getLogger().debug("Getting object from memory. Key: " + key);
  +        }
           Object tmpobject = this.mCache.get(key);
           if ( tmpobject != null ) {
               /** put the accessed key on top of the linked list */
  @@ -176,10 +192,14 @@
           if(this.mFilesystem) {
               tmpobject = this.mFsstore.get(key);
               if (tmpobject == null) {
  -                this.getLogger().debug( "Object was NOT found on fs.  Looked for: " + key);
  +                if (getLogger().isDebugEnabled()) {
  +                    this.getLogger().debug( "Object was NOT found on fs.  Looked for: "
+ key);
  +                }
                   return null;
               } else {
  -                this.getLogger().debug("Object was found on fs");
  +                if (getLogger().isDebugEnabled()) {
  +                    this.getLogger().debug("Object was found on fs");
  +                }
                   if(!this.mCache.containsKey(key)) {
                       this.hold(key,tmpobject);
                   }
  @@ -195,7 +215,9 @@
        * @param the key of to be removed object
        */
       public void remove(Object key) {
  -        this.getLogger().debug("Removing object from store");
  +        if (getLogger().isDebugEnabled()) {
  +            this.getLogger().debug("Removing object from store");
  +        }
           this.mCache.remove(key);
           this.mMRUList.remove(key);
           if(this.mFilesystem && key != null) {
  @@ -236,7 +258,9 @@
                   this.getLogger().debug("Freeing cache");
                   this.mCache.remove(this.mMRUList.getLast());
                   this.mMRUList.removeLast();
  -                this.getLogger().debug("Cache size=" + mCache.size());
  +                if (getLogger().isDebugEnabled()) {
  +                    this.getLogger().debug("Cache size=" + mCache.size());
  +                }
               }
           } catch (Exception e) {
               this.getLogger().error("Error in free()", e);
  @@ -253,7 +277,9 @@
        */
       private boolean checkSerializable(Object object) {
           try {
  -            this.getLogger().debug("Object=" + object);
  +            if (getLogger().isDebugEnabled()) {
  +                this.getLogger().debug("Object=" + object);
  +            }
               if((object.getClass().getName().equals("org.apache.cocoon.caching.CachedEventObject"))
                 || (object.getClass().getName().equals("org.apache.cocoon.caching.CachedStreamObject"))
                 || (ClassUtils.implementsInterface(object.getClass().getName(),"org.apache.cocoon.caching.CacheValidity")))
{
  
  
  
  1.8       +42 -24    xml-cocoon2/scratchpad/src/org/apache/cocoon/jispstore/JispFilesystemStore.java
  
  Index: JispFilesystemStore.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/scratchpad/src/org/apache/cocoon/jispstore/JispFilesystemStore.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- JispFilesystemStore.java	2001/12/14 17:15:22	1.7
  +++ JispFilesystemStore.java	2001/12/15 14:29:04	1.8
  @@ -85,23 +85,31 @@
        */
       public void initialize() {
           /** determine datafile */
  -        getLogger().debug("initialize() JispFilesystemStore");
  +        if (getLogger().isDebugEnabled()) {
  +            getLogger().debug("initialize() JispFilesystemStore");
  +        }
   
           try {
  -            getLogger().debug("initialize(): Path to Datafile=" + this.getDirectoryPath()
+ mDatabaseName);
  +            if (getLogger().isDebugEnabled()) {
  +                getLogger().debug("initialize(): Path to Datafile=" + this.getDirectoryPath()
+ mDatabaseName);
  +            }
               File myFile = new File(this.getDirectoryPath() + mDatabaseName);
   
               if (myFile.exists()) {
  -                this.getLogger().debug("initialize(): Datafile exists");
  +                if (getLogger().isDebugEnabled()) {
  +                    this.getLogger().debug("initialize(): Datafile exists");
  +                }
                   mDatabase = new IndexedObjectDatabase(getDirectoryPath() + mDatabaseName,false);
                   mIndex = new BTreeIndex(this.getDirectoryPath() + mIndexName);
                   mDatabase.attachIndex(mIndex);
                   mIndex.dumpTree();
               } else {
  -                this.getLogger().debug("initialize(): Datafile not exists");
  +                if (getLogger().isDebugEnabled()) {
  +                    this.getLogger().debug("initialize(): Datafile not exists");
  +                }
                   mDatabase = new IndexedObjectDatabase(getDirectoryPath() + mDatabaseName,false);
                   mIndex = new BTreeIndex(this.getDirectoryPath() + mIndexName,
  -                                           mOrder, new JispKey(),false);
  +                                           mOrder, new JispStringKey(),false);
                   mDatabase.attachIndex(mIndex);
                   mIndex.dumpTree();
               }   
  @@ -129,9 +137,11 @@
           mIndexName = params.getParameter("indexfile","cocoon.idx");
           mOrder = params.getParameterAsInteger("order",1001);
   
  -        this.getLogger().debug("parameterize(..): mDatabaseName=" + mDatabaseName);
  -        this.getLogger().debug("parameterize(..): mIndexName=" + mIndexName);
  -        this.getLogger().debug("parameterize(..): mOrder=" + mOrder);
  +        if (getLogger().isDebugEnabled()) {
  +            this.getLogger().debug("parameterize(..): mDatabaseName=" + mDatabaseName);
  +            this.getLogger().debug("parameterize(..): mIndexName=" + mIndexName);
  +            this.getLogger().debug("parameterize(..): mOrder=" + mOrder);
  +        }
       }
   
       /**
  @@ -185,17 +195,20 @@
        * @return the Object associated with Key Object
        */
       public Object get(Object key) {
  -        this.getLogger().debug("get(): Get file with key: " + key.toString());
  +        if (getLogger().isDebugEnabled()) {
  +            this.getLogger().debug("get(): Get file with key: " + key.toString());
  +        }
           Object readObj = null;
   
           try {
  -            readObj = mDatabase.read(new JispKey(key.toString()),mIndex);
  -            if(readObj != null) {
  -                this.getLogger().debug("get(): FOUND!!= " + readObj);
  -            } else {
  -                this.getLogger().debug("get(): NOT_FOUND!!");
  +            readObj = mDatabase.read(new JispStringKey(key.toString()),mIndex);
  +            if (getLogger().isDebugEnabled()) {
  +                if(readObj != null) {
  +                    this.getLogger().debug("get(): FOUND!!= " + readObj);
  +                } else {
  +                    this.getLogger().debug("get(): NOT_FOUND!!");
  +                }
               }
  -            
           } catch (Exception e) {
               getLogger().error("get(..): Exception",e);
           }
  @@ -209,13 +222,14 @@
        * @param the Value Object
        */
       public void store(Object key, Object value) throws IOException {
  -        this.getLogger().debug("store(): Store file with key: " + key.toString());
  -        
  +        if (getLogger().isDebugEnabled()) {
  +            this.getLogger().debug("store(): Store file with key: " + key.toString());
  +        }
   
           if(value instanceof Serializable) {
               try {
  -                JispKey[] keyArray = new JispKey[1];
  -                keyArray[0] = new JispKey(key.toString());
  +                JispStringKey[] keyArray = new JispStringKey[1];
  +                keyArray[0] = new JispStringKey(key.toString());
           
                   mDatabase.write(keyArray,(Serializable)value);
               } catch (Exception e) {
  @@ -249,11 +263,13 @@
        * @param the Key Object
        */
       public void remove(Object key) {
  -        this.getLogger().debug("remove(..) Remove item");
  +        if (getLogger().isDebugEnabled()) {
  +            this.getLogger().debug("remove(..) Remove item");
  +        }
   
           try {
  -            JispKey[] keyArray = new JispKey[1];
  -            keyArray[0] = new JispKey(key.toString());
  +            JispStringKey[] keyArray = new JispStringKey[1];
  +            keyArray[0] = new JispStringKey(key.toString());
       
               mDatabase.remove(keyArray);
           } catch (KeyNotFound ignore) {
  @@ -273,8 +289,10 @@
           long res = -1;
           
           try {
  -            res = mIndex.findKey(new JispKey(key.toString()));
  -            this.getLogger().debug("containsKey(..): res=" + res);
  +            res = mIndex.findKey(new JispStringKey(key.toString()));
  +            if (getLogger().isDebugEnabled()) {
  +                this.getLogger().debug("containsKey(..): res=" + res);
  +            }
           } catch (KeyNotFound ignore) {
           
           } catch (Exception e) {
  
  
  
  1.1                  xml-cocoon2/scratchpad/src/org/apache/cocoon/jispstore/JispStringKey.java
  
  Index: JispStringKey.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.cocoon.jispstore;
  
  import com.coyotegulch.jisp.KeyObject;
  import java.io.IOException;
  import java.io.ObjectInput;
  import java.io.ObjectOutput; 
  
  /**
   * Wrapper class to make our cache Key compatible with the Jisp KeyObject
   * NOTE: This Wrapper is only for String Keys.
   *
   * @author <a href="mailto:g-froehlich@gmx.de">Gerhard Froehlich</a>
   */
  final class JispStringKey extends KeyObject{
      static final long serialVersionUID = -6894793231339165076L;
      private String mKey;
      
      public JispStringKey() {
          mKey = new String("");
      }
      
      public JispStringKey(String keyValue) {
          mKey = keyValue;
      }
      
      public int compareTo(KeyObject key) {
          if (key instanceof JispStringKey) {
              int comp = mKey.trim().compareTo(((JispStringKey)key).mKey.trim());
      
              if (comp == 0) {
                  return KEY_EQUAL;
              } else {
                  if (comp < 0) {
                      return KEY_LESS;
                  } else {
                      return KEY_MORE;
                  }
              }
          } else {
              return KEY_ERROR;
          }
      }
            
      public KeyObject makeNullKey() {
          return new JispStringKey();;
      }
      
      public void writeExternal(ObjectOutput out) throws IOException {
          String outKey;
          outKey = new String(mKey);
          out.writeUTF(outKey);
      }
      
      public void readExternal(ObjectInput in) 
      throws IOException, ClassNotFoundException {
          mKey = in.readUTF();
      }
  
      public String toString() {
          return mKey;
      }
  }
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org


Mime
View raw message