Author: jukka
Date: Wed Aug 14 09:51:32 2013
New Revision: 1513790
URL: http://svn.apache.org/r1513790
Log:
OAK-150: Basic JCR LockManager support
More LockManagerImpl improvements.
Modified:
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockManagerImpl.java
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=1513790&r1=1513789&r2=1513790&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 14 09:51:32 2013
@@ -16,8 +16,8 @@
*/
package org.apache.jackrabbit.oak.jcr.lock;
-import java.util.Arrays;
-import java.util.HashSet;
+import static com.google.common.collect.Sets.newTreeSet;
+
import java.util.Set;
import javax.annotation.Nonnull;
@@ -45,7 +45,7 @@ public class LockManagerImpl implements
private final SessionDelegate delegate;
- private final Set<String> tokens = new HashSet<String>();
+ private final Set<String> tokens = newTreeSet();
public LockManagerImpl(SessionContext sessionContext) {
this.sessionContext = sessionContext;
@@ -53,19 +53,18 @@ public class LockManagerImpl implements
}
@Override
- public String[] getLockTokens() throws RepositoryException {
- String[] array = tokens.toArray(new String[tokens.size()]);
- Arrays.sort(array);
- return array;
+ public synchronized String[] getLockTokens() {
+ return tokens.toArray(new String[tokens.size()]);
}
@Override
- public void addLockToken(String lockToken) throws RepositoryException {
+ public synchronized void addLockToken(String lockToken) {
tokens.add(lockToken);
}
@Override
- public void removeLockToken(String lockToken) throws RepositoryException {
+ public synchronized void removeLockToken(String lockToken)
+ throws LockException {
if (!tokens.remove(lockToken)) {
throw new LockException(
"Lock token " + lockToken + " is not held by this
session");
@@ -74,40 +73,30 @@ public class LockManagerImpl implements
@Override
public boolean isLocked(String absPath) throws RepositoryException {
- final String path = sessionContext.getOakPathOrThrowNotFound(absPath);
- return delegate.perform(new SessionOperation<Boolean>() {
- @Override public Boolean perform() throws RepositoryException {
- NodeDelegate node = delegate.getNode(path);
- if (node != null) {
- return node.isLocked();
- } else {
- throw new PathNotFoundException(
- "Node " + path + " does not exist");
- }
+ return perform(new LockOperation<Boolean>(absPath) {
+ @Override
+ protected Boolean perform(NodeDelegate node) {
+ return node.isLocked();
}
});
}
@Override
- @SuppressWarnings("deprecation")
public boolean holdsLock(String absPath) throws RepositoryException {
- return getSession().getNode(absPath).holdsLock();
+ return perform(new LockOperation<Boolean>(absPath) {
+ @Override
+ protected Boolean perform(NodeDelegate node) {
+ return node.holdsLock(false);
+ }
+ });
}
@Override
public Lock getLock(String absPath) throws RepositoryException {
- final String oakPath =
- sessionContext.getOakPathOrThrowNotFound(absPath);
- NodeDelegate lock = perform(new SessionOperation<NodeDelegate>() {
+ NodeDelegate lock = perform(new LockOperation<NodeDelegate>(absPath) {
@Override
- public NodeDelegate perform() throws RepositoryException {
- NodeDelegate node = delegate.getNode(oakPath);
- if (node != null) {
- return node.getLock();
- } else {
- throw new PathNotFoundException(
- "Node " + oakPath + " not found");
- }
+ protected NodeDelegate perform(NodeDelegate node) {
+ return node.getLock();
}
});
if (lock != null) {
@@ -141,4 +130,27 @@ public class LockManagerImpl implements
return delegate.perform(operation);
}
+ private abstract class LockOperation<T> extends SessionOperation<T> {
+
+ private final String path;
+
+ public LockOperation(String absPath) throws PathNotFoundException {
+ this.path = sessionContext.getOakPathOrThrowNotFound(absPath);
+ }
+
+ @Override
+ public T perform() throws RepositoryException {
+ NodeDelegate node = delegate.getNode(path);
+ if (node != null) {
+ return perform(node);
+ } else {
+ throw new PathNotFoundException(
+ "Node " + path + " not found");
+ }
+ }
+
+ protected abstract T perform(NodeDelegate node);
+
+ }
+
}
\ No newline at end of file