commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ozeigerm...@apache.org
Subject svn commit: r560618 - in /jakarta/commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/locking: HierarchicalLockManager.java HierarchicalRWLockManager.java
Date Sat, 28 Jul 2007 21:31:45 GMT
Author: ozeigermann
Date: Sat Jul 28 14:31:44 2007
New Revision: 560618

URL: http://svn.apache.org/viewvc?view=rev&rev=560618
Log:
Established first version of a hierarchical lock manager

Modified:
    jakarta/commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/locking/HierarchicalLockManager.java
    jakarta/commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/locking/HierarchicalRWLockManager.java

Modified: jakarta/commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/locking/HierarchicalLockManager.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/locking/HierarchicalLockManager.java?view=diff&rev=560618&r1=560617&r2=560618
==============================================================================
--- jakarta/commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/locking/HierarchicalLockManager.java
(original)
+++ jakarta/commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/locking/HierarchicalLockManager.java
Sat Jul 28 14:31:44 2007
@@ -16,9 +16,8 @@
  */
 package org.apache.commons.transaction.locking;
 
-
 // Takes care of hierarchical locking with folders and resources
-public interface HierarchicalLockManager<M> extends LockManager<String, M> {
-    public void lockAsFolder(String path, boolean exclusive) throws LockException;
-    public void lockAsResource(String path, boolean exclusive) throws LockException;
+public interface HierarchicalLockManager<K, M> extends LockManager<K, M> {
+    
+    public void lockInHierarchy(M managedResource, String path, boolean exclusive) throws
LockException;
 }

Modified: jakarta/commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/locking/HierarchicalRWLockManager.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/locking/HierarchicalRWLockManager.java?view=diff&rev=560618&r1=560617&r2=560618
==============================================================================
--- jakarta/commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/locking/HierarchicalRWLockManager.java
(original)
+++ jakarta/commons/proper/transaction/branches/TRANSACTION_2/src/java/org/apache/commons/transaction/locking/HierarchicalRWLockManager.java
Sat Jul 28 14:31:44 2007
@@ -16,16 +16,69 @@
  */
 package org.apache.commons.transaction.locking;
 
-public class HierarchicalRWLockManager<M> extends RWLockManager<String, M> implements
-        HierarchicalLockManager<M> {
+import java.util.concurrent.TimeUnit;
+
+public class HierarchicalRWLockManager<M> implements HierarchicalLockManager<Object,
M> {
+
+    private final String rootPath;
+
+    private final LockManager<Object, M> lm;
+
+    public HierarchicalRWLockManager(String rootPath, LockManager<Object, M> lm) {
+        this.rootPath = rootPath;
+        this.lm = lm;
+    }
+
+    public void lockInHierarchy(M managedResource, String path, boolean exclusive)
+            throws LockException {
+        // strip off root path
+        // TODO misses sane checks
+        String relativePath = path.substring(path.indexOf(rootPath));
+
+        // this is the root path we want to lock
+        if (relativePath.length() == 0) {
+            lock(managedResource, "/", exclusive);
+            return;
+        }
+
+        // always read lock root
+        lock(managedResource, "/", false);
+
+        String[] segments = relativePath.split("/");
+        StringBuffer currentPath = new StringBuffer(relativePath.length());
+        // for root path
+        currentPath.append('/');
+
+        for (int i = 0; i < segments.length; i++) {
+            String segment = segments[i];
+
+            currentPath.append(segment).append('/');
+            String key = currentPath.toString();
+
+            if (i == segments.length - 1) {
+                // this is the resource itself
+                lock(managedResource, key, exclusive);
+            } else {
+                // this is one of the parent path segments
+                lock(managedResource, key, false);
+            }
+        }
+    }
+
+    public void endWork() {
+        lm.endWork();
+    }
+
+    public void lock(M managedResource, Object key, boolean exclusive) throws LockException
{
+        lm.lock(managedResource, key, exclusive);
+    }
+
+    public void startWork(long timeout, TimeUnit unit) {
+        lm.startWork(timeout, unit);
 
-    public void lockAsFolder(String path, boolean exclusive) throws LockException {
-        // TODO Auto-generated method stub
-        
     }
 
-    public void lockAsResource(String path, boolean exclusive) throws LockException {
-        // TODO Auto-generated method stub
-        
+    public boolean tryLock(M managedResource, Object key, boolean exclusive) {
+        return lm.tryLock(managedResource, key, exclusive);
     }
 }



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


Mime
View raw message