From 281a429e6f526e356353103ae3b60d45d75791c9 Mon Sep 17 00:00:00 2001
From: abobrov <abobrov@localhost>
Date: Wed, 11 Jul 2007 23:03:46 +0000
Subject: [PATCH] - [Issue 1588] consolidate cache entry locking code:   getEntry(lck) locking code logic is now consolidated in a single method    inside the EntryCache abstract class effectively moving it out of entry    cache implementing subclasses.

---
 opends/src/server/org/opends/server/extensions/FIFOEntryCache.java |  235 ++--------------------------------------------------------
 1 files changed, 9 insertions(+), 226 deletions(-)

diff --git a/opends/src/server/org/opends/server/extensions/FIFOEntryCache.java b/opends/src/server/org/opends/server/extensions/FIFOEntryCache.java
index 03d6d76..d5cb968 100644
--- a/opends/src/server/org/opends/server/extensions/FIFOEntryCache.java
+++ b/opends/src/server/org/opends/server/extensions/FIFOEntryCache.java
@@ -53,8 +53,6 @@
 import org.opends.server.types.DN;
 import org.opends.server.types.Entry;
 import org.opends.server.types.InitializationException;
-import org.opends.server.types.LockManager;
-import org.opends.server.types.LockType;
 import org.opends.server.types.ResultCode;
 import org.opends.server.types.SearchFilter;
 
@@ -144,9 +142,6 @@
   // the cache.
   private Lock cacheLock;
 
-  // The maximum length of time to try to obtain a lock before giving up.
-  private long lockTimeout;
-
   // The maximum amount of memory in bytes that the JVM will be allowed to use
   // before we need to start purging entries.
   private long maxAllowedMemory;
@@ -288,229 +283,17 @@
   /**
    * {@inheritDoc}
    */
-  public Entry getEntry(DN entryDN, LockType lockType, List<Lock> lockList)
+  protected DN getEntryDN(Backend backend, long entryID)
   {
-    // Get the entry from the DN map if it is present.  If not, then return
-    // null.
-    CacheEntry entry = dnMap.get(entryDN);
-    if (entry == null)
-    {
-      return null;
+    // Locate specific backend map and return the entry DN by ID.
+    HashMap<Long,CacheEntry> backendMap = idMap.get(backend);
+    if (backendMap != null) {
+      CacheEntry e = backendMap.get(entryID);
+      if (e != null) {
+        return e.getDN();
+      }
     }
-
-
-    // Obtain a lock for the entry as appropriate.  If an error occurs, then
-    // make sure no lock is held and return null.  Otherwise, return the entry.
-    switch (lockType)
-    {
-      case READ:
-        // Try to obtain a read lock for the entry.
-        Lock readLock = LockManager.lockRead(entryDN, lockTimeout);
-        if (readLock == null)
-        {
-          // We couldn't get the lock, so we have to return null.
-          return null;
-        }
-        else
-        {
-          try
-          {
-            lockList.add(readLock);
-            return entry.getEntry();
-          }
-          catch (Exception e)
-          {
-            if (debugEnabled())
-            {
-              TRACER.debugCaught(DebugLogLevel.ERROR, e);
-            }
-
-            // The attempt to add the lock to the list failed, so we need to
-            // release the lock and return null.
-            try
-            {
-              LockManager.unlock(entryDN, readLock);
-            }
-            catch (Exception e2)
-            {
-              if (debugEnabled())
-              {
-                TRACER.debugCaught(DebugLogLevel.ERROR, e2);
-              }
-            }
-
-            return null;
-          }
-        }
-
-      case WRITE:
-        // Try to obtain a write lock for the entry.
-        Lock writeLock = LockManager.lockWrite(entryDN, lockTimeout);
-        if (writeLock == null)
-        {
-          // We couldn't get the lock, so we have to return null.
-          return null;
-        }
-        else
-        {
-          try
-          {
-            lockList.add(writeLock);
-            return entry.getEntry();
-          }
-          catch (Exception e)
-          {
-            if (debugEnabled())
-            {
-              TRACER.debugCaught(DebugLogLevel.ERROR, e);
-            }
-
-            // The attempt to add the lock to the list failed, so we need to
-            // release the lock and return null.
-            try
-            {
-              LockManager.unlock(entryDN, writeLock);
-            }
-            catch (Exception e2)
-            {
-              if (debugEnabled())
-              {
-                TRACER.debugCaught(DebugLogLevel.ERROR, e2);
-              }
-            }
-
-            return null;
-          }
-        }
-
-      case NONE:
-        // We don't need to obtain a lock, so just return the entry.
-        return entry.getEntry();
-
-      default:
-        // This is an unknown type of lock, so we'll return null.
-        return null;
-    }
-  }
-
-
-  /**
-   * {@inheritDoc}
-   */
-  public Entry getEntry(Backend backend, long entryID, LockType lockType,
-                        List<Lock> lockList)
-  {
-    // Get the hash map for the provided backend.  If it isn't present, then
-    // return null.
-    HashMap<Long,CacheEntry> map = idMap.get(backend);
-    if (map == null)
-    {
-      return null;
-    }
-
-
-    // Get the entry from the map by its ID.  If it isn't present, then return
-    // null.
-    CacheEntry cacheEntry = map.get(entryID);
-    if (cacheEntry == null)
-    {
-      return null;
-    }
-
-
-    // Obtain a lock for the entry as appropriate.  If an error occurs, then
-    // make sure no lock is held and return null.  Otherwise, return the entry.
-    Entry entry = cacheEntry.getEntry();
-    switch (lockType)
-    {
-      case READ:
-        // Try to obtain a read lock for the entry.
-        Lock readLock = LockManager.lockRead(entry.getDN(), lockTimeout);
-        if (readLock == null)
-        {
-          // We couldn't get the lock, so we have to return null.
-          return null;
-        }
-        else
-        {
-          try
-          {
-            lockList.add(readLock);
-            return entry;
-          }
-          catch (Exception e)
-          {
-            if (debugEnabled())
-            {
-              TRACER.debugCaught(DebugLogLevel.ERROR, e);
-            }
-
-            // The attempt to add the lock to the list failed, so we need to
-            // release the lock and return null.
-            try
-            {
-              LockManager.unlock(entry.getDN(), readLock);
-            }
-            catch (Exception e2)
-            {
-              if (debugEnabled())
-              {
-                TRACER.debugCaught(DebugLogLevel.ERROR, e2);
-              }
-            }
-
-            return null;
-          }
-        }
-
-      case WRITE:
-        // Try to obtain a write lock for the entry.
-        Lock writeLock = LockManager.lockWrite(entry.getDN(), lockTimeout);
-        if (writeLock == null)
-        {
-          // We couldn't get the lock, so we have to return null.
-          return null;
-        }
-        else
-        {
-          try
-          {
-            lockList.add(writeLock);
-            return entry;
-          }
-          catch (Exception e)
-          {
-            if (debugEnabled())
-            {
-              TRACER.debugCaught(DebugLogLevel.ERROR, e);
-            }
-
-            // The attempt to add the lock to the list failed, so we need to
-            // release the lock and return null.
-            try
-            {
-              LockManager.unlock(entry.getDN(), writeLock);
-            }
-            catch (Exception e2)
-            {
-              if (debugEnabled())
-              {
-                TRACER.debugCaught(DebugLogLevel.ERROR, e2);
-              }
-            }
-
-            return null;
-          }
-        }
-
-      case NONE:
-        // We don't need to obtain a lock, so just return the entry.
-        return entry;
-
-      default:
-        // This is an unknown type of lock, so we'll return null.
-        return null;
-    }
+    return null;
   }
 
 

--
Gitblit v1.10.0