db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r373137 - in /db/ojb/branches/OJB_1_0_RELEASE/src: java/org/apache/ojb/odmg/locking/ test/org/apache/ojb/odmg/
Date Sat, 28 Jan 2006 11:09:26 GMT
Author: arminw
Date: Sat Jan 28 03:09:12 2006
New Revision: 373137

URL: http://svn.apache.org/viewcvs?rev=373137&view=rev
Log:
minor changes in internal odmg-locking interface
performance improvements

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/locking/InMemoryLockMapImpl.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/locking/LockManager.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/locking/LockManagerDefaultImpl.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/locking/LockManagerFactory.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/locking/LockManagerOdmgImpl.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/locking/LockStrategyFactory.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/locking/RemoteLockMapImpl.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/LockingMultithreadedTest.java

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/locking/InMemoryLockMapImpl.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/locking/InMemoryLockMapImpl.java?rev=373137&r1=373136&r2=373137&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/locking/InMemoryLockMapImpl.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/locking/InMemoryLockMapImpl.java
Sat Jan 28 03:09:12 2006
@@ -15,19 +15,17 @@
  * limitations under the License.
  */
 
-import org.apache.ojb.broker.Identity;
-import org.apache.ojb.broker.PersistenceBroker;
-import org.apache.ojb.broker.util.configuration.Configuration;
-import org.apache.ojb.broker.util.configuration.ConfigurationException;
-import org.apache.ojb.odmg.TransactionImpl;
-import org.apache.ojb.odmg.TxManagerFactory;
-
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Vector;
 
+import org.apache.ojb.broker.Identity;
+import org.apache.ojb.broker.util.configuration.Configuration;
+import org.apache.ojb.broker.util.configuration.ConfigurationException;
+import org.apache.ojb.odmg.TransactionImpl;
+
 /**
  *
  * We use a HashMap and synchronize blocks of access for a get "check" then put
@@ -49,7 +47,7 @@
 	 * while still maintaining an O(1) lookup like a normal hashmap. We can then
 	 * use this to get the oldest entries very quickly, makes cleanup a breeze.
 	 */
-    private HashMap locktable = new HashMap();
+    private final HashMap locktable = new HashMap();
 
     private long m_lastCleanupAt = System.currentTimeMillis();
 	private static long CLEANUP_FREQUENCY = 500; // 500 milliseconds.
@@ -61,8 +59,7 @@
      */
     public LockEntry getWriter(Object obj)
     {
-        PersistenceBroker broker = getBroker();
-        Identity oid = broker.serviceIdentity().buildIdentity(obj);
+        Identity oid = (Identity) obj;
         return getWriter(oid);
     }
 
@@ -90,21 +87,13 @@
     }
 
     /**
-     * obtain a PersistenceBroker instance for persistence operations.
-     */
-    private PersistenceBroker getBroker()
-    {
-        return TxManagerFactory.instance().getCurrentTransaction().getBroker();
-    }
-
-    /**
      * returns a collection of Reader LockEntries for object obj.
      * If no LockEntries could be found an empty Vector is returned.
      */
     public Collection getReaders(Object obj)
     {
     	checkTimedOutLocks();
-        Identity oid = getBroker().serviceIdentity().buildIdentity(obj);
+        Identity oid = (Identity) obj;
         return getReaders(oid);
     }
 
@@ -133,11 +122,11 @@
     {
         checkTimedOutLocks();
 
-        Identity oid = getBroker().serviceIdentity().buildIdentity(obj);
+        Identity oid = (Identity) obj;
         LockEntry reader = new LockEntry(oid.toString(),
                 tx.getGUID(),
                 System.currentTimeMillis(),
-                LockStrategyFactory.getIsolationLevel(obj),
+                LockStrategyFactory.getIsolationLevel(oid),
                 LockEntry.LOCK_READ);
 
         addReaderInternal(reader);
@@ -172,7 +161,7 @@
     {
         checkTimedOutLocks();
 
-        Identity oid = getBroker().serviceIdentity().buildIdentity(obj);
+        Identity oid = (Identity) obj;
         String oidString = oid.toString();
         String txGuid = tx.getGUID();
         removeReaderInternal(oidString, txGuid);
@@ -295,11 +284,11 @@
     {
         checkTimedOutLocks();
 
-        Identity oid = getBroker().serviceIdentity().buildIdentity(obj);
+        Identity oid = (Identity) obj;
         LockEntry writer = new LockEntry(oid.toString(),
                 tx.getGUID(),
                 System.currentTimeMillis(),
-                LockStrategyFactory.getIsolationLevel(obj),
+                LockStrategyFactory.getIsolationLevel(oid),
                 LockEntry.LOCK_WRITE);
         String oidString = oid.toString();
         setWriterInternal(writer, oidString);
@@ -339,7 +328,7 @@
     {
         checkTimedOutLocks();
 
-        Identity oid = getBroker().serviceIdentity().buildIdentity(obj);
+        Identity oid = (Identity) obj;
         String oidString = oid.toString();
 		String txGuid = tx.getGUID();
         return hasReadLockInternal(oidString, txGuid);

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/locking/LockManager.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/locking/LockManager.java?rev=373137&r1=373136&r2=373137&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/locking/LockManager.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/locking/LockManager.java
Sat Jan 28 03:09:12 2006
@@ -17,17 +17,18 @@
 
 import org.apache.ojb.odmg.TransactionImpl;
 import org.apache.ojb.broker.Identity;
+import org.apache.ojb.broker.metadata.ClassDescriptor;
 
 /**
- * This interface declares the functionality of the OJB internal Locking mechanism.
- * A default implementaion LockManagerDefaultImpl is provided. This implementaion
- * keeps distributed locks in the database. The locking mechanisms thus involves a
- * lot of database lookups and writes. For some environments this solution may not
- * be adequate. OJB allows to provide user defined implementations of this interface.
- * To activate a user defined LockManagerDefaultImpl it must be configured in the OJB.properties
file.
+ * This interface declares the functionality of the ODMG-api implementation Locking mechanism
+ * and wraps OJB's kernel locking manager (see {@link org.apache.ojb.broker.locking.LockManager}).
+ * The internal used implementaion class of this interface is {@link LockManagerOdmgImpl}.
+ * <br/>
+ * The OJB kernel Locking-api allows to provide user defined implementations
+ * of {@link org.apache.ojb.broker.locking.LockManager} configured in the
+ * OJB.properties file.
  *
- *
- * @author thma
+ * @version $Id: $
  */
 public interface LockManager
 {
@@ -35,78 +36,66 @@
      * aquires a readlock for transaction tx on object obj.
      * Returns true if successful, else false.
      */
-    public abstract boolean readLock(TransactionImpl tx, Object obj);
+    public boolean readLock(TransactionImpl tx, Identity oid);
 
     /**
      * aquires a readlock for transaction tx on object obj.
      * Returns true if successful, else false.
      */
-    public abstract boolean readLock(TransactionImpl tx, Identity oid, Object obj);
-
+    public boolean readLock(TransactionImpl tx, Identity oid, ClassDescriptor cld);
 
     /**
      * aquires a writelock for transaction tx on object obj.
      * Returns true if successful, else false.
      */
-    public abstract boolean writeLock(TransactionImpl tx, Object obj);
+    public boolean writeLock(TransactionImpl tx, Identity oid);
 
     /**
      * aquires a writelock for transaction tx on object obj.
      * Returns true if successful, else false.
      */
-    public abstract boolean writeLock(TransactionImpl tx, Identity oid, Object obj);
-
+    public boolean writeLock(TransactionImpl tx, Identity oid, ClassDescriptor cld);
 
     /**
      * upgrades readlock for transaction tx on object obj to a writelock.
      * If no readlock existed a writelock is acquired anyway.
      * Returns true if successful, else false.
      */
-    public abstract boolean upgradeLock(TransactionImpl tx, Object obj);
+    public boolean upgradeLock(TransactionImpl tx, Identity oid);
 
     /**
      * upgrades readlock for transaction tx on object obj to a writelock.
      * If no readlock existed a writelock is acquired anyway.
      * Returns true if successful, else false.
      */
-    public abstract boolean upgradeLock(TransactionImpl tx, Identity oid, Object obj);
-
-
-    /**
-     * releases a lock for transaction tx on object obj.
-     * Returns true if successful, else false.
-     */
-    public abstract boolean releaseLock(TransactionImpl tx, Object obj);
-
-    /**
-     * releases a lock for transaction tx on object obj.
-     * Returns true if successful, else false.
-     */
-    public abstract boolean releaseLock(TransactionImpl tx, Identity oid, Object obj);
-
+    public boolean upgradeLock(TransactionImpl tx, Identity oid, ClassDescriptor cld);
 
     /**
      * checks if there is a readlock for transaction tx on object obj.
      * Returns true if so, else false.
      */
-    public abstract boolean checkRead(TransactionImpl tx, Object obj);
+    public boolean checkRead(TransactionImpl tx, Identity oid);
 
     /**
-     * checks if there is a readlock for transaction tx on object obj.
+     * checks if there is a writelock for transaction tx on object obj.
      * Returns true if so, else false.
      */
-    public abstract boolean checkRead(TransactionImpl tx, Identity oid, Object obj);
+    public boolean checkWrite(TransactionImpl tx, Identity oid);
 
+    /**
+     * releases a lock for transaction tx on object obj.
+     * Returns true if successful, else false.
+     */
+    public boolean releaseLock(TransactionImpl tx, Identity oid);
 
     /**
-     * checks if there is a writelock for transaction tx on object obj.
-     * Returns true if so, else false.
+     * Releases all locks acquired by the specified transaction.
      */
-    public abstract boolean checkWrite(TransactionImpl tx, Object obj);
+    public void releaseLocks(TransactionImpl tx);
 
     /**
-     * checks if there is a writelock for transaction tx on object obj.
-     * Returns true if so, else false.
+     * Returns info about the used lock manager implementation and the state
+     * of the lock manager.
      */
-    public abstract boolean checkWrite(TransactionImpl tx, Identity oid, Object obj);
+    public String getLockInfo();
 }

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/locking/LockManagerDefaultImpl.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/locking/LockManagerDefaultImpl.java?rev=373137&r1=373136&r2=373137&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/locking/LockManagerDefaultImpl.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/locking/LockManagerDefaultImpl.java
Sat Jan 28 03:09:12 2006
@@ -15,10 +15,16 @@
  * limitations under the License.
  */
 
+import java.util.Enumeration;
+import java.util.Iterator;
+
 import org.apache.ojb.broker.Identity;
+import org.apache.ojb.broker.metadata.ClassDescriptor;
 import org.apache.ojb.broker.util.logging.Logger;
 import org.apache.ojb.broker.util.logging.LoggerFactory;
 import org.apache.ojb.odmg.TransactionImpl;
+import org.apache.ojb.odmg.RuntimeObject;
+import org.apache.ojb.odmg.ObjectEnvelope;
 
 /**
  * The OJB default implementation of a Locking mechanism.
@@ -44,7 +50,7 @@
  * standalone server, that allows to elminate additional db reads and writes.
  *
  * @author thma
- * @deprecated 
+ * @deprecated
  */
 public class LockManagerDefaultImpl implements LockManager
 {
@@ -54,36 +60,45 @@
     {
     }
 
+    public String getLockInfo()
+    {
+        return "Method not implemented";
+    }
+
     /**
      * aquires a readlock for transaction tx on object obj.
      * Returns true if successful, else false.
      */
-    public synchronized boolean readLock(TransactionImpl tx, Object obj)
+    public synchronized boolean readLock(TransactionImpl tx, Identity oid)
     {
-        if (log.isDebugEnabled()) log.debug("LM.readLock(tx-" + tx.getGUID() + ", " + tx.getBroker().serviceIdentity().buildIdentity(obj).toString()
+ ")");
-        LockStrategy lockStrategy = LockStrategyFactory.getStrategyFor(obj);
-        return lockStrategy.readLock(tx, obj);
+        if (log.isDebugEnabled()) log.debug("LM.readLock(tx-" + tx.getGUID() + ", " + oid
+ ")");
+        LockStrategy lockStrategy = LockStrategyFactory.getStrategyFor(oid);
+        return lockStrategy.readLock(tx, oid);
     }
 
-    public boolean readLock(TransactionImpl tx, Identity oid, Object obj)
+    public boolean readLock(TransactionImpl tx, Identity oid, ClassDescriptor cld)
     {
-        return readLock(tx,obj);
+        if (log.isDebugEnabled()) log.debug("LM.readLock(tx-" + tx.getGUID() + ", " + oid
+ ")");
+        LockStrategy lockStrategy = LockStrategyFactory.getStrategyFor(oid);
+        return lockStrategy.readLock(tx, oid);
     }
 
     /**
      * aquires a writelock for transaction tx on object obj.
      * Returns true if successful, else false.
      */
-    public synchronized boolean writeLock(TransactionImpl tx, Object obj)
+    public synchronized boolean writeLock(TransactionImpl tx, Identity oid)
     {
-        if (log.isDebugEnabled()) log.debug("LM.writeLock(tx-" + tx.getGUID() + ", " + tx.getBroker().serviceIdentity().buildIdentity(obj).toString()
+ ")");
-        LockStrategy lockStrategy = LockStrategyFactory.getStrategyFor(obj);
-        return lockStrategy.writeLock(tx, obj);
+        if (log.isDebugEnabled()) log.debug("LM.writeLock(tx-" + tx.getGUID() + ", " + oid
+ ")");
+        LockStrategy lockStrategy = LockStrategyFactory.getStrategyFor(oid);
+        return lockStrategy.writeLock(tx, oid);
     }
 
-    public boolean writeLock(TransactionImpl tx, Identity oid, Object obj)
+    public boolean writeLock(TransactionImpl tx, Identity oid, ClassDescriptor cld)
     {
-        return writeLock(tx, obj);
+        if (log.isDebugEnabled()) log.debug("LM.writeLock(tx-" + tx.getGUID() + ", " + oid
+ ")");
+        LockStrategy lockStrategy = LockStrategyFactory.getStrategyFor(oid);
+        return lockStrategy.writeLock(tx, oid);
     }
 
     /**
@@ -91,63 +106,61 @@
      * If no readlock existed a writelock is acquired anyway.
      * Returns true if successful, else false.
      */
-    public synchronized boolean upgradeLock(TransactionImpl tx, Object obj)
+    public synchronized boolean upgradeLock(TransactionImpl tx, Identity oid)
     {
-        if (log.isDebugEnabled()) log.debug("LM.upgradeLock(tx-" + tx.getGUID() + ", " +
tx.getBroker().serviceIdentity().buildIdentity(obj).toString() + ")");
-        LockStrategy lockStrategy = LockStrategyFactory.getStrategyFor(obj);
-        return lockStrategy.upgradeLock(tx, obj);
+        if (log.isDebugEnabled()) log.debug("LM.upgradeLock(tx-" + tx.getGUID() + ", " +
oid + ")");
+        LockStrategy lockStrategy = LockStrategyFactory.getStrategyFor(oid);
+        return lockStrategy.upgradeLock(tx, oid);
     }
 
-    public boolean upgradeLock(TransactionImpl tx, Identity oid, Object obj)
+    public boolean upgradeLock(TransactionImpl tx, Identity oid, ClassDescriptor cld)
     {
-        return upgradeLock(tx, obj);
+        if (log.isDebugEnabled()) log.debug("LM.upgradeLock(tx-" + tx.getGUID() + ", " +
oid + ")");
+        LockStrategy lockStrategy = LockStrategyFactory.getStrategyFor(oid);
+        return lockStrategy.upgradeLock(tx, oid);
     }
 
     /**
      * releases a lock for transaction tx on object obj.
      * Returns true if successful, else false.
      */
-    public synchronized boolean releaseLock(TransactionImpl tx, Object obj)
-    {
-        if (log.isDebugEnabled()) log.debug("LM.releaseLock(tx-" + tx.getGUID() + ", " +
tx.getBroker().serviceIdentity().buildIdentity(obj).toString() + ")");
-        LockStrategy lockStrategy = LockStrategyFactory.getStrategyFor(obj);
-        return lockStrategy.releaseLock(tx, obj);
-    }
-
-    public boolean releaseLock(TransactionImpl tx, Identity oid, Object obj)
+    public synchronized boolean releaseLock(TransactionImpl tx, Identity oid)
     {
-        return releaseLock(tx, obj);
+        if (log.isDebugEnabled()) log.debug("LM.releaseLock(tx-" + tx.getGUID() + ", " +
oid + ")");
+        LockStrategy lockStrategy = LockStrategyFactory.getStrategyFor(oid);
+        return lockStrategy.releaseLock(tx, oid);
+    }
+
+    public synchronized void releaseLocks(TransactionImpl tx)
+    {
+        Enumeration en = tx.objectEnvelopeTable.elements();
+        while (en.hasMoreElements())
+        {
+            ObjectEnvelope oe = (ObjectEnvelope) en.nextElement();
+            releaseLock(tx, oe.getIdentity());
+        }
+        tx.releaseUnmaterialzedLocks();
     }
 
     /**
      * checks if there is a readlock for transaction tx on object obj.
      * Returns true if so, else false.
      */
-    public synchronized boolean checkRead(TransactionImpl tx, Object obj)
+    public synchronized boolean checkRead(TransactionImpl tx, Identity oid)
     {
-        if (log.isDebugEnabled()) log.debug("LM.checkRead(tx-" + tx.getGUID() + ", " + tx.getBroker().serviceIdentity().buildIdentity(obj).toString()
+ ")");
-        LockStrategy lockStrategy = LockStrategyFactory.getStrategyFor(obj);
-        return lockStrategy.checkRead(tx, obj);
-    }
-
-    public boolean checkRead(TransactionImpl tx, Identity oid, Object obj)
-    {
-        return checkRead(tx, obj);
+        if (log.isDebugEnabled()) log.debug("LM.checkRead(tx-" + tx.getGUID() + ", " + oid
+ ")");
+        LockStrategy lockStrategy = LockStrategyFactory.getStrategyFor(oid);
+        return lockStrategy.checkRead(tx, oid);
     }
 
     /**
      * checks if there is a writelock for transaction tx on object obj.
      * Returns true if so, else false.
      */
-    public synchronized boolean checkWrite(TransactionImpl tx, Object obj)
-    {
-        if (log.isDebugEnabled()) log.debug("LM.checkWrite(tx-" + tx.getGUID() + ", " + tx.getBroker().serviceIdentity().buildIdentity(obj).toString()
+ ")");
-        LockStrategy lockStrategy = LockStrategyFactory.getStrategyFor(obj);
-        return lockStrategy.checkWrite(tx, obj);
-    }
-
-    public boolean checkWrite(TransactionImpl tx, Identity oid, Object obj)
+    public synchronized boolean checkWrite(TransactionImpl tx, Identity oid)
     {
-        return checkWrite(tx, obj);
+        if (log.isDebugEnabled()) log.debug("LM.checkWrite(tx-" + tx.getGUID() + ", " + oid
+ ")");
+        LockStrategy lockStrategy = LockStrategyFactory.getStrategyFor(oid);
+        return lockStrategy.checkWrite(tx, oid);
     }
 }

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/locking/LockManagerFactory.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/locking/LockManagerFactory.java?rev=373137&r1=373136&r2=373137&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/locking/LockManagerFactory.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/locking/LockManagerFactory.java
Sat Jan 28 03:09:12 2006
@@ -20,6 +20,8 @@
 import org.apache.ojb.broker.locking.LockManager;
 import org.apache.ojb.broker.util.ClassHelper;
 import org.apache.ojb.broker.util.configuration.Configuration;
+import org.apache.ojb.broker.util.configuration.Configurator;
+import org.apache.ojb.broker.util.configuration.Configurable;
 import org.apache.ojb.broker.util.configuration.impl.OjbConfigurator;
 import org.apache.ojb.broker.util.logging.Logger;
 import org.apache.ojb.broker.util.logging.LoggerFactory;
@@ -28,20 +30,18 @@
  * This factory class creates LockManager instances according
  * to the setting in the OJB properties file.
  */
-public class LockManagerFactory
+public abstract class LockManagerFactory
 {
-    private static LockManagerFactory lockManagerFactory = null;
-    private Logger log = LoggerFactory.getLogger(LockManagerFactory.class);
-    private org.apache.ojb.odmg.locking.LockManager lockManager;
+    private static Logger log = LoggerFactory.getLogger(LockManagerFactory.class);
+    private static org.apache.ojb.odmg.locking.LockManager lockManager = null;
 
     private LockManagerFactory()
     {
-        init();
     }
 
-    private void init()
+    private static void createLockManagerInstance(Configurator configurator)
     {
-        Configuration conf = OjbConfigurator.getInstance().getConfigurationFor(null);
+        Configuration conf = configurator.getConfigurationFor(null);
         Class lockMapClass = conf.getClass("LockMapClass", Object.class);
         Class lockManagerClass = conf.getClass("LockManagerClass", null);
         if(lockManagerClass == null)
@@ -58,7 +58,7 @@
             {
                 throw new OJBRuntimeException(buildErrorMsg(lockMapClass, lockManagerClass));
             }
-            setupLockManager(lockManagerClass);
+            setupLockManagerOld(lockManagerClass);
         }
         else
         {
@@ -69,18 +69,22 @@
             {
                 throw new OJBRuntimeException(buildErrorMsg(lockMapClass, lockManagerClass));
             }
-            setupLockManager(conf, lockManagerClass);
+            setupLockManager(configurator, lockManagerClass);
         }
     }
 
-    private void setupLockManager(Configuration conf, Class lockManagerClass)
+    private static void setupLockManager(Configurator c, Class lockManagerClass)
     {
-        long timeout = conf.getInteger("LockTimeout", 60000);
+        long timeout = c.getConfigurationFor(null).getInteger("LockTimeout", 60000);
         log.info("LockTimeout=" + timeout);
         try
         {
             LockManager lm = (LockManager) ClassHelper.newInstance(lockManagerClass);
             lm.setLockTimeout(timeout);
+            if(lm instanceof Configurable)
+            {
+                c.configure((Configurable) lm);
+            }
             lockManager = new LockManagerOdmgImpl(lm);
         }
         catch(Exception e)
@@ -89,12 +93,11 @@
         }
     }
 
-    private void setupLockManager(Class lockManagerClass)
+    private static void setupLockManagerOld(Class lockManagerClass)
     {
         try
         {
             lockManager = (org.apache.ojb.odmg.locking.LockManager) ClassHelper.newInstance(lockManagerClass);
-
         }
         catch(Exception e)
         {
@@ -102,8 +105,7 @@
         }
     }
 
-
-    private String buildErrorMsg(Class lockMap, Class lockManager)
+    private static String buildErrorMsg(Class lockMap, Class lockManager)
     {
         String eol = SystemUtils.LINE_SEPARATOR;
         StringBuffer msg = new StringBuffer("Can't setup LockManager. Current used properties
are:" + eol);
@@ -118,21 +120,17 @@
         return msg.toString();
     }
 
-    private org.apache.ojb.odmg.locking.LockManager getManager()
-    {
-        return lockManager;
-    }
-
     /**
      * Get a {@link org.apache.ojb.odmg.locking.LockManager} instance. The implementation
class is
      * configured in the OJB properties file.
      */
     public static synchronized org.apache.ojb.odmg.locking.LockManager getLockManager()
     {
-        if(lockManagerFactory == null)
+        if(lockManager == null)
         {
-            lockManagerFactory = new LockManagerFactory();
+            Configurator configurator = OjbConfigurator.getInstance();
+            createLockManagerInstance(configurator);
         }
-        return lockManagerFactory.getManager();
+        return lockManager;
     }
 }

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/locking/LockManagerOdmgImpl.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/locking/LockManagerOdmgImpl.java?rev=373137&r1=373136&r2=373137&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/locking/LockManagerOdmgImpl.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/locking/LockManagerOdmgImpl.java
Sat Jan 28 03:09:12 2006
@@ -17,7 +17,6 @@
 
 import org.apache.ojb.broker.Identity;
 import org.apache.ojb.broker.locking.IsolationLevels;
-import org.apache.ojb.broker.core.proxy.ProxyHelper;
 import org.apache.ojb.broker.metadata.ClassDescriptor;
 import org.apache.ojb.odmg.TransactionImpl;
 
@@ -33,7 +32,7 @@
 {
     private org.apache.ojb.broker.locking.LockManager lm;
 
-    public LockManagerOdmgImpl(org.apache.ojb.broker.locking.LockManager lm)
+    public LockManagerOdmgImpl(final org.apache.ojb.broker.locking.LockManager lm)
     {
         this.lm = lm;
     }
@@ -43,74 +42,67 @@
         return isolationLevel == IsolationLevels.IL_OPTIMISTIC || isolationLevel == IsolationLevels.IL_NONE;
     }
 
-    public boolean readLock(TransactionImpl tx, Object obj)
+    private ClassDescriptor getCld(final TransactionImpl tx, final Identity oid)
     {
-        Identity oid = tx.getBroker().serviceIdentity().buildIdentity(obj);
-        return readLock(tx, oid, obj);
+        Class clazz = oid.getObjectsRealClass();
+        if(clazz == null) clazz = oid.getObjectsTopLevelClass();
+        return tx.getBroker().getClassDescriptor(clazz);
     }
 
-    public boolean readLock(TransactionImpl tx, Identity oid, Object obj)
+    public String getLockInfo()
     {
-        ClassDescriptor cld = tx.getBroker().getClassDescriptor(ProxyHelper.getRealClass(obj));
-        int isolationLevel = cld.getIsolationLevel();
-        return ignore(isolationLevel) || lm.readLock(tx.getGUID(), oid, isolationLevel);
+        return lm.getLockInfo();
     }
 
-    public boolean writeLock(TransactionImpl tx, Object obj)
+    public boolean readLock(final TransactionImpl tx, final Identity oid)
     {
-        Identity oid = tx.getBroker().serviceIdentity().buildIdentity(obj);
-        return writeLock(tx, oid, obj);
+        return readLock(tx, oid, getCld(tx, oid));
     }
 
-    public boolean writeLock(TransactionImpl tx, Identity oid, Object obj)
+    public boolean readLock(final TransactionImpl tx, final Identity oid, final ClassDescriptor
cld)
     {
-        ClassDescriptor cld = tx.getBroker().getClassDescriptor(ProxyHelper.getRealClass(obj));
         int isolationLevel = cld.getIsolationLevel();
-        return ignore(isolationLevel) || lm.writeLock(tx.getGUID(), oid, isolationLevel);
+        return ignore(isolationLevel) || lm.readLock(tx.getGUID(), oid, isolationLevel);
     }
 
-    public boolean upgradeLock(TransactionImpl tx, Object obj)
+    public boolean writeLock(final TransactionImpl tx, final Identity oid)
     {
-        Identity oid = tx.getBroker().serviceIdentity().buildIdentity(obj);
-        return upgradeLock(tx, oid, obj);
+        return writeLock(tx, oid, getCld(tx, oid));
     }
 
-    public boolean upgradeLock(TransactionImpl tx, Identity oid, Object obj)
+    public boolean writeLock(final TransactionImpl tx, final Identity oid, final ClassDescriptor
cld)
     {
-        ClassDescriptor cld = tx.getBroker().getClassDescriptor(ProxyHelper.getRealClass(obj));
         int isolationLevel = cld.getIsolationLevel();
-        return ignore(isolationLevel) || lm.upgradeLock(tx.getGUID(), oid, isolationLevel);
+        return ignore(isolationLevel) || lm.writeLock(tx.getGUID(), oid, isolationLevel);
     }
 
-    public boolean releaseLock(TransactionImpl tx, Object obj)
+    public boolean upgradeLock(final TransactionImpl tx, final Identity oid)
     {
-        Identity oid = tx.getBroker().serviceIdentity().buildIdentity(obj);
-        return releaseLock(tx, oid, obj);
+        return upgradeLock(tx, oid, getCld(tx, oid));
     }
 
-    public boolean releaseLock(TransactionImpl tx, Identity oid, Object obj)
+    public boolean upgradeLock(final TransactionImpl tx, final Identity oid, final ClassDescriptor
cld)
     {
-        return lm.releaseLock(tx.getGUID(), oid);
+        int isolationLevel = cld.getIsolationLevel();
+        return ignore(isolationLevel) || lm.upgradeLock(tx.getGUID(), oid, isolationLevel);
     }
 
-    public boolean checkRead(TransactionImpl tx, Object obj)
+    public boolean releaseLock(final TransactionImpl tx, final Identity oid)
     {
-        Identity oid = tx.getBroker().serviceIdentity().buildIdentity(obj);
-        return checkRead(tx, oid, obj);
+        return lm.releaseLock(tx.getGUID(), oid);
     }
 
-    public boolean checkRead(TransactionImpl tx, Identity oid, Object obj)
+    public void releaseLocks(TransactionImpl tx)
     {
-        return lm.hasRead(tx.getGUID(), oid);
+        lm.releaseLocks(tx.getGUID());
     }
 
-    public boolean checkWrite(TransactionImpl tx, Object obj)
+    public boolean checkRead(final TransactionImpl tx, final Identity oid)
     {
-        Identity oid = tx.getBroker().serviceIdentity().buildIdentity(obj);
-        return checkWrite(tx, oid, obj);
+        return lm.hasRead(tx.getGUID(), oid);
     }
 
-    public boolean checkWrite(TransactionImpl tx, Identity oid, Object obj)
+    public boolean checkWrite(final TransactionImpl tx, final Identity oid)
     {
         return lm.hasWrite(tx.getGUID(), oid);
     }

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/locking/LockStrategyFactory.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/locking/LockStrategyFactory.java?rev=373137&r1=373136&r2=373137&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/locking/LockStrategyFactory.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/locking/LockStrategyFactory.java
Sat Jan 28 03:09:12 2006
@@ -16,7 +16,7 @@
  */
 
 import org.apache.ojb.broker.PersistenceBrokerException;
-import org.apache.ojb.broker.core.proxy.ProxyHelper;
+import org.apache.ojb.broker.Identity;
 import org.apache.ojb.broker.locking.IsolationLevels;
 import org.apache.ojb.broker.metadata.ClassDescriptor;
 import org.apache.ojb.broker.util.logging.LoggerFactory;
@@ -53,9 +53,9 @@
      *
      * @return LockStrategy
      */
-    public static LockStrategy getStrategyFor(Object obj)
+    public static LockStrategy getStrategyFor(Identity oid)
     {
-        int isolationLevel = getIsolationLevel(obj);
+        int isolationLevel = getIsolationLevel(oid);
         switch (isolationLevel)
         {
             case IsolationLevels.IL_READ_UNCOMMITTED:
@@ -81,14 +81,13 @@
      *
      * @return int the isolationlevel
      */
-    public static int getIsolationLevel(Object obj)
+    public static int getIsolationLevel(Identity oid)
     {
-        Class c = ProxyHelper.getRealClass(obj);
         int isolationLevel = IsolationLevels.IL_READ_UNCOMMITTED;
-
         try
         {
-            ClassDescriptor cld = TxManagerFactory.instance().getCurrentTransaction().getBroker().getClassDescriptor(c);
+            ClassDescriptor cld = TxManagerFactory.instance().getCurrentTransaction().getBroker().getClassDescriptor(
+                    oid.getObjectsRealClass() != null ? oid.getObjectsRealClass() : oid.getObjectsTopLevelClass());
             isolationLevel = cld.getIsolationLevel();
         }
         catch (PersistenceBrokerException e)

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/locking/RemoteLockMapImpl.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/locking/RemoteLockMapImpl.java?rev=373137&r1=373136&r2=373137&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/locking/RemoteLockMapImpl.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/locking/RemoteLockMapImpl.java
Sat Jan 28 03:09:12 2006
@@ -28,7 +28,6 @@
 import java.util.Collection;
 
 import org.apache.ojb.broker.Identity;
-import org.apache.ojb.broker.PersistenceBroker;
 import org.apache.ojb.broker.PersistenceBrokerException;
 import org.apache.ojb.broker.util.configuration.Configurable;
 import org.apache.ojb.broker.util.configuration.Configuration;
@@ -36,7 +35,6 @@
 import org.apache.ojb.broker.util.logging.Logger;
 import org.apache.ojb.broker.util.logging.LoggerFactory;
 import org.apache.ojb.odmg.TransactionImpl;
-import org.apache.ojb.odmg.TxManagerFactory;
 
 /**
  * Servlet based lock mechanism for usage in distributed environment.
@@ -50,22 +48,12 @@
 	private static URL lockservlet = null;
 
 	/**
-	 * obtain a PersistenceBroker instance.
-	 */
-	private PersistenceBroker getBroker()
-	{
-		return TxManagerFactory.instance().getCurrentTransaction().getBroker();
-	}
-
-	/**
 	 * returns the LockEntry for the Writer of object obj.
 	 * If now writer exists, null is returned.
 	 */
 	public LockEntry getWriter(Object obj)
 	{
-		PersistenceBroker broker = getBroker();
-		Identity oid = broker.serviceIdentity().buildIdentity(obj);
-		
+		Identity oid = (Identity) obj;
         LockEntry result = null;
         try
         {
@@ -148,7 +136,7 @@
 		Collection result = null;
         try
         {
-            Identity oid = getBroker().serviceIdentity().buildIdentity(obj);
+            Identity oid = (Identity) obj;
             byte selector = (byte) 'r';
             byte[] requestBarr = buildRequestArray(oid, selector);
             
@@ -183,12 +171,13 @@
 	 */
 	public boolean addReader(TransactionImpl tx, Object obj)
 	{
-		try
+		Identity oid = (Identity) obj;
+        try
 		{
-			LockEntry lock = new LockEntry(getBroker().serviceIdentity().buildIdentity(obj).toString(),
+			LockEntry lock = new LockEntry(oid.toString(),
 					tx.getGUID(),
 					System.currentTimeMillis(),
-					LockStrategyFactory.getIsolationLevel(obj),
+					LockStrategyFactory.getIsolationLevel(oid),
 					LockEntry.LOCK_READ);
             addReaderRemote(lock);
 			return true;
@@ -244,9 +233,10 @@
 	 */
 	public void removeReader(TransactionImpl tx, Object obj)
 	{
-		try
+		Identity oid = (Identity) obj;
+        try
 		{
-			LockEntry lock = new LockEntry(getBroker().serviceIdentity().buildIdentity(obj).toString(),
tx.getGUID());
+			LockEntry lock = new LockEntry(oid.toString(), tx.getGUID());
             removeReaderRemote(lock);
 		}
 		catch (Throwable t)
@@ -380,12 +370,13 @@
 	 */
 	public boolean setWriter(TransactionImpl tx, Object obj)
 	{
-		try
+		Identity oid = (Identity) obj;
+        try
 		{
-			LockEntry lock = new LockEntry(getBroker().serviceIdentity().buildIdentity(obj).toString(),
+			LockEntry lock = new LockEntry(oid.toString(),
 					tx.getGUID(),
 					System.currentTimeMillis(),
-					LockStrategyFactory.getIsolationLevel(obj),
+					LockStrategyFactory.getIsolationLevel(oid),
 					LockEntry.LOCK_WRITE);
 
 			setWriterRemote(lock);
@@ -432,9 +423,10 @@
 	 */
 	public boolean hasReadLock(TransactionImpl tx, Object obj)
 	{
-		try
+		Identity oid = (Identity) obj;
+        try
 		{
-			LockEntry lock = new LockEntry(getBroker().serviceIdentity().buildIdentity(obj).toString(),
tx.getGUID());
+			LockEntry lock = new LockEntry(oid.toString(), tx.getGUID());
 			boolean result = hasReadLockRemote(lock);			
 			return result;
 		}

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/LockingMultithreadedTest.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/LockingMultithreadedTest.java?rev=373137&r1=373136&r2=373137&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/LockingMultithreadedTest.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/odmg/LockingMultithreadedTest.java
Sat Jan 28 03:09:12 2006
@@ -66,6 +66,8 @@
         LockObject targetObject = createLockObjectWithRef();
         storeObject(targetObject);
 
+        System.out.println("** Start multithreaded lock test **");
+        Thread.sleep(500);
         TestCaseRunnable tct [] = new TestCaseRunnable[concurrentThreads];
         for (int i = 0; i < concurrentThreads; i++)
         {
@@ -83,6 +85,8 @@
         System.out.println("*** Result of multithreaded lock test ***");
         System.out.println(result.toString());
         //System.out.println(targetObject.getReference().getName());
+        String statistic = ((ImplementationImpl) odmg).getLockManager().getLockInfo();
+        System.out.println("Lock-Statistic: " + statistic);
     }
 
     private LockObject createLockObjectWithRef()



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message