manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1540056 [1/2] - in /manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core: ./ lockmanager/
Date Fri, 08 Nov 2013 14:44:20 GMT
Author: kwright
Date: Fri Nov  8 14:44:19 2013
New Revision: 1540056

URL: http://svn.apache.org/r1540056
Log:
Revamp infrastructure for zookeeper to use a pool model

Added:
    manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperConnectionPool.java   (with props)
    manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperLockManager.java
      - copied, changed from r1539618, manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZookeeperLockManager.java
    manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperLockObject.java   (with props)
    manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperLockObjectFactory.java   (with props)
Removed:
    manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZookeeperLockManager.java
Modified:
    manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/LockClean.java
    manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/FileLockManager.java
    manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/FileLockObject.java
    manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/LockManager.java
    manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/LockObject.java
    manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperConnection.java

Modified: manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/LockClean.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/LockClean.java?rev=1540056&r1=1540055&r2=1540056&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/LockClean.java (original)
+++ manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/LockClean.java Fri Nov  8 14:44:19 2013
@@ -39,14 +39,13 @@ public class LockClean implements Initia
   public void execute() throws ManifoldCFException
   {
     ManifoldCF.initializeEnvironment(ThreadContextFactory.make());
-    String synchDir = ManifoldCF.getFileProperty(org.apache.manifoldcf.core.lockmanager.LockManager.synchDirectoryProperty).toString();
+    File synchDir = org.apache.manifoldcf.core.lockmanager.FileLockManager.getSynchDirectoryProperty();
     if (synchDir != null)
     {
       // Recursively clean up the contents of the synch directory. But don't remove the directory itself
-      File dir = new File(synchDir);
-      if (dir.isDirectory())
+      if (synchDir.isDirectory())
       {
-        removeContentsOfDirectory(dir);
+        removeContentsOfDirectory(synchDir);
       }
     }
     Logging.root.info("Synchronization storage cleaned up");

Modified: manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/FileLockManager.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/FileLockManager.java?rev=1540056&r1=1540055&r2=1540056&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/FileLockManager.java (original)
+++ manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/FileLockManager.java Fri Nov  8 14:44:19 2013
@@ -60,9 +60,16 @@ public class FileLockManager extends Bas
   public FileLockManager()
     throws ManifoldCFException
   {
-    this(ManifoldCF.getFileProperty(synchDirectoryProperty));
+    this(getSynchDirectoryProperty());
   }
 
+  /** Get the synch directory property. */
+  public static File getSynchDirectoryProperty()
+    throws ManifoldCFException
+  {
+    return ManifoldCF.getFileProperty(synchDirectoryProperty);
+  }
+  
   /** Calculate the name of a flag resource.
   *@param flagName is the name of the flag.
   *@return the name for the flag resource.

Modified: manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/FileLockObject.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/FileLockObject.java?rev=1540056&r1=1540055&r2=1540056&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/FileLockObject.java (original)
+++ manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/FileLockObject.java Fri Nov  8 14:44:19 2013
@@ -70,7 +70,7 @@ public class FileLockObject extends Lock
 
   @Override
   protected void obtainGlobalWriteLock()
-    throws LockException, InterruptedException
+    throws ManifoldCFException, LockException, InterruptedException
   {
     if (isSync)
     {
@@ -93,7 +93,7 @@ public class FileLockObject extends Lock
 
   @Override
   protected void clearGlobalWriteLock()
-    throws LockException, InterruptedException
+    throws ManifoldCFException, LockException, InterruptedException
   {
     if (isSync)
     {
@@ -110,8 +110,8 @@ public class FileLockObject extends Lock
   }
 
   @Override
-  protected void enterGlobalNonExWriteLock()
-    throws LockException, InterruptedException
+  protected void obtainGlobalNonExWriteLock()
+    throws ManifoldCFException, LockException, InterruptedException
   {
     // Attempt to obtain a global write lock
     if (isSync)
@@ -136,8 +136,8 @@ public class FileLockObject extends Lock
   }
 
   @Override
-  protected void leaveGlobalNonExWriteLock()
-    throws LockException, InterruptedException
+  protected void clearGlobalNonExWriteLock()
+    throws ManifoldCFException, LockException, InterruptedException
   {
     if (isSync)
     {
@@ -160,8 +160,8 @@ public class FileLockObject extends Lock
   }
 
   @Override
-  protected void enterGlobalReadLock()
-    throws LockException, InterruptedException
+  protected void obtainGlobalReadLock()
+    throws ManifoldCFException, LockException, InterruptedException
   {
     // Attempt to obtain a global read lock
     if (isSync)
@@ -185,8 +185,8 @@ public class FileLockObject extends Lock
   }
 
   @Override
-  protected void leaveGlobalReadLock()
-    throws LockException, InterruptedException
+  protected void clearGlobalReadLock()
+    throws ManifoldCFException, LockException, InterruptedException
   {
     if (isSync)
     {

Modified: manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/LockManager.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/LockManager.java?rev=1540056&r1=1540055&r2=1540056&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/LockManager.java (original)
+++ manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/LockManager.java Fri Nov  8 14:44:19 2013
@@ -31,204 +31,73 @@ public class LockManager implements ILoc
 {
   public static final String _rcsid = "@(#)$Id: LockManager.java 988245 2010-08-23 18:39:35Z kwright $";
 
-  /** Synchronization directory property - local to this implementation of ILockManager */
-  public static final String synchDirectoryProperty = "org.apache.manifoldcf.synchdirectory";
-
-  // These are the lock/section types, in order of escalation
-  protected final static int TYPE_READ = 1;
-  protected final static int TYPE_WRITENONEX = 2;
-  protected final static int TYPE_WRITE = 3;
-
-  // These are for locks (which cross JVM boundaries)
-  protected final HashMap localLocks = new HashMap();
-  protected final static Integer lockPoolInitialization = new Integer(0);
-  protected static LockPool myLocks = null;
-
-  // These are for critical sections (which do not cross JVM boundaries)
-  protected final HashMap localSections = new HashMap();
-  protected final static LockPool mySections = new LockPool(new LockObjectFactory());
-
-  // This is the directory used for cross-JVM synchronization, or null if off
-  protected File synchDirectory = null;
+  /** Backing lock manager */
+  protected final ILockManager lockManager;
 
   public LockManager()
     throws ManifoldCFException
   {
-    synchronized(lockPoolInitialization)
-    {
-      if (myLocks == null)
-      {
-        synchDirectory = ManifoldCF.getFileProperty(synchDirectoryProperty);
-        if (synchDirectory != null)
-        {
-          if (!synchDirectory.isDirectory())
-            throw new ManifoldCFException("Property "+synchDirectoryProperty+" must point to an existing, writeable directory!",ManifoldCFException.SETUP_ERROR);
-        }
-        myLocks = new LockPool(new FileLockObjectFactory(synchDirectory));
-      }
-    }
-  }
-
-  /** Calculate the name of a flag resource.
-  *@param flagName is the name of the flag.
-  *@return the name for the flag resource.
-  */
-  protected static String getFlagResourceName(String flagName)
-  {
-    return "flag-"+flagName;
+    File synchDirectory = FileLockManager.getSynchDirectoryProperty();
+    if (synchDirectory != null)
+      lockManager = new FileLockManager(synchDirectory);
+    else
+      lockManager = new BaseLockManager();
   }
-  
-  /** Global flag information.  This is used only when all of ManifoldCF is run within one process. */
-  protected static HashMap globalFlags = new HashMap();
-  
+
   /** Get the current shared configuration.  This configuration is available in common among all nodes,
   * and thus must not be accessed through here for the purpose of finding configuration data that is specific to any one
   * specific node.
   *@param configurationData is the globally-shared configuration information.
   */
+  @Override
   public ManifoldCFConfiguration getSharedConfiguration()
     throws ManifoldCFException
   {
-    // Local implementation vectors through to system property file, which is shared in this case
-    return ManifoldCF.getConfiguration();
+    return lockManager.getSharedConfiguration();
   }
 
   /** Raise a flag.  Use this method to assert a condition, or send a global signal.  The flag will be reset when the
   * entire system is restarted.
   *@param flagName is the name of the flag to set.
   */
+  @Override
   public void setGlobalFlag(String flagName)
     throws ManifoldCFException
   {
-    if (synchDirectory == null)
-    {
-      // Keep local flag information in memory
-      synchronized (globalFlags)
-      {
-        globalFlags.put(flagName,new Boolean(true));
-      }
-    }
-    else
-    {
-      String resourceName = getFlagResourceName(flagName);
-      String path = makeFilePath(resourceName);
-      (new File(path)).mkdirs();
-      File f = new File(path,ManifoldCF.safeFileName(resourceName));
-      try
-      {
-        f.createNewFile();
-      }
-      catch (InterruptedIOException e)
-      {
-        throw new ManifoldCFException("Interrupted: "+e.getMessage(),e,ManifoldCFException.INTERRUPTED);
-      }
-      catch (IOException e)
-      {
-        throw new ManifoldCFException(e.getMessage(),e);
-      }
-    }
+    lockManager.setGlobalFlag(flagName);
   }
 
   /** Clear a flag.  Use this method to clear a condition, or retract a global signal.
   *@param flagName is the name of the flag to clear.
   */
+  @Override
   public void clearGlobalFlag(String flagName)
     throws ManifoldCFException
   {
-    if (synchDirectory == null)
-    {
-      // Keep flag information in memory
-      synchronized (globalFlags)
-      {
-        globalFlags.remove(flagName);
-      }
-    }
-    else
-    {
-      String resourceName = getFlagResourceName(flagName);
-      File f = new File(makeFilePath(resourceName),ManifoldCF.safeFileName(resourceName));
-      f.delete();
-    }
+    lockManager.clearGlobalFlag(flagName);
   }
   
   /** Check the condition of a specified flag.
   *@param flagName is the name of the flag to check.
   *@return true if the flag is set, false otherwise.
   */
+  @Override
   public boolean checkGlobalFlag(String flagName)
     throws ManifoldCFException
   {
-    if (synchDirectory == null)
-    {
-      // Keep flag information in memory
-      synchronized (globalFlags)
-      {
-        return globalFlags.get(flagName) != null;
-      }
-    }
-    else
-    {
-      String resourceName = getFlagResourceName(flagName);
-      File f = new File(makeFilePath(resourceName),ManifoldCF.safeFileName(resourceName));
-      return f.exists();
-    }
+    return lockManager.checkGlobalFlag(flagName);
   }
 
-  /** Global resource data.  Used only when ManifoldCF is run entirely out of one process. */
-  protected static HashMap globalData = new HashMap();
-  
   /** Read data from a shared data resource.  Use this method to read any existing data, or get a null back if there is no such resource.
   * Note well that this is not necessarily an atomic operation, and it must thus be protected by a lock.
   *@param resourceName is the global name of the resource.
   *@return a byte array containing the data, or null.
   */
+  @Override
   public byte[] readData(String resourceName)
     throws ManifoldCFException
   {
-    if (synchDirectory == null)
-    {
-      // Keep resource data local
-      synchronized (globalData)
-      {
-        return (byte[])globalData.get(resourceName);
-      }
-    }
-    else
-    {
-      File f = new File(makeFilePath(resourceName),ManifoldCF.safeFileName(resourceName));
-      try
-      {
-        InputStream is = new FileInputStream(f);
-        try
-        {
-          ByteArrayBuffer bab = new ByteArrayBuffer();
-          while (true)
-          {
-            int x = is.read();
-            if (x == -1)
-              break;
-            bab.add((byte)x);
-          }
-          return bab.toArray();
-        }
-        finally
-        {
-          is.close();
-        }
-      }
-      catch (FileNotFoundException e)
-      {
-        return null;
-      }
-      catch (InterruptedIOException e)
-      {
-        throw new ManifoldCFException("Interrupted: "+e.getMessage(),e,ManifoldCFException.INTERRUPTED);
-      }
-      catch (IOException e)
-      {
-        throw new ManifoldCFException("IO exception: "+e.getMessage(),e);
-      }
-    }
+    return lockManager.readData(resourceName);
   }
   
   /** Write data to a shared data resource.  Use this method to write a body of data into a shared resource.
@@ -236,73 +105,20 @@ public class LockManager implements ILoc
   *@param resourceName is the global name of the resource.
   *@param data is the byte array containing the data.  Pass null if you want to delete the resource completely.
   */
+  @Override
   public void writeData(String resourceName, byte[] data)
     throws ManifoldCFException
   {
-    if (synchDirectory == null)
-    {
-      // Keep resource data local
-      synchronized (globalData)
-      {
-        if (data == null)
-          globalData.remove(resourceName);
-        else
-          globalData.put(resourceName,data);
-      }
-    }
-    else
-    {
-      try
-      {
-        String path = makeFilePath(resourceName);
-        // Make sure the directory exists
-        (new File(path)).mkdirs();
-        File f = new File(path,ManifoldCF.safeFileName(resourceName));
-        if (data == null)
-        {
-          f.delete();
-          return;
-        }
-        FileOutputStream os = new FileOutputStream(f);
-        try
-        {
-          os.write(data,0,data.length);
-        }
-        finally
-        {
-          os.close();
-        }
-      }
-      catch (InterruptedIOException e)
-      {
-        throw new ManifoldCFException("Interrupted: "+e.getMessage(),e,ManifoldCFException.INTERRUPTED);
-      }
-      catch (IOException e)
-      {
-        throw new ManifoldCFException("IO exception: "+e.getMessage(),e);
-      }
-    }
+    lockManager.writeData(resourceName,data);
   }
 
   /** Wait for a time before retrying a lock.
   */
+  @Override
   public void timedWait(int time)
     throws ManifoldCFException
   {
-
-    if (Logging.lock.isDebugEnabled())
-    {
-      Logging.lock.debug("Waiting for time "+Integer.toString(time));
-    }
-
-    try
-    {
-      ManifoldCF.sleep(time);
-    }
-    catch (InterruptedException e)
-    {
-      throw new ManifoldCFException("Interrupted",e,ManifoldCFException.INTERRUPTED);
-    }
+    lockManager.timedWait(time);
   }
 
   /** Enter a non-exclusive write-locked area (blocking out all readers, but letting in other "writers").
@@ -311,948 +127,106 @@ public class LockManager implements ILoc
   * to an individual item that might affect the query, but where multiple modifications do not individually
   * interfere with one another (use of another, standard, write lock per item can guarantee this).
   */
+  @Override
   public void enterNonExWriteLock(String lockKey)
     throws ManifoldCFException
   {
-
-    if (Logging.lock.isDebugEnabled())
-    {
-      Logging.lock.debug("Entering non-ex write lock '"+lockKey+"'");
-    }
-
-    LocalLock ll = getLocalLock(lockKey);
-
-
-    // See if we already own a write lock for the object
-    // If we do, there is no reason to change the status of the global lock we own.
-    if (ll.hasNonExWriteLock() || ll.hasWriteLock())
-    {
-      ll.incrementNonExWriteLocks();
-      Logging.lock.debug(" Successfully obtained lock!");
-      return;
-    }
-
-    // Check for illegalities
-    if (ll.hasReadLock())
-    {
-      throw new ManifoldCFException("Illegal lock sequence: NonExWrite lock can't be within read lock",ManifoldCFException.GENERAL_ERROR);
-    }
-
-    // We don't own a local non-ex write lock.  Get one.  The global lock will need
-    // to know if we already have a a read lock.
-    while (true)
-    {
-      LockObject lo = myLocks.getObject(lockKey);
-      try
-      {
-        lo.enterNonExWriteLock();
-        break;
-      }
-      catch (InterruptedException e)
-      {
-        throw new ManifoldCFException("Interrupted",e,ManifoldCFException.INTERRUPTED);
-      }
-      catch (ExpiredObjectException e)
-      {
-        // Try again to get a valid object
-      }
-    }
-    ll.incrementNonExWriteLocks();
-    Logging.lock.debug(" Successfully obtained lock!");
+    lockManager.enterNonExWriteLock(lockKey);
   }
 
+  @Override
   public void enterNonExWriteLockNoWait(String lockKey)
     throws ManifoldCFException, LockException
   {
-
-    if (Logging.lock.isDebugEnabled())
-    {
-      Logging.lock.debug("Entering non-ex write lock no wait '"+lockKey+"'");
-    }
-
-    LocalLock ll = getLocalLock(lockKey);
-
-
-    // See if we already own a write lock for the object
-    // If we do, there is no reason to change the status of the global lock we own.
-    if (ll.hasNonExWriteLock() || ll.hasWriteLock())
-    {
-      ll.incrementNonExWriteLocks();
-      Logging.lock.debug(" Successfully obtained lock!");
-      return;
-    }
-
-    // Check for illegalities
-    if (ll.hasReadLock())
-    {
-      throw new ManifoldCFException("Illegal lock sequence: NonExWrite lock can't be within read lock",ManifoldCFException.GENERAL_ERROR);
-    }
-
-    // We don't own a local non-ex write lock.  Get one.  The global lock will need
-    // to know if we already have a a read lock.
-    while (true)
-    {
-      LockObject lo = myLocks.getObject(lockKey);
-      try
-      {
-        synchronized (lo)
-        {
-          lo.enterNonExWriteLockNoWait();
-          break;
-        }
-      }
-      catch (LocalLockException e)
-      {
-
-        if (Logging.lock.isDebugEnabled())
-        {
-          Logging.lock.debug(" Could not non-ex write lock '"+lockKey+"', lock exception");
-        }
-
-        // Throw LockException instead
-        throw new LockException(e.getMessage());
-      }
-      catch (InterruptedException e)
-      {
-        throw new ManifoldCFException("Interrupted",e,ManifoldCFException.INTERRUPTED);
-      }
-      catch (ExpiredObjectException e)
-      {
-        // Try again to get a valid object
-      }
-    }
-    ll.incrementNonExWriteLocks();
-    Logging.lock.debug(" Successfully obtained lock!");
+    lockManager.enterNonExWriteLockNoWait(lockKey);
   }
 
   /** Leave a non-exclusive write lock.
   */
+  @Override
   public void leaveNonExWriteLock(String lockKey)
     throws ManifoldCFException
   {
-
-    if (Logging.lock.isDebugEnabled())
-    {
-      Logging.lock.debug("Leaving non-ex write lock '"+lockKey+"'");
-    }
-
-    LocalLock ll = getLocalLock(lockKey);
-
-    ll.decrementNonExWriteLocks();
-    // See if we no longer have a write lock for the object.
-    // If we retain the stronger exclusive lock, we still do not need to
-    // change the status of the global lock.
-    if (!(ll.hasNonExWriteLock() || ll.hasWriteLock()))
-    {
-      while (true)
-      {
-        LockObject lo = myLocks.getObject(lockKey);
-        try
-        {
-          lo.leaveNonExWriteLock();
-          break;
-        }
-        catch (InterruptedException e)
-        {
-          // try one more time
-          try
-          {
-            lo.leaveNonExWriteLock();
-            throw new ManifoldCFException("Interrupted",e,ManifoldCFException.INTERRUPTED);
-          }
-          catch (InterruptedException e2)
-          {
-            ll.incrementNonExWriteLocks();
-            throw new ManifoldCFException("Interrupted",e2,ManifoldCFException.INTERRUPTED);
-          }
-          catch (ExpiredObjectException e2)
-          {
-            ll.incrementNonExWriteLocks();
-            throw new ManifoldCFException("Interrupted",e,ManifoldCFException.INTERRUPTED);
-          }
-        }
-        catch (ExpiredObjectException e)
-        {
-          // Try again to get a valid object
-        }
-      }
-
-      releaseLocalLock(lockKey);
-    }
+    lockManager.leaveNonExWriteLock(lockKey);
   }
 
   /** Enter a write locked area (i.e., block out both readers and other writers)
   * NOTE: Can't enter until all readers have left.
   */
+  @Override
   public void enterWriteLock(String lockKey)
     throws ManifoldCFException
   {
-
-    if (Logging.lock.isDebugEnabled())
-    {
-      Logging.lock.debug("Entering write lock '"+lockKey+"'");
-    }
-
-    LocalLock ll = getLocalLock(lockKey);
-
-
-    // See if we already own the write lock for the object
-    if (ll.hasWriteLock())
-    {
-      ll.incrementWriteLocks();
-      Logging.lock.debug(" Successfully obtained lock!");
-      return;
-    }
-
-    // Check for illegalities
-    if (ll.hasReadLock() || ll.hasNonExWriteLock())
-    {
-      throw new ManifoldCFException("Illegal lock sequence: Write lock can't be within read lock or non-ex write lock",ManifoldCFException.GENERAL_ERROR);
-    }
-
-    // We don't own a local write lock.  Get one.  The global lock will need
-    // to know if we already have a non-exclusive lock or a read lock, which we don't because
-    // it's illegal.
-    while (true)
-    {
-      LockObject lo = myLocks.getObject(lockKey);
-      try
-      {
-        lo.enterWriteLock();
-        break;
-      }
-      catch (InterruptedException e)
-      {
-        throw new ManifoldCFException("Interrupted",e,ManifoldCFException.INTERRUPTED);
-      }
-      catch (ExpiredObjectException e)
-      {
-        // Try again
-      }
-    }
-    ll.incrementWriteLocks();
-    Logging.lock.debug(" Successfully obtained lock!");
+    lockManager.enterWriteLock(lockKey);
   }
 
+  @Override
   public void enterWriteLockNoWait(String lockKey)
     throws ManifoldCFException, LockException
   {
-
-    if (Logging.lock.isDebugEnabled())
-    {
-      Logging.lock.debug("Entering write lock no wait '"+lockKey+"'");
-    }
-
-    LocalLock ll = getLocalLock(lockKey);
-
-
-    // See if we already own the write lock for the object
-    if (ll.hasWriteLock())
-    {
-      ll.incrementWriteLocks();
-      Logging.lock.debug(" Successfully obtained lock!");
-      return;
-    }
-
-    // Check for illegalities
-    if (ll.hasReadLock() || ll.hasNonExWriteLock())
-    {
-      throw new ManifoldCFException("Illegal lock sequence: Write lock can't be within read lock or non-ex write lock",ManifoldCFException.GENERAL_ERROR);
-    }
-
-    // We don't own a local write lock.  Get one.  The global lock will need
-    // to know if we already have a non-exclusive lock or a read lock, which we don't because
-    // it's illegal.
-    while (true)
-    {
-      LockObject lo = myLocks.getObject(lockKey);
-      try
-      {
-        synchronized (lo)
-        {
-          lo.enterWriteLockNoWait();
-          break;
-        }
-      }
-      catch (LocalLockException e)
-      {
-
-        if (Logging.lock.isDebugEnabled())
-        {
-          Logging.lock.debug(" Could not write lock '"+lockKey+"', lock exception");
-        }
-
-        throw new LockException(e.getMessage());
-      }
-      catch (InterruptedException e)
-      {
-        throw new ManifoldCFException("Interrupted",e,ManifoldCFException.INTERRUPTED);
-      }
-      catch (ExpiredObjectException e)
-      {
-        // Try again
-      }
-    }
-
-    ll.incrementWriteLocks();
-    Logging.lock.debug(" Successfully obtained lock!");
+    lockManager.enterWriteLockNoWait(lockKey);
   }
 
+  @Override
   public void leaveWriteLock(String lockKey)
     throws ManifoldCFException
   {
-
-    if (Logging.lock.isDebugEnabled())
-    {
-      Logging.lock.debug("Leaving write lock '"+lockKey+"'");
-    }
-
-    LocalLock ll = getLocalLock(lockKey);
-
-    ll.decrementWriteLocks();
-    if (!ll.hasWriteLock())
-    {
-      while (true)
-      {
-        LockObject lo = myLocks.getObject(lockKey);
-        try
-        {
-          lo.leaveWriteLock();
-          break;
-        }
-        catch (InterruptedException e)
-        {
-          // try one more time
-          try
-          {
-            lo.leaveWriteLock();
-            throw new ManifoldCFException("Interrupted",e,ManifoldCFException.INTERRUPTED);
-          }
-          catch (InterruptedException e2)
-          {
-            ll.incrementWriteLocks();
-            throw new ManifoldCFException("Interrupted",e2,ManifoldCFException.INTERRUPTED);
-          }
-          catch (ExpiredObjectException e2)
-          {
-            ll.incrementWriteLocks();
-            throw new ManifoldCFException("Interrupted",e,ManifoldCFException.INTERRUPTED);
-          }
-        }
-        catch (ExpiredObjectException e)
-        {
-          // Try again
-        }
-      }
-
-      releaseLocalLock(lockKey);
-    }
+    lockManager.leaveWriteLock(lockKey);
   }
 
   /** Enter a read-only locked area (i.e., block ONLY if there's a writer)
   */
+  @Override
   public void enterReadLock(String lockKey)
     throws ManifoldCFException
   {
-
-    if (Logging.lock.isDebugEnabled())
-    {
-      Logging.lock.debug("Entering read lock '"+lockKey+"'");
-    }
-
-
-    LocalLock ll = getLocalLock(lockKey);
-
-    // See if we already own the read lock for the object.
-    // Write locks or non-ex writelocks count as well (they're stronger).
-    if (ll.hasReadLock() || ll.hasNonExWriteLock() || ll.hasWriteLock())
-    {
-      ll.incrementReadLocks();
-      Logging.lock.debug(" Successfully obtained lock!");
-      return;
-    }
-
-    // We don't own a local read lock.  Get one.
-    while (true)
-    {
-      LockObject lo = myLocks.getObject(lockKey);
-      try
-      {
-        lo.enterReadLock();
-        break;
-      }
-      catch (InterruptedException e)
-      {
-        throw new ManifoldCFException("Interrupted",e,ManifoldCFException.INTERRUPTED);
-      }
-      catch (ExpiredObjectException e)
-      {
-        // Try again
-      }
-    }
-    ll.incrementReadLocks();
-    Logging.lock.debug(" Successfully obtained lock!");
+    lockManager.enterReadLock(lockKey);
   }
 
+  @Override
   public void enterReadLockNoWait(String lockKey)
     throws ManifoldCFException, LockException
   {
-
-    if (Logging.lock.isDebugEnabled())
-    {
-      Logging.lock.debug("Entering read lock no wait '"+lockKey+"'");
-    }
-
-    LocalLock ll = getLocalLock(lockKey);
-
-    // See if we already own the read lock for the object.
-    // Write locks or non-ex writelocks count as well (they're stronger).
-    if (ll.hasReadLock() || ll.hasNonExWriteLock() || ll.hasWriteLock())
-    {
-      ll.incrementReadLocks();
-      Logging.lock.debug(" Successfully obtained lock!");
-      return;
-    }
-
-    // We don't own a local read lock.  Get one.
-    while (true)
-    {
-      LockObject lo = myLocks.getObject(lockKey);
-      try
-      {
-        synchronized (lo)
-        {
-          lo.enterReadLockNoWait();
-          break;
-        }
-      }
-      catch (LocalLockException e)
-      {
-
-        if (Logging.lock.isDebugEnabled())
-        {
-          Logging.lock.debug(" Could not read lock '"+lockKey+"', lock exception");
-        }
-
-        throw new LockException(e.getMessage());
-      }
-      catch (InterruptedException e)
-      {
-        throw new ManifoldCFException("Interrupted",e,ManifoldCFException.INTERRUPTED);
-      }
-      catch (ExpiredObjectException e)
-      {
-        // Try again
-      }
-    }
-
-    ll.incrementReadLocks();
-    Logging.lock.debug(" Successfully obtained lock!");
+    lockManager.enterReadLockNoWait(lockKey);
   }
 
+  @Override
   public void leaveReadLock(String lockKey)
     throws ManifoldCFException
   {
-
-    if (Logging.lock.isDebugEnabled())
-    {
-      Logging.lock.debug("Leaving read lock '"+lockKey+"'");
-    }
-
-    LocalLock ll = getLocalLock(lockKey);
-
-    ll.decrementReadLocks();
-    if (!(ll.hasReadLock() || ll.hasNonExWriteLock() || ll.hasWriteLock()))
-    {
-      while (true)
-      {
-        LockObject lo = myLocks.getObject(lockKey);
-        try
-        {
-          lo.leaveReadLock();
-          break;
-        }
-        catch (InterruptedException e)
-        {
-          // Try one more time
-          try
-          {
-            lo.leaveReadLock();
-            throw new ManifoldCFException("Interrupted",e,ManifoldCFException.INTERRUPTED);
-          }
-          catch (InterruptedException e2)
-          {
-            ll.incrementReadLocks();
-            throw new ManifoldCFException("Interrupted",e2,ManifoldCFException.INTERRUPTED);
-          }
-          catch (ExpiredObjectException e2)
-          {
-            ll.incrementReadLocks();
-            throw new ManifoldCFException("Interrupted",e,ManifoldCFException.INTERRUPTED);
-          }
-        }
-        catch (ExpiredObjectException e)
-        {
-          // Try again
-        }
-      }
-      releaseLocalLock(lockKey);
-    }
+    lockManager.leaveReadLock(lockKey);
   }
 
+  @Override
   public void clearLocks()
     throws ManifoldCFException
   {
-
-    if (Logging.lock.isDebugEnabled())
-    {
-      Logging.lock.debug("Clearing all locks");
-    }
-
-
-    Iterator e = localLocks.keySet().iterator();
-    while (e.hasNext())
-    {
-      String keyValue = (String)e.next();
-      LocalLock ll = (LocalLock)localLocks.get(keyValue);
-      while (ll.hasWriteLock())
-        leaveWriteLock(keyValue);
-      while (ll.hasNonExWriteLock())
-        leaveNonExWriteLock(keyValue);
-      while (ll.hasReadLock())
-        leaveReadLock(keyValue);
-    }
+    lockManager.clearLocks();
   }
 
   /** Enter multiple locks
   */
+  @Override
   public void enterLocks(String[] readLocks, String[] nonExWriteLocks, String[] writeLocks)
     throws ManifoldCFException
   {
-
-    if (Logging.lock.isDebugEnabled())
-    {
-      Logging.lock.debug("Entering multiple locks:");
-      int i;
-      if (readLocks != null)
-      {
-        i = 0;
-        while (i < readLocks.length)
-        {
-          Logging.lock.debug(" Read lock '"+readLocks[i++]+"'");
-        }
-      }
-      if (nonExWriteLocks != null)
-      {
-        i = 0;
-        while (i < nonExWriteLocks.length)
-        {
-          Logging.lock.debug(" Non-ex write lock '"+nonExWriteLocks[i++]+"'");
-        }
-      }
-      if (writeLocks != null)
-      {
-        i = 0;
-        while (i < writeLocks.length)
-        {
-          Logging.lock.debug(" Write lock '"+writeLocks[i++]+"'");
-        }
-      }
-    }
-
-
-    // Sort the locks.  This improves the chances of making it through the locking process without
-    // contention!
-    LockDescription lds[] = getSortedUniqueLocks(readLocks,nonExWriteLocks,writeLocks);
-    int locksProcessed = 0;
-    try
-    {
-      while (locksProcessed < lds.length)
-      {
-        LockDescription ld = lds[locksProcessed];
-        int lockType = ld.getType();
-        String lockKey = ld.getKey();
-        LocalLock ll;
-        switch (lockType)
-        {
-        case TYPE_WRITE:
-          ll = getLocalLock(lockKey);
-          // Check for illegalities
-          if ((ll.hasReadLock() || ll.hasNonExWriteLock()) && !ll.hasWriteLock())
-          {
-            throw new ManifoldCFException("Illegal lock sequence: Write lock can't be within read lock or non-ex write lock",ManifoldCFException.GENERAL_ERROR);
-          }
-
-          // See if we already own the write lock for the object
-          if (!ll.hasWriteLock())
-          {
-            // We don't own a local write lock.  Get one.
-            while (true)
-            {
-              LockObject lo = myLocks.getObject(lockKey);
-              try
-              {
-                lo.enterWriteLock();
-                break;
-              }
-              catch (ExpiredObjectException e)
-              {
-                // Try again
-              }
-            }
-          }
-          ll.incrementWriteLocks();
-          break;
-        case TYPE_WRITENONEX:
-          ll = getLocalLock(lockKey);
-          // Check for illegalities
-          if (ll.hasReadLock() && !(ll.hasNonExWriteLock() || ll.hasWriteLock()))
-          {
-            throw new ManifoldCFException("Illegal lock sequence: NonExWrite lock can't be within read lock",ManifoldCFException.GENERAL_ERROR);
-          }
-
-          // See if we already own the write lock for the object
-          if (!(ll.hasNonExWriteLock() || ll.hasWriteLock()))
-          {
-            // We don't own a local write lock.  Get one.
-            while (true)
-            {
-              LockObject lo = myLocks.getObject(lockKey);
-              try
-              {
-                lo.enterNonExWriteLock();
-                break;
-              }
-              catch (ExpiredObjectException e)
-              {
-                // Try again
-              }
-            }
-          }
-          ll.incrementNonExWriteLocks();
-          break;
-        case TYPE_READ:
-          ll = getLocalLock(lockKey);
-          if (!(ll.hasReadLock() || ll.hasNonExWriteLock() || ll.hasWriteLock()))
-          {
-            // We don't own a local read lock.  Get one.
-            while (true)
-            {
-              LockObject lo = myLocks.getObject(lockKey);
-              try
-              {
-                lo.enterReadLock();
-                break;
-              }
-              catch (ExpiredObjectException e)
-              {
-                // Try again
-              }
-            }
-          }
-          ll.incrementReadLocks();
-          break;
-        }
-        locksProcessed++;
-      }
-      // Got all; we are done!
-      Logging.lock.debug(" Successfully obtained multiple locks!");
-      return;
-    }
-    catch (Throwable ex)
-    {
-      // No matter what, undo the locks we've taken
-      ManifoldCFException ae = null;
-      int errno = 0;
-
-      while (--locksProcessed >= 0)
-      {
-        LockDescription ld = lds[locksProcessed];
-        int lockType = ld.getType();
-        String lockKey = ld.getKey();
-        try
-        {
-          switch (lockType)
-          {
-          case TYPE_READ:
-            leaveReadLock(lockKey);
-            break;
-          case TYPE_WRITENONEX:
-            leaveNonExWriteLock(lockKey);
-            break;
-          case TYPE_WRITE:
-            leaveWriteLock(lockKey);
-            break;
-          }
-        }
-        catch (ManifoldCFException e)
-        {
-          ae = e;
-        }
-      }
-
-      if (ae != null)
-      {
-        throw ae;
-      }
-      if (ex instanceof ManifoldCFException)
-      {
-        throw (ManifoldCFException)ex;
-      }
-      if (ex instanceof InterruptedException)
-      {
-        // It's InterruptedException
-        throw new ManifoldCFException("Interrupted",ex,ManifoldCFException.INTERRUPTED);
-      }
-      if (!(ex instanceof Error))
-      {
-        throw new Error("Unexpected exception",ex);
-      }
-      throw (Error)ex;
-    }
+    lockManager.enterLocks(readLocks, nonExWriteLocks, writeLocks);
   }
 
+  @Override
   public void enterLocksNoWait(String[] readLocks, String[] nonExWriteLocks, String[] writeLocks)
     throws ManifoldCFException, LockException
   {
-
-    if (Logging.lock.isDebugEnabled())
-    {
-      Logging.lock.debug("Entering multiple locks no wait:");
-      int i;
-      if (readLocks != null)
-      {
-        i = 0;
-        while (i < readLocks.length)
-        {
-          Logging.lock.debug(" Read lock '"+readLocks[i++]+"'");
-        }
-      }
-      if (nonExWriteLocks != null)
-      {
-        i = 0;
-        while (i < nonExWriteLocks.length)
-        {
-          Logging.lock.debug(" Non-ex write lock '"+nonExWriteLocks[i++]+"'");
-        }
-      }
-      if (writeLocks != null)
-      {
-        i = 0;
-        while (i < writeLocks.length)
-        {
-          Logging.lock.debug(" Write lock '"+writeLocks[i++]+"'");
-        }
-      }
-    }
-
-
-    // Sort the locks.  This improves the chances of making it through the locking process without
-    // contention!
-    LockDescription lds[] = getSortedUniqueLocks(readLocks,nonExWriteLocks,writeLocks);
-    int locksProcessed = 0;
-    try
-    {
-      while (locksProcessed < lds.length)
-      {
-        LockDescription ld = lds[locksProcessed];
-        int lockType = ld.getType();
-        String lockKey = ld.getKey();
-        LocalLock ll;
-        switch (lockType)
-        {
-        case TYPE_WRITE:
-          ll = getLocalLock(lockKey);
-          // Check for illegalities
-          if ((ll.hasReadLock() || ll.hasNonExWriteLock()) && !ll.hasWriteLock())
-          {
-            throw new ManifoldCFException("Illegal lock sequence: Write lock can't be within read lock or non-ex write lock",ManifoldCFException.GENERAL_ERROR);
-          }
-
-          // See if we already own the write lock for the object
-          if (!ll.hasWriteLock())
-          {
-            // We don't own a local write lock.  Get one.
-            while (true)
-            {
-              LockObject lo = myLocks.getObject(lockKey);
-              synchronized (lo)
-              {
-                try
-                {
-                  lo.enterWriteLockNoWait();
-                  break;
-                }
-                catch (ExpiredObjectException e)
-                {
-                  // Try again
-                }
-              }
-            }
-          }
-          ll.incrementWriteLocks();
-          break;
-        case TYPE_WRITENONEX:
-          ll = getLocalLock(lockKey);
-          // Check for illegalities
-          if (ll.hasReadLock() && !(ll.hasNonExWriteLock() || ll.hasWriteLock()))
-          {
-            throw new ManifoldCFException("Illegal lock sequence: NonExWrite lock can't be within read lock",ManifoldCFException.GENERAL_ERROR);
-          }
-
-          // See if we already own the write lock for the object
-          if (!(ll.hasNonExWriteLock() || ll.hasWriteLock()))
-          {
-            // We don't own a local write lock.  Get one.
-            while (true)
-            {
-              LockObject lo = myLocks.getObject(lockKey);
-              synchronized (lo)
-              {
-                try
-                {
-                  lo.enterNonExWriteLockNoWait();
-                  break;
-                }
-                catch (ExpiredObjectException e)
-                {
-                  // Try again
-                }
-              }
-            }
-          }
-          ll.incrementNonExWriteLocks();
-          break;
-        case TYPE_READ:
-          ll = getLocalLock(lockKey);
-          if (!(ll.hasReadLock() || ll.hasNonExWriteLock() || ll.hasWriteLock()))
-          {
-            // We don't own a local read lock.  Get one.
-            while (true)
-            {
-              LockObject lo = myLocks.getObject(lockKey);
-              synchronized (lo)
-              {
-                try
-                {
-                  lo.enterReadLockNoWait();
-                  break;
-                }
-                catch (ExpiredObjectException e)
-                {
-                  // Try again
-                }
-              }
-            }
-          }
-          ll.incrementReadLocks();
-          break;
-        }
-        locksProcessed++;
-      }
-      // Got all; we are done!
-      Logging.lock.debug(" Successfully obtained multiple locks!");
-      return;
-    }
-    catch (Throwable ex)
-    {
-      // No matter what, undo the locks we've taken
-      ManifoldCFException ae = null;
-      int errno = 0;
-
-      while (--locksProcessed >= 0)
-      {
-        LockDescription ld = lds[locksProcessed];
-        int lockType = ld.getType();
-        String lockKey = ld.getKey();
-        try
-        {
-          switch (lockType)
-          {
-          case TYPE_READ:
-            leaveReadLock(lockKey);
-            break;
-          case TYPE_WRITENONEX:
-            leaveNonExWriteLock(lockKey);
-            break;
-          case TYPE_WRITE:
-            leaveWriteLock(lockKey);
-            break;
-          }
-        }
-        catch (ManifoldCFException e)
-        {
-          ae = e;
-        }
-      }
-
-      if (ae != null)
-      {
-        throw ae;
-      }
-      if (ex instanceof ManifoldCFException)
-      {
-        throw (ManifoldCFException)ex;
-      }
-      if (ex instanceof LockException || ex instanceof LocalLockException)
-      {
-        Logging.lock.debug(" Couldn't get lock; throwing LockException");
-        // It's either LockException or LocalLockException
-        throw new LockException(ex.getMessage());
-      }
-      if (ex instanceof InterruptedException)
-      {
-        throw new ManifoldCFException("Interrupted",ex,ManifoldCFException.INTERRUPTED);
-      }
-      if (!(ex instanceof Error))
-      {
-        throw new Error("Unexpected exception",ex);
-      }
-      throw (Error)ex;
-
-    }
-
+    lockManager.enterLocksNoWait(readLocks, nonExWriteLocks, writeLocks);
   }
 
   /** Leave multiple locks
   */
+  @Override
   public void leaveLocks(String[] readLocks, String[] writeNonExLocks, String[] writeLocks)
     throws ManifoldCFException
   {
-    LockDescription[] lds = getSortedUniqueLocks(readLocks,writeNonExLocks,writeLocks);
-    // Free them all... one at a time is fine
-    ManifoldCFException ae = null;
-    int i = lds.length;
-    while (--i >= 0)
-    {
-      LockDescription ld = lds[i];
-      String lockKey = ld.getKey();
-      int lockType = ld.getType();
-      try
-      {
-        switch (lockType)
-        {
-        case TYPE_READ:
-          leaveReadLock(lockKey);
-          break;
-        case TYPE_WRITENONEX:
-          leaveNonExWriteLock(lockKey);
-          break;
-        case TYPE_WRITE:
-          leaveWriteLock(lockKey);
-          break;
-        }
-      }
-      catch (ManifoldCFException e)
-      {
-        ae = e;
-      }
-    }
-
-    if (ae != null)
-    {
-      throw ae;
-    }
+    lockManager.leaveLocks(readLocks, writeNonExLocks, writeLocks);
   }
 
   /** Enter a named, read critical section (NOT a lock).  Critical sections never cross JVM boundaries.
@@ -1260,38 +234,11 @@ public class LockManager implements ILoc
   *@param sectionKey is the name of the section to enter.  Only one thread can be in any given named
   * section at a time.
   */
+  @Override
   public void enterReadCriticalSection(String sectionKey)
     throws ManifoldCFException
   {
-    LocalLock ll = getLocalSection(sectionKey);
-
-    // See if we already own the read lock for the object.
-    // Write locks or non-ex writelocks count as well (they're stronger).
-    if (ll.hasReadLock() || ll.hasNonExWriteLock() || ll.hasWriteLock())
-    {
-      ll.incrementReadLocks();
-      return;
-    }
-
-    // We don't own a local read lock.  Get one.
-    while (true)
-    {
-      LockObject lo = mySections.getObject(sectionKey);
-      try
-      {
-        lo.enterReadLock();
-        break;
-      }
-      catch (InterruptedException e)
-      {
-        throw new ManifoldCFException("Interrupted",e,ManifoldCFException.INTERRUPTED);
-      }
-      catch (ExpiredObjectException e)
-      {
-        // Try again
-      }
-    }
-    ll.incrementReadLocks();
+    lockManager.enterReadCriticalSection(sectionKey);
   }
 
   /** Leave a named, read critical section (NOT a lock).  Critical sections never cross JVM boundaries.
@@ -1299,49 +246,11 @@ public class LockManager implements ILoc
   *@param sectionKey is the name of the section to leave.  Only one thread can be in any given named
   * section at a time.
   */
+  @Override
   public void leaveReadCriticalSection(String sectionKey)
     throws ManifoldCFException
   {
-    LocalLock ll = getLocalSection(sectionKey);
-
-    ll.decrementReadLocks();
-    if (!(ll.hasReadLock() || ll.hasNonExWriteLock() || ll.hasWriteLock()))
-    {
-      while (true)
-      {
-        LockObject lo = mySections.getObject(sectionKey);
-        try
-        {
-          lo.leaveReadLock();
-          break;
-        }
-        catch (InterruptedException e)
-        {
-          // Try one more time
-          try
-          {
-            lo.leaveReadLock();
-            throw new ManifoldCFException("Interrupted",e,ManifoldCFException.INTERRUPTED);
-          }
-          catch (InterruptedException e2)
-          {
-            ll.incrementReadLocks();
-            throw new ManifoldCFException("Interrupted",e2,ManifoldCFException.INTERRUPTED);
-          }
-          catch (ExpiredObjectException e2)
-          {
-            ll.incrementReadLocks();
-            throw new ManifoldCFException("Interrupted",e,ManifoldCFException.INTERRUPTED);
-          }
-        }
-        catch (ExpiredObjectException e)
-        {
-          // Try again
-        }
-      }
-
-      releaseLocalSection(sectionKey);
-    }
+    lockManager.leaveReadCriticalSection(sectionKey);
   }
 
   /** Enter a named, non-exclusive write critical section (NOT a lock).  Critical sections never cross JVM boundaries.
@@ -1349,46 +258,11 @@ public class LockManager implements ILoc
   *@param sectionKey is the name of the section to enter.  Only one thread can be in any given named
   * section at a time.
   */
+  @Override
   public void enterNonExWriteCriticalSection(String sectionKey)
     throws ManifoldCFException
   {
-    LocalLock ll = getLocalSection(sectionKey);
-
-
-    // See if we already own a write lock for the object
-    // If we do, there is no reason to change the status of the global lock we own.
-    if (ll.hasNonExWriteLock() || ll.hasWriteLock())
-    {
-      ll.incrementNonExWriteLocks();
-      return;
-    }
-
-    // Check for illegalities
-    if (ll.hasReadLock())
-    {
-      throw new ManifoldCFException("Illegal lock sequence: NonExWrite critical section can't be within read critical section",ManifoldCFException.GENERAL_ERROR);
-    }
-
-    // We don't own a local non-ex write lock.  Get one.  The global lock will need
-    // to know if we already have a a read lock.
-    while (true)
-    {
-      LockObject lo = mySections.getObject(sectionKey);
-      try
-      {
-        lo.enterNonExWriteLock();
-        break;
-      }
-      catch (InterruptedException e)
-      {
-        throw new ManifoldCFException("Interrupted",e,ManifoldCFException.INTERRUPTED);
-      }
-      catch (ExpiredObjectException e)
-      {
-        // Try again
-      }
-    }
-    ll.incrementNonExWriteLocks();
+    lockManager.enterNonExWriteCriticalSection(sectionKey);
   }
 
   /** Leave a named, non-exclusive write critical section (NOT a lock).  Critical sections never cross JVM boundaries.
@@ -1396,52 +270,11 @@ public class LockManager implements ILoc
   *@param sectionKey is the name of the section to leave.  Only one thread can be in any given named
   * section at a time.
   */
+  @Override
   public void leaveNonExWriteCriticalSection(String sectionKey)
     throws ManifoldCFException
   {
-    LocalLock ll = getLocalSection(sectionKey);
-
-    ll.decrementNonExWriteLocks();
-    // See if we no longer have a write lock for the object.
-    // If we retain the stronger exclusive lock, we still do not need to
-    // change the status of the global lock.
-    if (!(ll.hasNonExWriteLock() || ll.hasWriteLock()))
-    {
-      while (true)
-      {
-        LockObject lo = mySections.getObject(sectionKey);
-        try
-        {
-          lo.leaveNonExWriteLock();
-          break;
-        }
-        catch (InterruptedException e)
-        {
-          // try one more time
-          try
-          {
-            lo.leaveNonExWriteLock();
-            throw new ManifoldCFException("Interrupted",e,ManifoldCFException.INTERRUPTED);
-          }
-          catch (InterruptedException e2)
-          {
-            ll.incrementNonExWriteLocks();
-            throw new ManifoldCFException("Interrupted",e2,ManifoldCFException.INTERRUPTED);
-          }
-          catch (ExpiredObjectException e2)
-          {
-            ll.incrementNonExWriteLocks();
-            throw new ManifoldCFException("Interrupted",e,ManifoldCFException.INTERRUPTED);
-          }
-        }
-        catch (ExpiredObjectException e)
-        {
-          // Try again
-        }
-      }
-
-      releaseLocalSection(sectionKey);
-    }
+    lockManager.leaveNonExWriteCriticalSection(sectionKey);
   }
 
   /** Enter a named, exclusive critical section (NOT a lock).  Critical sections never cross JVM boundaries.
@@ -1449,47 +282,11 @@ public class LockManager implements ILoc
   *@param sectionKey is the name of the section to enter.  Only one thread can be in any given named
   * section at a time.
   */
+  @Override
   public void enterWriteCriticalSection(String sectionKey)
     throws ManifoldCFException
   {
-    LocalLock ll = getLocalSection(sectionKey);
-
-
-    // See if we already own the write lock for the object
-    if (ll.hasWriteLock())
-    {
-      ll.incrementWriteLocks();
-      return;
-    }
-
-    // Check for illegalities
-    if (ll.hasReadLock() || ll.hasNonExWriteLock())
-    {
-      throw new ManifoldCFException("Illegal lock sequence: Write lock can't be within read lock or non-ex write lock",ManifoldCFException.GENERAL_ERROR);
-    }
-
-    // We don't own a local write lock.  Get one.  The global lock will need
-    // to know if we already have a non-exclusive lock or a read lock, which we don't because
-    // it's illegal.
-    while (true)
-    {
-      LockObject lo = mySections.getObject(sectionKey);
-      try
-      {
-        lo.enterWriteLock();
-        break;
-      }
-      catch (InterruptedException e)
-      {
-        throw new ManifoldCFException("Interrupted",e,ManifoldCFException.INTERRUPTED);
-      }
-      catch (ExpiredObjectException e)
-      {
-        // Try again
-      }
-    }
-    ll.incrementWriteLocks();
-
+    lockManager.enterWriteCriticalSection(sectionKey);
   }
 
   /** Leave a named, exclusive critical section (NOT a lock).  Critical sections never cross JVM boundaries.
@@ -1497,49 +294,11 @@ public class LockManager implements ILoc
   *@param sectionKey is the name of the section to leave.  Only one thread can be in any given named
   * section at a time.
   */
+  @Override
   public void leaveWriteCriticalSection(String sectionKey)
     throws ManifoldCFException
   {
-    LocalLock ll = getLocalSection(sectionKey);
-
-    ll.decrementWriteLocks();
-    if (!ll.hasWriteLock())
-    {
-      while (true)
-      {
-        LockObject lo = mySections.getObject(sectionKey);
-        try
-        {
-          lo.leaveWriteLock();
-          break;
-        }
-        catch (InterruptedException e)
-        {
-          // try one more time
-          try
-          {
-            lo.leaveWriteLock();
-            throw new ManifoldCFException("Interrupted",e,ManifoldCFException.INTERRUPTED);
-          }
-          catch (InterruptedException e2)
-          {
-            ll.incrementWriteLocks();
-            throw new ManifoldCFException("Interrupted",e2,ManifoldCFException.INTERRUPTED);
-          }
-          catch (ExpiredObjectException e2)
-          {
-            ll.incrementWriteLocks();
-            throw new ManifoldCFException("Interrupted",e,ManifoldCFException.INTERRUPTED);
-          }
-        }
-        catch (ExpiredObjectException e)
-        {
-          // Try again
-        }
-      }
-
-      releaseLocalSection(sectionKey);
-    }
+    lockManager.leaveWriteCriticalSection(sectionKey);
   }
 
   /** Enter multiple critical sections simultaneously.
@@ -1547,157 +306,11 @@ public class LockManager implements ILoc
   *@param nonExSectionKeys is an array of non-ex write section descriptors, or null if none desired.
   *@param writeSectionKeys is an array of write section descriptors, or null if there are none desired.
   */
+  @Override
   public void enterCriticalSections(String[] readSectionKeys, String[] nonExSectionKeys, String[] writeSectionKeys)
     throws ManifoldCFException
   {
-    // Sort the locks.  This improves the chances of making it through the locking process without
-    // contention!
-    LockDescription lds[] = getSortedUniqueLocks(readSectionKeys,nonExSectionKeys,writeSectionKeys);
-    int locksProcessed = 0;
-    try
-    {
-      while (locksProcessed < lds.length)
-      {
-        LockDescription ld = lds[locksProcessed];
-        int lockType = ld.getType();
-        String lockKey = ld.getKey();
-        LocalLock ll;
-        switch (lockType)
-        {
-        case TYPE_WRITE:
-          ll = getLocalSection(lockKey);
-          // Check for illegalities
-          if ((ll.hasReadLock() || ll.hasNonExWriteLock()) && !ll.hasWriteLock())
-          {
-            throw new ManifoldCFException("Illegal lock sequence: Write critical section can't be within read critical section or non-ex write critical section",ManifoldCFException.GENERAL_ERROR);
-          }
-
-          // See if we already own the write lock for the object
-          if (!ll.hasWriteLock())
-          {
-            // We don't own a local write lock.  Get one.
-            while (true)
-            {
-              LockObject lo = mySections.getObject(lockKey);
-              try
-              {
-                lo.enterWriteLock();
-                break;
-              }
-              catch (ExpiredObjectException e)
-              {
-                // Try again
-              }
-            }
-          }
-          ll.incrementWriteLocks();
-          break;
-        case TYPE_WRITENONEX:
-          ll = getLocalSection(lockKey);
-          // Check for illegalities
-          if (ll.hasReadLock() && !(ll.hasNonExWriteLock() || ll.hasWriteLock()))
-          {
-            throw new ManifoldCFException("Illegal lock sequence: NonExWrite critical section can't be within read critical section",ManifoldCFException.GENERAL_ERROR);
-          }
-
-          // See if we already own the write lock for the object
-          if (!(ll.hasNonExWriteLock() || ll.hasWriteLock()))
-          {
-            // We don't own a local write lock.  Get one.
-            while (true)
-            {
-              LockObject lo = mySections.getObject(lockKey);
-              try
-              {
-                lo.enterNonExWriteLock();
-                break;
-              }
-              catch (ExpiredObjectException e)
-              {
-                // Try again
-              }
-            }
-          }
-          ll.incrementNonExWriteLocks();
-          break;
-        case TYPE_READ:
-          ll = getLocalSection(lockKey);
-          if (!(ll.hasReadLock() || ll.hasNonExWriteLock() || ll.hasWriteLock()))
-          {
-            // We don't own a local read lock.  Get one.
-            while (true)
-            {
-              LockObject lo = mySections.getObject(lockKey);
-              try
-              {
-                lo.enterReadLock();
-                break;
-              }
-              catch (ExpiredObjectException e)
-              {
-                // Try again
-              }
-            }
-          }
-          ll.incrementReadLocks();
-          break;
-        }
-        locksProcessed++;
-      }
-      // Got all; we are done!
-      return;
-    }
-    catch (Throwable ex)
-    {
-      // No matter what, undo the locks we've taken
-      ManifoldCFException ae = null;
-      int errno = 0;
-
-      while (--locksProcessed >= 0)
-      {
-        LockDescription ld = lds[locksProcessed];
-        int lockType = ld.getType();
-        String lockKey = ld.getKey();
-        try
-        {
-          switch (lockType)
-          {
-          case TYPE_READ:
-            leaveReadCriticalSection(lockKey);
-            break;
-          case TYPE_WRITENONEX:
-            leaveNonExWriteCriticalSection(lockKey);
-            break;
-          case TYPE_WRITE:
-            leaveWriteCriticalSection(lockKey);
-            break;
-          }
-        }
-        catch (ManifoldCFException e)
-        {
-          ae = e;
-        }
-      }
-
-      if (ae != null)
-      {
-        throw ae;
-      }
-      if (ex instanceof ManifoldCFException)
-      {
-        throw (ManifoldCFException)ex;
-      }
-      if (ex instanceof InterruptedException)
-      {
-        // It's InterruptedException
-        throw new ManifoldCFException("Interrupted",ex,ManifoldCFException.INTERRUPTED);
-      }
-      if (!(ex instanceof Error))
-      {
-        throw new Error("Unexpected exception",ex);
-      }
-      throw (Error)ex;
-    }
+    lockManager.enterCriticalSections(readSectionKeys, nonExSectionKeys, writeSectionKeys);
   }
 
   /** Leave multiple critical sections simultaneously.
@@ -1705,284 +318,11 @@ public class LockManager implements ILoc
   *@param nonExSectionKeys is an array of non-ex write section descriptors, or null if none desired.
   *@param writeSectionKeys is an array of write section descriptors, or null if there are none desired.
   */
+  @Override
   public void leaveCriticalSections(String[] readSectionKeys, String[] nonExSectionKeys, String[] writeSectionKeys)
     throws ManifoldCFException
   {
-    LockDescription[] lds = getSortedUniqueLocks(readSectionKeys,nonExSectionKeys,writeSectionKeys);
-    // Free them all... one at a time is fine
-    ManifoldCFException ae = null;
-    int i = lds.length;
-    while (--i >= 0)
-    {
-      LockDescription ld = lds[i];
-      String lockKey = ld.getKey();
-      int lockType = ld.getType();
-      try
-      {
-        switch (lockType)
-        {
-        case TYPE_READ:
-          leaveReadCriticalSection(lockKey);
-          break;
-        case TYPE_WRITENONEX:
-          leaveNonExWriteCriticalSection(lockKey);
-          break;
-        case TYPE_WRITE:
-          leaveWriteCriticalSection(lockKey);
-          break;
-        }
-      }
-      catch (ManifoldCFException e)
-      {
-        ae = e;
-      }
-    }
-
-    if (ae != null)
-    {
-      throw ae;
-    }
-  }
-
-  protected LocalLock getLocalLock(String lockKey)
-  {
-    LocalLock ll = (LocalLock)localLocks.get(lockKey);
-    if (ll == null)
-    {
-      ll = new LocalLock();
-      localLocks.put(lockKey,ll);
-    }
-    return ll;
-  }
-
-  protected void releaseLocalLock(String lockKey)
-  {
-    localLocks.remove(lockKey);
-  }
-
-  protected LocalLock getLocalSection(String sectionKey)
-  {
-    LocalLock ll = (LocalLock)localSections.get(sectionKey);
-    if (ll == null)
-    {
-      ll = new LocalLock();
-      localSections.put(sectionKey,ll);
-    }
-    return ll;
-  }
-
-  protected void releaseLocalSection(String sectionKey)
-  {
-    localSections.remove(sectionKey);
-  }
-
-  /** Process inbound locks into a sorted vector of most-restrictive unique locks
-  */
-  protected LockDescription[] getSortedUniqueLocks(String[] readLocks, String[] writeNonExLocks,
-    String[] writeLocks)
-  {
-    // First build a unique hash of lock descriptions
-    HashMap ht = new HashMap();
-    int i;
-    if (readLocks != null)
-    {
-      i = 0;
-      while (i < readLocks.length)
-      {
-        String key = readLocks[i++];
-        LockDescription ld = (LockDescription)ht.get(key);
-        if (ld == null)
-        {
-          ld = new LockDescription(TYPE_READ,key);
-          ht.put(key,ld);
-        }
-        else
-          ld.set(TYPE_READ);
-      }
-    }
-    if (writeNonExLocks != null)
-    {
-      i = 0;
-      while (i < writeNonExLocks.length)
-      {
-        String key = writeNonExLocks[i++];
-        LockDescription ld = (LockDescription)ht.get(key);
-        if (ld == null)
-        {
-          ld = new LockDescription(TYPE_WRITENONEX,key);
-          ht.put(key,ld);
-        }
-        else
-          ld.set(TYPE_WRITENONEX);
-      }
-    }
-    if (writeLocks != null)
-    {
-      i = 0;
-      while (i < writeLocks.length)
-      {
-        String key = writeLocks[i++];
-        LockDescription ld = (LockDescription)ht.get(key);
-        if (ld == null)
-        {
-          ld = new LockDescription(TYPE_WRITE,key);
-          ht.put(key,ld);
-        }
-        else
-          ld.set(TYPE_WRITE);
-      }
-    }
-
-    // Now, sort by key name
-    LockDescription[] rval = new LockDescription[ht.size()];
-    String[] sortarray = new String[ht.size()];
-    i = 0;
-    Iterator iter = ht.keySet().iterator();
-    while (iter.hasNext())
-    {
-      String key = (String)iter.next();
-      sortarray[i++] = key;
-    }
-    java.util.Arrays.sort(sortarray);
-    i = 0;
-    while (i < sortarray.length)
-    {
-      rval[i] = (LockDescription)ht.get(sortarray[i]);
-      i++;
-    }
-    return rval;
-  }
-
-  /** Create a file path given a key name.
-  *@param key is the key name.
-  *@return the file path.
-  */
-  protected String makeFilePath(String key)
-  {
-    int hashcode = key.hashCode();
-    int outerDirNumber = (hashcode & (1023));
-    int innerDirNumber = ((hashcode >> 10) & (1023));
-    String fullDir = synchDirectory.toString();
-    if (fullDir.length() == 0 || !fullDir.endsWith("/"))
-      fullDir = fullDir + "/";
-    fullDir = fullDir + Integer.toString(outerDirNumber)+"/"+Integer.toString(innerDirNumber);
-    return fullDir;
-  }
-
-  protected class LockDescription
-  {
-    protected int lockType;
-    protected String lockKey;
-
-    public LockDescription(int lockType, String lockKey)
-    {
-      this.lockType = lockType;
-      this.lockKey = lockKey;
-    }
-
-    public void set(int lockType)
-    {
-      if (lockType > this.lockType)
-        this.lockType = lockType;
-    }
-
-    public int getType()
-    {
-      return lockType;
-    }
-
-    public String getKey()
-    {
-      return lockKey;
-    }
-  }
-
-  protected class LocalLock
-  {
-    private int readCount = 0;
-    private int writeCount = 0;
-    private int nonExWriteCount = 0;
-
-    public LocalLock()
-    {
-    }
-
-    public boolean hasWriteLock()
-    {
-      return (writeCount > 0);
-    }
-
-    public boolean hasReadLock()
-    {
-      return (readCount > 0);
-    }
-
-    public boolean hasNonExWriteLock()
-    {
-      return (nonExWriteCount > 0);
-    }
-
-    public void incrementReadLocks()
-    {
-      readCount++;
-    }
-
-    public void incrementNonExWriteLocks()
-    {
-      nonExWriteCount++;
-    }
-
-    public void incrementWriteLocks()
-    {
-      writeCount++;
-    }
-
-    public void decrementReadLocks()
-    {
-      readCount--;
-    }
-
-    public void decrementNonExWriteLocks()
-    {
-      nonExWriteCount--;
-    }
-
-    public void decrementWriteLocks()
-    {
-      writeCount--;
-    }
-  }
-  
-  protected static final int BASE_SIZE = 128;
-  
-  protected static class ByteArrayBuffer
-  {
-    protected byte[] buffer;
-    protected int length;
-    
-    public ByteArrayBuffer()
-    {
-      buffer = new byte[BASE_SIZE];
-      length = 0;
-    }
-    
-    public void add(byte b)
-    {
-      if (length == buffer.length)
-      {
-        byte[] oldbuffer = buffer;
-        buffer = new byte[length * 2];
-        System.arraycopy(oldbuffer,0,buffer,0,length);
-      }
-      buffer[length++] = b;
-    }
-    
-    public byte[] toArray()
-    {
-      byte[] rval = new byte[length];
-      System.arraycopy(buffer,0,rval,0,length);
-      return rval;
-    }
+    lockManager.leaveCriticalSections(readSectionKeys, nonExSectionKeys, writeSectionKeys);
   }
 
 }

Modified: manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/LockObject.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/LockObject.java?rev=1540056&r1=1540055&r2=1540056&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/LockObject.java (original)
+++ manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/LockObject.java Fri Nov  8 14:44:19 2013
@@ -29,8 +29,9 @@ public class LockObject
 {
   public static final String _rcsid = "@(#)$Id: LockObject.java 988245 2010-08-23 18:39:35Z kwright $";
 
+  protected Object lockKey;
+
   private LockPool lockPool;
-  private Object lockKey;
   private boolean obtainedWrite = false;  // Set to true if this object already owns the permission to exclusively write
   private int obtainedRead = 0;           // Set to a count if this object already owns the permission to read
   private int obtainedNonExWrite = 0;     // Set to a count if this object already owns the permission to non-exclusively write
@@ -54,7 +55,7 @@ public class LockObject
   * first time for a given thread.
   */
   public void enterWriteLock()
-    throws InterruptedException, ExpiredObjectException
+    throws ManifoldCFException, InterruptedException, ExpiredObjectException
   {
     while (true)
     {
@@ -95,7 +96,7 @@ public class LockObject
   * exclusive write area.
   */
   public synchronized void enterWriteLockNoWait()
-    throws LockException, LocalLockException, InterruptedException, ExpiredObjectException
+    throws ManifoldCFException, LockException, LocalLockException, InterruptedException, ExpiredObjectException
   {
     if (lockPool == null)
       throw new ExpiredObjectException("Invalid");
@@ -112,13 +113,13 @@ public class LockObject
   }
 
   protected void obtainGlobalWriteLock()
-    throws LockException, InterruptedException
+    throws ManifoldCFException, LockException, InterruptedException
   {
   }
   
 
   public void leaveWriteLock()
-    throws InterruptedException, ExpiredObjectException
+    throws ManifoldCFException, InterruptedException, ExpiredObjectException
   {
     while (true)
     {
@@ -169,12 +170,12 @@ public class LockObject
   }
 
   protected void clearGlobalWriteLock()
-    throws LockException, InterruptedException
+    throws ManifoldCFException, LockException, InterruptedException
   {
   }
   
   public void enterNonExWriteLock()
-    throws InterruptedException, ExpiredObjectException
+    throws ManifoldCFException, InterruptedException, ExpiredObjectException
   {
     while (true)
     {
@@ -216,7 +217,7 @@ public class LockObject
   * exclusive write area.
   */
   public synchronized void enterNonExWriteLockNoWait()
-    throws LockException, LocalLockException, InterruptedException, ExpiredObjectException
+    throws ManifoldCFException, LockException, LocalLockException, InterruptedException, ExpiredObjectException
   {
     if (lockPool == null)
       throw new ExpiredObjectException("Invalid");
@@ -230,18 +231,18 @@ public class LockObject
       obtainedNonExWrite++;
       return;
     }
-    enterGlobalNonExWriteLock();
+    obtainGlobalNonExWriteLock();
     obtainedNonExWrite++;
   }
 
-  protected void enterGlobalNonExWriteLock()
-    throws LockException, InterruptedException
+  protected void obtainGlobalNonExWriteLock()
+    throws ManifoldCFException, LockException, InterruptedException
   {
   }
   
 
   public void leaveNonExWriteLock()
-    throws InterruptedException, ExpiredObjectException
+    throws ManifoldCFException, InterruptedException, ExpiredObjectException
   {
     // System.out.println("Releasing non-ex-write lock for resource "+lockFileName.toString());
     while (true)
@@ -261,7 +262,7 @@ public class LockObject
 
           try
           {
-            leaveGlobalNonExWriteLock();
+            clearGlobalNonExWriteLock();
           }
           catch (LockException le)
           {
@@ -295,14 +296,14 @@ public class LockObject
     // System.out.println("Non-ex Write lock released for resource "+lockFileName.toString());
   }
 
-  protected void leaveGlobalNonExWriteLock()
-    throws LockException, InterruptedException
+  protected void clearGlobalNonExWriteLock()
+    throws ManifoldCFException, LockException, InterruptedException
   {
   }
   
 
   public void enterReadLock()
-    throws InterruptedException, ExpiredObjectException
+    throws ManifoldCFException, InterruptedException, ExpiredObjectException
   {
     // if (lockFileName != null)
     //      System.out.println("Entering read lock for resource "+lockFileName.toString()+" "+toString());
@@ -340,7 +341,7 @@ public class LockObject
   }
 
   public synchronized void enterReadLockNoWait()
-    throws LockException, LocalLockException, InterruptedException, ExpiredObjectException
+    throws ManifoldCFException, LockException, LocalLockException, InterruptedException, ExpiredObjectException
   {
     if (lockPool == null)
       throw new ExpiredObjectException("Invalid");
@@ -353,19 +354,19 @@ public class LockObject
       return;
     }
     // Got the read token locally!
-    enterGlobalReadLock();
+    obtainGlobalReadLock();
 
     obtainedRead = 1;
   }
 
-  protected void enterGlobalReadLock()
-    throws LockException, InterruptedException
+  protected void obtainGlobalReadLock()
+    throws ManifoldCFException, LockException, InterruptedException
   {
   }
   
 
   public void leaveReadLock()
-    throws InterruptedException, ExpiredObjectException
+    throws ManifoldCFException, InterruptedException, ExpiredObjectException
   {
     while (true)
     {
@@ -385,7 +386,7 @@ public class LockObject
           }
           try
           {
-            leaveGlobalReadLock();
+            clearGlobalReadLock();
           }
           catch (LockException le)
           {
@@ -418,8 +419,8 @@ public class LockObject
     }
   }
 
-  protected void leaveGlobalReadLock()
-    throws LockException, InterruptedException
+  protected void clearGlobalReadLock()
+    throws ManifoldCFException, LockException, InterruptedException
   {
   }
   

Modified: manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperConnection.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperConnection.java?rev=1540056&r1=1540055&r2=1540056&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperConnection.java (original)
+++ manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperConnection.java Fri Nov  8 14:44:19 2013
@@ -42,35 +42,165 @@ public class ZooKeeperConnection
 
   /** Constructor. */
   public ZooKeeperConnection(String connectString, int sessionTimeout)
-    throws ManifoldCFException
+    throws ManifoldCFException, InterruptedException
   {
     try
     {
       zookeeperWatcher = new ZooKeeperWatcher();
       zookeeper = new ZooKeeper(connectString, sessionTimeout, zookeeperWatcher);
     }
+    catch (InterruptedIOException e)
+    {
+      throw new InterruptedException(e.getMessage());
+    }
     catch (IOException e)
     {
       throw new ManifoldCFException("Zookeeper initialization error: "+e.getMessage(),e);
     }
   }
 
-  // MHL
+  public void obtainGlobalWriteLock(String lockPath)
+    throws ManifoldCFException, LockException, InterruptedException
+  {
+    /*
+      1. Call create( ) to create a node with pathname "guid-/write-". This is the lock node
+         spoken of later in the protocol. Make sure to set both sequence and ephemeral flags.
+         If a recoverable error occurs calling create() the client should call getChildren() and
+         check for a node containing the guid used in the path name. This handles the case
+         (noted above) of the create() succeeding on the server but the server crashing before
+         returning the name of the new node.
+    */
+
+    /*
+      2. Call getChildren( ) on the lock node without setting the watch flag - this is important,
+         as it avoids the herd effect.
+    */
+
+    /*
+      3. If there are no children with a lower sequence number than the node created in step
+         1, the client has the lock and the client exits the protocol.
+    */
+
+    /*
+      4. Call exists( ), with watch flag set, on the node with the pathname that has the next
+         lowest sequence number.
+    */
+
+    /* 5. If exists( ) returns false, goto step 2. Otherwise, wait for a notification for the
+         pathname from the previous step before going to step 2.
+    */
+
+    // MHL
+  }
+  
+  public void clearGlobalWriteLock(String lockPath)
+    throws ManifoldCFException, LockException, InterruptedException
+  {
+    /*
+      Delete the node we created in step 1 above.
+    */
+    // MHL
+  }
+
+  public void obtainGlobalNonExWriteLock(String lockPath)
+    throws ManifoldCFException, LockException, InterruptedException
+  {
+    // MHL
+  }
+
+  public void clearGlobalNonExWriteLock(String lockPath)
+    throws ManifoldCFException, LockException, InterruptedException
+  {
+    // MHL
+  }
+  
+  public void obtainGlobalReadLock(String lockPath)
+    throws ManifoldCFException, LockException, InterruptedException
+  {
+    /*
+      1. Call create( ) to create a node with pathname "guid-/read-". This is the lock node use later in the
+         protocol. Make sure to set both the sequence and ephemeral flags.
+         If a recoverable error occurs calling create() the client should call getChildren() and
+         check for a node containing the guid used in the path name. This handles the case
+         (noted above) of the create() succeeding on the server but the server crashing before
+         returning the name of the new node.
+    */
+
+    /*
+      2. Call getChildren( ) on the lock node without setting the watch flag - this is important, as it
+         avoids the herd effect.
+    */
+
+    /*
+      3. If there are no children with a pathname starting with "write-" and having a lower
+         sequence number than the node created in step 1, the client has the lock and can exit the protocol.
+    */
+
+    /*
+      4. Otherwise, call exists( ), with watch flag, set on the node in lock directory with pathname
+         staring with "write-" having the next lowest sequence number.
+    */
+
+    /*
+      5. If exists( ) returns false, goto step 2.
+    */
+
+    /*
+      6. Otherwise, wait for a notification for the pathname from the previous step before going to step 2
+    */
+
+    // MHL
+
+  }
+  
+ public void clearGlobalReadLock(String lockPath)
+    throws ManifoldCFException, LockException, InterruptedException
+  {
+    /*
+      Delete the node we created in step 1 above.
+    */
+    // MHL
+  }
+
+  public byte[] readData(String resourcePath)
+    throws ManifoldCFException, InterruptedException
+  {
+    // MHL
+    return null;
+  }
+  
+  public void writeData(String resourcePath, byte[] data)
+    throws ManifoldCFException, InterruptedException
+  {
+    // MHL
+  }
+
+  public void setGlobalFlag(String flagPath)
+    throws ManifoldCFException, InterruptedException
+  {
+    // MHL
+  }
+
+  public void clearGlobalFlag(String flagPath)
+    throws ManifoldCFException, InterruptedException
+  {
+    // MHL
+  }
+  
+  public boolean checkGlobalFlag(String flagPath)
+    throws ManifoldCFException, InterruptedException
+  {
+    // MHL
+    return false;
+  }
   
   /** Close this connection. */
   public void close()
-    throws ManifoldCFException
+    throws InterruptedException
   {
-    try
-    {
-      zookeeper.close();
-      zookeeper = null;
-      zookeeperWatcher = null;
-    }
-    catch (InterruptedException e)
-    {
-      throw new ManifoldCFException(e.getMessage(),e,ManifoldCFException.INTERRUPTED);
-    }
+    zookeeper.close();
+    zookeeper = null;
+    zookeeperWatcher = null;
   }
   
   /** Watcher class for zookeeper, so we get notified about zookeeper events. */

Added: manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperConnectionPool.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperConnectionPool.java?rev=1540056&view=auto
==============================================================================
--- manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperConnectionPool.java (added)
+++ manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperConnectionPool.java Fri Nov  8 14:44:19 2013
@@ -0,0 +1,65 @@
+/* $Id$ */
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.manifoldcf.core.lockmanager;
+
+import org.apache.manifoldcf.core.interfaces.*;
+import java.util.*;
+import java.io.*;
+
+/** Pool of ZooKeeper connections.
+* ZooKeeper connections are not trivial to set up and each one carries a cost.  Plus,
+* if we want to shut them all down on exit we need them all in one place.
+*/
+public class ZooKeeperConnectionPool
+{
+  public static final String _rcsid = "@(#)$Id$";
+
+  protected final String connectString;
+  protected final int sessionTimeout;
+  
+  protected final List<ZooKeeperConnection> openConnectionList = new ArrayList<ZooKeeperConnection>();
+  
+  public ZooKeeperConnectionPool(String connectString, int sessionTimeout)
+  {
+    this.connectString = connectString;
+    this.sessionTimeout = sessionTimeout;
+  }
+  
+  public synchronized ZooKeeperConnection grab()
+    throws ManifoldCFException, InterruptedException
+  {
+    if (openConnectionList.size() == 0)
+      openConnectionList.add(new ZooKeeperConnection(connectString, sessionTimeout));
+    return openConnectionList.remove(openConnectionList.size()-1);
+  }
+
+  public synchronized void release(ZooKeeperConnection connection)
+  {
+    openConnectionList.add(connection);
+  }
+  
+  public synchronized void closeAll()
+    throws InterruptedException
+  {
+    for (ZooKeeperConnection c : openConnectionList)
+    {
+      c.close();
+    }
+  }
+}

Propchange: manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperConnectionPool.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperConnectionPool.java
------------------------------------------------------------------------------
    svn:keywords = Id



Mime
View raw message