manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1560685 - in /manifoldcf/branches/CONNECTORS-867/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager: ZooKeeperConnection.java ZooKeeperLockObject.java
Date Thu, 23 Jan 2014 13:46:54 GMT
Author: kwright
Date: Thu Jan 23 13:46:54 2014
New Revision: 1560685

URL: http://svn.apache.org/r1560685
Log:
Add calling infrastructure for ZooKeeper blocking locks

Modified:
    manifoldcf/branches/CONNECTORS-867/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperConnection.java
    manifoldcf/branches/CONNECTORS-867/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperLockObject.java

Modified: manifoldcf/branches/CONNECTORS-867/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperConnection.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-867/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperConnection.java?rev=1560685&r1=1560684&r2=1560685&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-867/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperConnection.java
(original)
+++ manifoldcf/branches/CONNECTORS-867/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperConnection.java
Thu Jan 23 13:46:54 2014
@@ -282,6 +282,21 @@ public class ZooKeeperConnection
     }
   }
   
+  /** Obtain a write lock, with wait.
+  *@param lockPath is the lock node path.
+  */
+  public void obtainWriteLock(String lockPath)
+    throws ManifoldCFException, InterruptedException
+  {
+    // MHL to do this the proper ZooKeeper way
+    while (true)
+    {
+      if (obtainWriteLockNoWait(lockPath))
+        return;
+      ManifoldCF.sleep(10L);
+    }
+  }
+
   /** Obtain a non-ex-write lock, with no wait.
   *@param lockPath is the lock node path.
   *@return true if the lock was obtained, false otherwise.
@@ -325,6 +340,21 @@ public class ZooKeeperConnection
     }
   }
 
+  /** Obtain a non-ex-write lock, with wait.
+  *@param lockPath is the lock node path.
+  */
+  public void obtainNonExWriteLock(String lockPath)
+    throws ManifoldCFException, InterruptedException
+  {
+    // MHL to do this the proper ZooKeeper way
+    while (true)
+    {
+      if (obtainNonExWriteLockNoWait(lockPath))
+        return;
+      ManifoldCF.sleep(10L);
+    }
+  }
+
   /** Obtain a read lock, with no wait.
   *@param lockPath is the lock node path.
   *@return true if the lock was obtained, false otherwise.
@@ -368,6 +398,21 @@ public class ZooKeeperConnection
     }
   }
   
+  /** Obtain a read lock, with wait.
+  *@param lockPath is the lock node path.
+  */
+  public void obtainReadLock(String lockPath)
+    throws ManifoldCFException, InterruptedException
+  {
+    // MHL to do this the proper ZooKeeper way
+    while (true)
+    {
+      if (obtainReadLockNoWait(lockPath))
+        return;
+      ManifoldCF.sleep(10L);
+    }
+  }
+  
   /** Release the (saved) lock.
   */
   public void releaseLock()

Modified: manifoldcf/branches/CONNECTORS-867/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperLockObject.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-867/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperLockObject.java?rev=1560685&r1=1560684&r2=1560685&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-867/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperLockObject.java
(original)
+++ manifoldcf/branches/CONNECTORS-867/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperLockObject.java
Thu Jan 23 13:46:54 2014
@@ -69,6 +69,29 @@ public class ZooKeeperLockObject extends
   }
 
   @Override
+  protected void obtainGlobalWriteLock()
+    throws ManifoldCFException, InterruptedException
+  {
+    if (currentConnection != null)
+      throw new IllegalStateException("Already have a connection before write locking: "+lockPath);
+    boolean succeeded = false;
+    currentConnection = pool.grab();
+    try
+    {
+      currentConnection.obtainWriteLock(lockPath);
+      succeeded = true;
+    }
+    finally
+    {
+      if (!succeeded)
+      {
+        pool.release(currentConnection);
+        currentConnection = null;
+      }
+    }
+  }
+
+  @Override
   protected void clearGlobalWriteLockNoWait()
     throws ManifoldCFException, LockException, InterruptedException
   {
@@ -102,6 +125,29 @@ public class ZooKeeperLockObject extends
   }
 
   @Override
+  protected void obtainGlobalNonExWriteLock()
+    throws ManifoldCFException, InterruptedException
+  {
+    if (currentConnection != null)
+      throw new IllegalStateException("Already have a connection before non-ex-write locking:
"+lockPath);
+    boolean succeeded = false;
+    currentConnection = pool.grab();
+    try
+    {
+      currentConnection.obtainNonExWriteLock(lockPath);
+      succeeded = true;
+    }
+    finally
+    {
+      if (!succeeded)
+      {
+        pool.release(currentConnection);
+        currentConnection = null;
+      }
+    }
+  }
+
+  @Override
   protected void clearGlobalNonExWriteLockNoWait()
     throws ManifoldCFException, LockException, InterruptedException
   {
@@ -135,6 +181,29 @@ public class ZooKeeperLockObject extends
   }
 
   @Override
+  protected void obtainGlobalReadLock()
+    throws ManifoldCFException, InterruptedException
+  {
+    if (currentConnection != null)
+      throw new IllegalStateException("Already have a connection before read locking: "+lockPath);
+    boolean succeeded = false;
+    currentConnection = pool.grab();
+    try
+    {
+      currentConnection.obtainReadLock(lockPath);
+      succeeded = true;
+    }
+    finally
+    {
+      if (!succeeded)
+      {
+        pool.release(currentConnection);
+        currentConnection = null;
+      }
+    }
+  }
+
+  @Override
   protected void clearGlobalReadLockNoWait()
     throws ManifoldCFException, LockException, InterruptedException
   {



Mime
View raw message