cziegeler    2003/08/25 02:20:30

  Modified:    store    build.xml default.properties
               store/src/java/org/apache/excalibur/store/impl
                        AbstractJispFilesystemStore.java
  Log:
  Better synchronization of the JispStore
  
  Revision  Changes    Path
  1.28      +1 -0      avalon-excalibur/store/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/store/build.xml,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- build.xml 30 Jul 2003 19:33:53 -0000      1.27
  +++ build.xml 25 Aug 2003 09:20:30 -0000      1.28
  @@ -16,6 +16,7 @@
           <pathelement location="${avalon-framework.jar}"/>
           <pathelement location="${checkstyle.jar}"/>
           <pathelement location="${jisp.jar}"/>
  +        <pathelement location="${util.concurrent.jar}"/>
           <pathelement location="${excalibur-fortress-tools.jar}"/>
           <pathelement location="${qdox.jar}"/>
           <pathelement path="${java.class.path}"/>
  
  
  
  1.10      +3 -0      avalon-excalibur/store/default.properties
  
  Index: default.properties
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/store/default.properties,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- default.properties        14 Jul 2003 17:16:27 -0000      1.9
  +++ default.properties        25 Aug 2003 09:20:30 -0000      1.10
  @@ -23,6 +23,9 @@
   # ----- Jisp 2.5.1 -----
   jisp.jar=${basedir}/../lib/jisp.2.5.1.jar
   
  +# ----- Doug Lea's Concurrent Utils, version 1.3 or later -----
  +util.concurrent.jar=../lib/util.concurrent-1.3.1.jar
  +
   # --------------------------------------------------
   
   #  Settings used to configure compile environment
  
  
  
  1.17      +136 -65   
avalon-excalibur/store/src/java/org/apache/excalibur/store/impl/AbstractJispFilesystemStore.java
  
  Index: AbstractJispFilesystemStore.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-excalibur/store/src/java/org/apache/excalibur/store/impl/AbstractJispFilesystemStore.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- AbstractJispFilesystemStore.java  31 Jul 2003 03:13:47 -0000      1.16
  +++ AbstractJispFilesystemStore.java  25 Aug 2003 09:20:30 -0000      1.17
  @@ -66,6 +66,10 @@
   import org.apache.avalon.framework.thread.ThreadSafe;
   import org.apache.excalibur.store.Store;
   
  +import EDU.oswego.cs.dl.util.concurrent.FIFOReadWriteLock;
  +import EDU.oswego.cs.dl.util.concurrent.ReadWriteLock;
  +import EDU.oswego.cs.dl.util.concurrent.Sync;
  +
   /**
    * This store is based on the Jisp library
    * (http://www.coyotegulch.com/jisp/index.html). This store uses B-Tree indexes
  @@ -73,6 +77,7 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Gerhard Froehlich</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Vadim Gritsenko</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
    * @version CVS $Id$
    */
   public abstract class AbstractJispFilesystemStore
  @@ -88,6 +93,9 @@
       /** And the index */
       protected BTreeIndex m_Index;
   
  +    /** The lock */
  +    protected ReadWriteLock lock = new FIFOReadWriteLock();
  +    
       /**
        * Sets the repository's location
        */
  @@ -128,28 +136,41 @@
        * @param key the Key object
        * @return the Object associated with Key Object
        */
  -    public synchronized Object get(Object key) 
  +    public Object get(Object key) 
       {
           Object value = null;
  -        try 
  +        Sync sync = this.lock.writeLock();
  +        try
           {
  -            value = m_Database.read(this.wrapKeyObject(key), m_Index);
  -            if (getLogger().isDebugEnabled()) 
  +            sync.acquire();
  +            try 
               {
  -                if (value != null) 
  -                {
  -                    getLogger().debug("Found key: " + key);
  -                } 
  -                else 
  +                value = m_Database.read(this.wrapKeyObject(key), m_Index);
  +                if (getLogger().isDebugEnabled()) 
                   {
  -                    getLogger().debug("NOT Found key: " + key);
  +                    if (value != null) 
  +                    {
  +                        getLogger().debug("Found key: " + key);
  +                    } 
  +                    else 
  +                    {
  +                        getLogger().debug("NOT Found key: " + key);
  +                    }
                   }
  +            } 
  +            catch (Exception e) 
  +            {
  +                getLogger().error("get(..): Exception", e);
  +            }
  +            finally 
  +            {
  +                sync.release();
               }
  -        } 
  -        catch (Exception e) 
  -        {
  -            getLogger().error("get(..): Exception", e);
           }
  +        catch (InterruptedException ignore)
  +        {
  +        } 
  +        
           return value;
       }
   
  @@ -160,7 +181,7 @@
        * @param value the value object
        * @exception  IOException
        */
  -    public synchronized void store(Object key, Object value)
  +    public void store(Object key, Object value)
       throws IOException 
       {
   
  @@ -174,16 +195,29 @@
   
           if (value instanceof Serializable) 
           {
  -            try 
  +            Sync sync = this.lock.writeLock();
  +            try
               {
  -                KeyObject[] keyArray = new KeyObject[1];
  -                keyArray[0] = this.wrapKeyObject(key);
  -                m_Database.write(keyArray, (Serializable) value);
  -            } 
  -            catch (Exception e) 
  -            {
  -                getLogger().error("store(..): Exception", e);
  +                sync.acquire();
  +
  +                try 
  +                {
  +                    KeyObject[] keyArray = new KeyObject[1];
  +                    keyArray[0] = this.wrapKeyObject(key);
  +                    m_Database.write(keyArray, (Serializable) value);
  +                } 
  +                catch (Exception e) 
  +                {
  +                    getLogger().error("store(..): Exception", e);
  +                }
  +                finally 
  +                {
  +                    sync.release();
  +                }
               }
  +            catch (InterruptedException ignore)
  +            {
  +            } 
           } 
           else 
           {
  @@ -198,9 +232,10 @@
        * @param value the value object
        * @exception IOException
        */
  -    public synchronized void hold(Object key, Object value)
  +    public void hold(Object key, Object value)
       throws IOException 
       {
  +        // store is synced!
           this.store(key, value);
       }
   
  @@ -208,14 +243,14 @@
        * Frees some values of the data file.<br>
        * TODO: implementation
        */
  -    public synchronized void free() 
  +    public void free() 
       {
       }
   
       /**
        * Clear the Store of all elements
        */
  -    public synchronized void clear() 
  +    public void clear() 
       {
           
           if (getLogger().isDebugEnabled()) 
  @@ -223,29 +258,41 @@
               getLogger().debug("clear(): Clearing the database ");
           }
   
  -        try 
  +        Sync sync = this.lock.writeLock();
  +        try
           {
  -            final BTreeIterator iter = new BTreeIterator(m_Index);
  -            Object tmp;
  -            do 
  +            sync.acquire();
  +            try 
               {
  -                tmp = iter.getKey();
  -                if ( tmp != null ) 
  +                final BTreeIterator iter = new BTreeIterator(m_Index);
  +                Object tmp;
  +                do 
                   {
  -                    if (getLogger().isDebugEnabled()) 
  +                    tmp = iter.getKey();
  +                    if ( tmp != null ) 
                       {
  -                        getLogger().debug("clear(): Removing key: " + 
tmp.toString());
  +                        if (getLogger().isDebugEnabled()) 
  +                        {
  +                            getLogger().debug("clear(): Removing key: " + 
tmp.toString());
  +                        }
  +                        iter.moveNext();
  +                        this.remove( tmp );
                       }
  -                    iter.moveNext();
  -                    this.remove( tmp );
  -                }
  +                } 
  +                while (tmp != null);
               } 
  -            while (tmp != null);
  -        } 
  -        catch (Exception ignore) 
  -        {
  -            getLogger().error("store(..): Exception", ignore);
  +            catch (Exception ignore) 
  +            {
  +                getLogger().error("store(..): Exception", ignore);
  +            }
  +            finally 
  +            {
  +                sync.release();
  +            }
           }
  +        catch (InterruptedException ignore)
  +        {
  +        } 
       }
   
       /**
  @@ -253,26 +300,38 @@
        *
        * @param key the key object
        */
  -    public synchronized void remove(Object key)
  +    public void remove(Object key)
       {
           if (getLogger().isDebugEnabled()) 
           {
               getLogger().debug("remove(..) Remove item");
           }
   
  -        try 
  +        Sync sync = this.lock.writeLock();
  +        try
           {
  -            KeyObject[] keyArray = new KeyObject[1];
  -            keyArray[0] = this.wrapKeyObject(key);
  -            m_Database.remove(keyArray);
  -        } 
  -        catch (KeyNotFound ignore) 
  +            sync.acquire();
  +            try 
  +            {
  +                KeyObject[] keyArray = new KeyObject[1];
  +                keyArray[0] = this.wrapKeyObject(key);
  +                m_Database.remove(keyArray);
  +            } 
  +            catch (KeyNotFound ignore) 
  +            {
  +            } 
  +            catch (Exception e) 
  +            {
  +                getLogger().error("remove(..): Exception", e);
  +            }
  +            finally 
  +            {
  +                sync.release();
  +            }
  +        }
  +        catch (InterruptedException ignore)
           {
           } 
  -        catch (Exception e) 
  -        {
  -            getLogger().error("remove(..): Exception", e);
  -        }
       }
   
       /**
  @@ -281,25 +340,37 @@
        * @param key the key object
        * @return true if Key exists and false if not
        */
  -    public synchronized boolean containsKey(Object key) 
  +    public boolean containsKey(Object key) 
       {
           long res = -1;
   
  -        try 
  +        Sync sync = this.lock.readLock();
  +        try
           {
  -            res = m_Index.findKey(this.wrapKeyObject(key));
  -            if (getLogger().isDebugEnabled()) 
  +            sync.acquire();
  +            try 
  +            {
  +                res = m_Index.findKey(this.wrapKeyObject(key));
  +                if (getLogger().isDebugEnabled()) 
  +                {
  +                    getLogger().debug("containsKey(..): res=" + res);
  +                }
  +            } 
  +            catch (KeyNotFound ignore) 
  +            {
  +            } 
  +            catch (Exception e)
               {
  -                getLogger().debug("containsKey(..): res=" + res);
  +                getLogger().error("containsKey(..): Exception", e);
               }
  -        } 
  -        catch (KeyNotFound ignore) 
  +            finally 
  +            {
  +                sync.release();
  +            }
  +        }
  +        catch (InterruptedException ignore)
           {
           } 
  -        catch (Exception e)
  -        {
  -            getLogger().error("containsKey(..): Exception", e);
  -        }
   
           if (res > 0) 
           {
  
  
  

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

Reply via email to