jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1518066 - in /jackrabbit/oak/trunk/oak-jcr: ./ src/main/java/org/apache/jackrabbit/oak/jcr/ src/main/java/org/apache/jackrabbit/oak/jcr/lock/
Date Wed, 28 Aug 2013 04:05:58 GMT
Author: jukka
Date: Wed Aug 28 04:05:58 2013
New Revision: 1518066

URL: http://svn.apache.org/r1518066
Log:
OAK-150: Basic JCR LockManager support

Simplify cleanup of session-scoped locks
Further trimming of the known issue list

Modified:
    jackrabbit/oak/trunk/oak-jcr/pom.xml
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionContext.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockManagerImpl.java

Modified: jackrabbit/oak/trunk/oak-jcr/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/pom.xml?rev=1518066&r1=1518065&r2=1518066&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-jcr/pom.xml Wed Aug 28 04:05:58 2013
@@ -66,7 +66,7 @@
       org.apache.jackrabbit.test.api.DocumentViewImportTest#testWorkspaceImportXml      
              <!-- OAK-970 -->
       org.apache.jackrabbit.test.api.DocumentViewImportTest#testSessionGetImportContentHandler
        <!-- OAK-970 -->
 
-      <!-- Locking : not implemented -->
+      <!-- Locking : not fully implemented -->
       org.apache.jackrabbit.test.api.SerializationTest#testLockExceptionWorkspaceWithHandler
          <!-- OAK-127: no session scoped locking -->
       org.apache.jackrabbit.test.api.SerializationTest#testLockExceptionSessionWithHandler
            <!-- OAK-127: no session scoped locking -->
       org.apache.jackrabbit.test.api.SerializationTest#testLockExceptionWorkspace       
              <!-- OAK-127: no session scoped locking -->
@@ -76,11 +76,8 @@
       org.apache.jackrabbit.test.api.lock.LockTest#testParentChildDeepLock
       org.apache.jackrabbit.test.api.lock.LockTest#testIsSessionScoped
       org.apache.jackrabbit.test.api.lock.LockTest#testLockTransfer
-      org.apache.jackrabbit.test.api.lock.LockTest#testRefreshNotLive
       org.apache.jackrabbit.test.api.lock.LockTest#testAddRemoveLockToken
-      org.apache.jackrabbit.test.api.lock.LockTest#testCheckedIn
       org.apache.jackrabbit.test.api.lock.LockTest#testOpenScopedLocks
-      org.apache.jackrabbit.test.api.lock.LockTest#testCheckedInUnlock
       org.apache.jackrabbit.test.api.lock.LockTest#testLogout
 
       org.apache.jackrabbit.test.api.lock.SetValueLockExceptionTest#testSetValueLockException
@@ -89,35 +86,12 @@
       org.apache.jackrabbit.test.api.lock.DeepLockTest#testParentChildDeepLock
       org.apache.jackrabbit.test.api.lock.DeepLockTest#testDeepLockAboveLockedChild
       org.apache.jackrabbit.test.api.lock.DeepLockTest#testRemoveLockedChild
-      org.apache.jackrabbit.test.api.lock.DeepLockTest#testIsSessionScoped
-      org.apache.jackrabbit.test.api.lock.DeepLockTest#testRefreshNotLive
-      org.apache.jackrabbit.test.api.lock.DeepLockTest#testIsLockOwningSession
-      org.apache.jackrabbit.test.api.lock.DeepLockTest#testUnlockByOtherSession
-      org.apache.jackrabbit.test.api.lock.DeepLockTest#testGetSecondsRemainingAfterUnlock
 
-      org.apache.jackrabbit.test.api.lock.LockManagerTest#testLockTransfer
       org.apache.jackrabbit.test.api.lock.LockManagerTest#testLockTransfer2
-      org.apache.jackrabbit.test.api.lock.LockManagerTest#testLockTransfer3
-      org.apache.jackrabbit.test.api.lock.LockManagerTest#testRemoveLockToken
-      org.apache.jackrabbit.test.api.lock.LockManagerTest#testRemoveLockToken2
       org.apache.jackrabbit.test.api.lock.LockManagerTest#testRemoveLockToken3
       org.apache.jackrabbit.test.api.lock.LockManagerTest#testLockWithPendingChanges
-      org.apache.jackrabbit.test.api.lock.LockManagerTest#testGetLockTokens
-      org.apache.jackrabbit.test.api.lock.LockManagerTest#testRemoveLockTokenTwice
-      org.apache.jackrabbit.test.api.lock.LockManagerTest#testAddLockTokenAgain
       org.apache.jackrabbit.test.api.lock.LockManagerTest#testAddLockTokenToAnotherSession
 
-      org.apache.jackrabbit.test.api.lock.OpenScopedLockTest#testGetLockToken
-      org.apache.jackrabbit.test.api.lock.OpenScopedLockTest#testRefreshNotLive
-      org.apache.jackrabbit.test.api.lock.OpenScopedLockTest#testIsLockOwningSession
-      org.apache.jackrabbit.test.api.lock.OpenScopedLockTest#testUnlockByOtherSession
-      org.apache.jackrabbit.test.api.lock.OpenScopedLockTest#testGetSecondsRemainingAfterUnlock
-
-      org.apache.jackrabbit.test.api.lock.SessionScopedLockTest#testIsSessionScoped
-      org.apache.jackrabbit.test.api.lock.SessionScopedLockTest#testRefreshNotLive
-      org.apache.jackrabbit.test.api.lock.SessionScopedLockTest#testIsLockOwningSession
-      org.apache.jackrabbit.test.api.lock.SessionScopedLockTest#testUnlockByOtherSession
-      org.apache.jackrabbit.test.api.lock.SessionScopedLockTest#testGetSecondsRemainingAfterUnlock
       org.apache.jackrabbit.test.api.lock.SessionScopedLockTest#testImplicitUnlock
       org.apache.jackrabbit.test.api.lock.SessionScopedLockTest#testImplicitUnlock2
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionContext.java?rev=1518066&r1=1518065&r2=1518066&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionContext.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionContext.java
Wed Aug 28 04:05:58 2013
@@ -21,6 +21,7 @@ import static com.google.common.collect.
 import static com.google.common.collect.Sets.newTreeSet;
 
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -44,11 +45,13 @@ import org.apache.jackrabbit.api.securit
 import org.apache.jackrabbit.oak.api.ContentSession;
 import org.apache.jackrabbit.oak.jcr.delegate.AccessControlManagerDelegator;
 import org.apache.jackrabbit.oak.jcr.delegate.JackrabbitAccessControlManagerDelegator;
+import org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate;
 import org.apache.jackrabbit.oak.jcr.delegate.PrincipalManagerDelegator;
 import org.apache.jackrabbit.oak.jcr.delegate.PrivilegeManagerDelegator;
 import org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate;
 import org.apache.jackrabbit.oak.jcr.delegate.UserManagerDelegator;
 import org.apache.jackrabbit.oak.jcr.observation.ObservationManagerImpl;
+import org.apache.jackrabbit.oak.jcr.operation.SessionOperation;
 import org.apache.jackrabbit.oak.jcr.security.AccessManager;
 import org.apache.jackrabbit.oak.namepath.LocalNameMapper;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
@@ -65,6 +68,8 @@ import org.apache.jackrabbit.oak.spi.sec
 import org.apache.jackrabbit.oak.spi.security.user.UserConfiguration;
 import org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard;
 import org.apache.jackrabbit.oak.spi.xml.ProtectedItemImporter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Instances of this class are passed to all JCR implementation classes
@@ -74,6 +79,10 @@ import org.apache.jackrabbit.oak.spi.xml
  */
 public class SessionContext implements NamePathMapper {
 
+    /** Logger instance */
+    private static final Logger log =
+            LoggerFactory.getLogger(SessionContext.class);
+
     private final RepositoryImpl repository;
     private final Whiteboard whiteboard;
     private final Map<String, Object> attributes;
@@ -352,13 +361,45 @@ public class SessionContext implements N
     //-----------------------------------------------------------< internal >---
 
     void dispose() {
-        getWorkspace().getLockManager().unlockAllSessionScopedLocks();
+        try {
+            unlockAllSessionScopedLocks();
+        } catch (RepositoryException e) {
+            throw new RuntimeException("Unexpected repository error", e);
+        }
         if (observationManager != null) {
             observationManager.dispose();
         }
         namespaces.clear();
     }
 
+    /**
+     * Unlocks all existing session-scoped locks (if any). Used for cleanup
+     * when a session is being closed.
+     *
+     * @throws RepositoryException if an unexpected problem occurs
+     */
+    // TODO: should this be in SessionImpl?
+    private void unlockAllSessionScopedLocks() throws RepositoryException {
+        delegate.perform(new SessionOperation<Void>() {
+            @Override
+            public Void perform() throws RepositoryException {
+                Iterator<String> iterator = sessionScopedLocks.iterator();
+                while (iterator.hasNext()) {
+                    NodeDelegate node = delegate.getNode(iterator.next());
+                    if (node != null) {
+                        try {
+                            node.unlock(); // TODO: use a single commit
+                        } catch (RepositoryException e) {
+                            log.warn("Failed to unlock a session scoped lock", e);
+                        }
+                    }
+                    iterator.remove();
+                }
+                return null;
+            }
+        });
+    }
+
     @Nonnull
     private <T> T getConfig(Class<T> clss) {
         return repository.getSecurityProvider().getConfiguration(clss);

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java?rev=1518066&r1=1518065&r2=1518066&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
Wed Aug 28 04:05:58 2013
@@ -61,7 +61,6 @@ public class WorkspaceImpl implements Ja
     private final SessionContext sessionContext;
     private final SessionDelegate sessionDelegate;
     private final QueryManagerImpl queryManager;
-    private final LockManagerImpl lockManager;
     private final VersionManagerImpl versionManager;
     private final ReadWriteNodeTypeManager nodeTypeManager;
 
@@ -69,7 +68,6 @@ public class WorkspaceImpl implements Ja
         this.sessionContext = sessionContext;
         this.sessionDelegate = sessionContext.getSessionDelegate();
         this.queryManager = new QueryManagerImpl(sessionContext);
-        this.lockManager = new LockManagerImpl(sessionContext);
         this.versionManager = new VersionManagerImpl(sessionContext);
         this.nodeTypeManager = new ReadWriteNodeTypeManager() {
             @Override
@@ -182,8 +180,8 @@ public class WorkspaceImpl implements Ja
     }
 
     @Override
-    public LockManagerImpl getLockManager() {
-        return lockManager;
+    public LockManager getLockManager() {
+        return new LockManagerImpl(sessionContext);
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockManagerImpl.java?rev=1518066&r1=1518065&r2=1518066&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockManagerImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockManagerImpl.java
Wed Aug 28 04:05:58 2013
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.oak.jcr.lock;
 
-import java.util.Iterator;
 import java.util.Set;
 
 import javax.annotation.Nonnull;
@@ -32,8 +31,6 @@ import org.apache.jackrabbit.oak.jcr.Ses
 import org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate;
 import org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate;
 import org.apache.jackrabbit.oak.jcr.operation.SessionOperation;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * Simple lock manager implementation that just keeps track of a set of lock
@@ -42,10 +39,6 @@ import org.slf4j.LoggerFactory;
  */
 public class LockManagerImpl implements LockManager {
 
-    /** Logger instance */
-    private static final Logger log =
-            LoggerFactory.getLogger(LockManagerImpl.class);
-
     private final SessionContext sessionContext;
 
     private final SessionDelegate delegate;
@@ -187,33 +180,6 @@ public class LockManagerImpl implements 
         });
     }
 
-    public void unlockAllSessionScopedLocks() {
-        try {
-            perform(new SessionOperation<Void>() {
-                @Override
-                public Void perform() throws RepositoryException {
-                    SessionDelegate delegate = sessionContext.getSessionDelegate();
-                    Iterator<String> iterator =
-                            sessionContext.getSessionScopedLocks().iterator();
-                    while (iterator.hasNext()) {
-                        NodeDelegate node = delegate.getNode(iterator.next());
-                        if (node != null) {
-                            try {
-                                node.unlock();
-                            } catch (RepositoryException e) {
-                                log.warn("Failed to clean up a session scoped lock", e);
-                            }
-                        }
-                        iterator.remove();
-                    }
-                    return null;
-                }
-            });
-        } catch (RepositoryException e) {
-            log.warn("Unexpected repository exception", e);
-        }
-    }
-
     private <T> T perform(SessionOperation<T> operation)
             throws RepositoryException {
         return delegate.perform(operation);



Mime
View raw message