You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by an...@apache.org on 2009/03/13 14:45:04 UTC
svn commit: r753248 - in /jackrabbit/sandbox/spi:
client/src/test/java/org/apache/jackrabbit/test/
spi-logger/src/main/java/org/apache/jackrabbit/spi/logger/
spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/client/
spi-rmi/src/main/java/org/apache/j...
Author: angela
Date: Fri Mar 13 13:45:04 2009
New Revision: 753248
URL: http://svn.apache.org/viewvc?rev=753248&view=rev
Log:
JCR-2004 Update SPI locking to match JCR 2.0
- extend spi/LockInfo.java
- add JCR 2.0 variant of RepositoryService#lock that takes timeoutHint and ownerHint
- adjust jcr2spi
- adjust spi implementation(s)
Added:
jackrabbit/sandbox/spi/client/src/test/java/org/apache/jackrabbit/test/TestLock.java (with props)
Modified:
jackrabbit/sandbox/spi/spi-logger/src/main/java/org/apache/jackrabbit/spi/logger/RepositoryServiceLogger.java
jackrabbit/sandbox/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/client/ClientRepositoryService.java
jackrabbit/sandbox/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/remote/RemoteRepositoryService.java
jackrabbit/sandbox/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/server/ServerRepositoryService.java
jackrabbit/sandbox/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/LockInfoImpl.java
jackrabbit/sandbox/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
jackrabbit/sandbox/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/SessionInfoImpl.java
Added: jackrabbit/sandbox/spi/client/src/test/java/org/apache/jackrabbit/test/TestLock.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi/client/src/test/java/org/apache/jackrabbit/test/TestLock.java?rev=753248&view=auto
==============================================================================
--- jackrabbit/sandbox/spi/client/src/test/java/org/apache/jackrabbit/test/TestLock.java (added)
+++ jackrabbit/sandbox/spi/client/src/test/java/org/apache/jackrabbit/test/TestLock.java Fri Mar 13 13:45:04 2009
@@ -0,0 +1,33 @@
+/*
+ * 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.jackrabbit.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * <code>TestObservation</code>...
+ */
+public class TestLock {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite("api lock and jcr2spi lock tests.");
+ suite.addTest(org.apache.jackrabbit.jcr2spi.TestAll.suite());
+ suite.addTest(org.apache.jackrabbit.test.api.lock.TestAll.suite());
+ return suite;
+ }
+}
Propchange: jackrabbit/sandbox/spi/client/src/test/java/org/apache/jackrabbit/test/TestLock.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jackrabbit/sandbox/spi/client/src/test/java/org/apache/jackrabbit/test/TestLock.java
------------------------------------------------------------------------------
svn:keywords = author date id revision url
Modified: jackrabbit/sandbox/spi/spi-logger/src/main/java/org/apache/jackrabbit/spi/logger/RepositoryServiceLogger.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi/spi-logger/src/main/java/org/apache/jackrabbit/spi/logger/RepositoryServiceLogger.java?rev=753248&r1=753247&r2=753248&view=diff
==============================================================================
--- jackrabbit/sandbox/spi/spi-logger/src/main/java/org/apache/jackrabbit/spi/logger/RepositoryServiceLogger.java (original)
+++ jackrabbit/sandbox/spi/spi-logger/src/main/java/org/apache/jackrabbit/spi/logger/RepositoryServiceLogger.java Fri Mar 13 13:45:04 2009
@@ -342,6 +342,18 @@
new Object[]{nodeId, new Boolean(b), new Boolean(b1)});
}
+ public LockInfo lock(final SessionInfo sessionInfo, final NodeId nodeId,
+ final boolean deep, final boolean sessionScoped,
+ final long timeoutHint, final String ownerHint)
+ throws UnsupportedRepositoryOperationException, LockException, AccessDeniedException, RepositoryException {
+ return (LockInfo) execute(new Callable() {
+ public Object call() throws RepositoryException {
+ return service.lock(sessionInfo, nodeId, deep, sessionScoped, timeoutHint, ownerHint);
+ }
+ }, "lock(SessionInfo,NodeId,boolean,boolean,long,String",
+ new Object[]{nodeId, new Boolean(deep), new Boolean(sessionScoped), new Long(timeoutHint), ownerHint});
+ }
+
public void refreshLock(final SessionInfo sessionInfo, final NodeId nodeId)
throws UnsupportedRepositoryOperationException, LockException, AccessDeniedException, RepositoryException {
execute(new Callable() {
Modified: jackrabbit/sandbox/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/client/ClientRepositoryService.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/client/ClientRepositoryService.java?rev=753248&r1=753247&r2=753248&view=diff
==============================================================================
--- jackrabbit/sandbox/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/client/ClientRepositoryService.java (original)
+++ jackrabbit/sandbox/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/client/ClientRepositoryService.java Fri Mar 13 13:45:04 2009
@@ -423,6 +423,15 @@
}
}
+ public LockInfo lock(SessionInfo sessionInfo, NodeId nodeId, boolean deep, boolean sessionScoped, long timeoutHint, String ownerHint) throws UnsupportedRepositoryOperationException, LockException, AccessDeniedException, RepositoryException {
+ try {
+ return remoteService.lock(getRemoteSessionInfo(sessionInfo),
+ nodeId, deep, sessionScoped, timeoutHint, ownerHint);
+ } catch (RemoteException e) {
+ throw new RemoteRepositoryException(e);
+ }
+ }
+
/**
* {@inheritDoc}
*/
Modified: jackrabbit/sandbox/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/remote/RemoteRepositoryService.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/remote/RemoteRepositoryService.java?rev=753248&r1=753247&r2=753248&view=diff
==============================================================================
--- jackrabbit/sandbox/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/remote/RemoteRepositoryService.java (original)
+++ jackrabbit/sandbox/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/remote/RemoteRepositoryService.java Fri Mar 13 13:45:04 2009
@@ -322,6 +322,23 @@
boolean sessionScoped)
throws RepositoryException, RemoteException;
+ /**
+ * @param sessionInfo
+ * @param nodeId
+ * @param deep
+ * @param sessionScoped
+ * @param timeoutHint
+ * @param ownerHint
+ * @return returns the <code>LockInfo</code> associated with this lock.
+ * @throws javax.jcr.RepositoryException
+ * @throws RemoteException if an error occurs.
+ * @see org.apache.jackrabbit.spi.RepositoryService#lock(org.apache.jackrabbit.spi.SessionInfo, org.apache.jackrabbit.spi.NodeId, boolean, boolean, long, String)
+ */
+ public LockInfo lock(RemoteSessionInfo sessionInfo, NodeId nodeId,
+ boolean deep, boolean sessionScoped, long timeoutHint,
+ String ownerHint)
+ throws RepositoryException, RemoteException;
+
/**
* Explicit refresh of an existing lock. Existing locks should be refreshed
* implicitely with all read and write methods listed here.
Modified: jackrabbit/sandbox/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/server/ServerRepositoryService.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/server/ServerRepositoryService.java?rev=753248&r1=753247&r2=753248&view=diff
==============================================================================
--- jackrabbit/sandbox/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/server/ServerRepositoryService.java (original)
+++ jackrabbit/sandbox/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/server/ServerRepositoryService.java Fri Mar 13 13:45:04 2009
@@ -460,6 +460,29 @@
/**
* {@inheritDoc}
*/
+ public LockInfo lock(RemoteSessionInfo sessionInfo, NodeId nodeId, boolean deep, boolean sessionScoped, long timeoutHint, String ownerHint) throws RepositoryException, RemoteException {
+ try {
+ LockInfo lockInfo = service.lock(getSessionInfo(sessionInfo),
+ nodeId, deep, sessionScoped, timeoutHint, ownerHint);
+ if (lockInfo instanceof Serializable) {
+ return lockInfo;
+ } else {
+ NodeId id = lockInfo.getNodeId();
+ return new LockInfoImpl(lockInfo.getLockToken(),
+ lockInfo.getOwner(), lockInfo.isDeep(),
+ lockInfo.isSessionScoped(), lockInfo.getSecondsRemaining(),
+ lockInfo.isLockOwner(),
+ idFactory.createNodeId(id.getUniqueID(), id.getPath()));
+ }
+ } catch (RepositoryException e) {
+ throw getRepositoryException(e);
+ }
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public void refreshLock(RemoteSessionInfo sessionInfo, NodeId nodeId)
throws RepositoryException, RemoteException {
try {
Modified: jackrabbit/sandbox/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/LockInfoImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/LockInfoImpl.java?rev=753248&r1=753247&r2=753248&view=diff
==============================================================================
--- jackrabbit/sandbox/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/LockInfoImpl.java (original)
+++ jackrabbit/sandbox/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/LockInfoImpl.java Fri Mar 13 13:45:04 2009
@@ -17,6 +17,7 @@
import org.apache.jackrabbit.webdav.lock.ActiveLock;
import org.apache.jackrabbit.webdav.jcr.ItemResourceConstants;
+import org.apache.jackrabbit.webdav.DavConstants;
import org.apache.jackrabbit.spi.LockInfo;
import org.apache.jackrabbit.spi.NodeId;
import org.slf4j.LoggerFactory;
@@ -37,8 +38,13 @@
this.nodeId = nodeId;
}
+ ActiveLock getActiveLock() {
+ return activeLock;
+ }
+
+ //-----------------------------------------------------------< LockInfo >---
public String getLockToken() {
- return activeLock.getToken();
+ return (isSessionScoped()) ? null : activeLock.getToken();
}
public String getOwner() {
@@ -53,6 +59,15 @@
return activeLock.getScope() == ItemResourceConstants.EXCLUSIVE_SESSION;
}
+ public long getSecondsRemaining() {
+ long timeout = activeLock.getTimeout();
+ return (timeout == DavConstants.INFINITE_TIMEOUT) ? Long.MAX_VALUE : timeout / 1000;
+ }
+
+ public boolean isLockOwner() {
+ return activeLock.getToken() != null;
+ }
+
public NodeId getNodeId() {
return nodeId;
}
Modified: jackrabbit/sandbox/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java?rev=753248&r1=753247&r2=753248&view=diff
==============================================================================
--- jackrabbit/sandbox/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java (original)
+++ jackrabbit/sandbox/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java Fri Mar 13 13:45:04 2009
@@ -281,9 +281,10 @@
return DavMethods.DAV_UNLOCK == code;
}
- private static void initMethod(DavMethod method, SessionInfo sessionInfo, boolean addIfHeader) {
+ private static void initMethod(DavMethod method, SessionInfo sessionInfo, boolean addIfHeader) throws RepositoryException {
if (addIfHeader) {
- String[] locktokens = sessionInfo.getLockTokens();
+ checkSessionInfo(sessionInfo);
+ String[] locktokens = ((SessionInfoImpl) sessionInfo).getAllLockTokens();
// TODO: ev. build tagged if header
if (locktokens != null && locktokens.length > 0) {
IfHeader ifH = new IfHeader(locktokens);
@@ -292,7 +293,7 @@
}
}
- private static void initMethod(DavMethod method, BatchImpl batchImpl, boolean addIfHeader) {
+ private static void initMethod(DavMethod method, BatchImpl batchImpl, boolean addIfHeader) throws RepositoryException {
initMethod(method, batchImpl.sessionInfo, addIfHeader);
// add batchId as separate header
@@ -354,14 +355,14 @@
if (client == null) {
client = new HttpClient(connectionManager);
client.setHostConfiguration(hostConfig);
- // always send authentication not waiting for 401
- client.getParams().setAuthenticationPreemptive(true);
// NOTE: null credentials only work if 'missing-auth-mapping' param is
// set on the server
org.apache.commons.httpclient.Credentials creds = null;
if (sessionInfo != null) {
checkSessionInfo(sessionInfo);
creds = ((SessionInfoImpl) sessionInfo).getCredentials().getCredentials();
+ // always send authentication not waiting for 401
+ client.getParams().setAuthenticationPreemptive(true);
}
client.getState().setCredentials(AuthScope.ANY, creds);
clients.put(sessionInfo, client);
@@ -1276,15 +1277,25 @@
*/
public LockInfo lock(SessionInfo sessionInfo, NodeId nodeId, boolean deep,
boolean sessionScoped) throws RepositoryException {
+ return lock(sessionInfo, nodeId, deep, sessionScoped, Long.MAX_VALUE, null);
+ }
+
+ /**
+ * @see RepositoryService#lock(SessionInfo, NodeId, boolean, boolean, long, String)
+ */
+ public LockInfo lock(SessionInfo sessionInfo, NodeId nodeId, boolean deep, boolean sessionScoped, long timeoutHint, String ownerHint) throws UnsupportedRepositoryOperationException, LockException, AccessDeniedException, RepositoryException {
try {
+ checkSessionInfo(sessionInfo);
+ long davTimeout = (timeoutHint == Long.MAX_VALUE) ? INFINITE_TIMEOUT : timeoutHint*1000;
+ String ownerInfo = (ownerHint == null) ? sessionInfo.getUserID() : ownerHint;
+
String uri = getItemUri(nodeId, sessionInfo);
Scope scope = (sessionScoped) ? ItemResourceConstants.EXCLUSIVE_SESSION : Scope.EXCLUSIVE;
- LockMethod method = new LockMethod(uri, scope, Type.WRITE,
- sessionInfo.getUserID(), INFINITE_TIMEOUT, deep);
+ LockMethod method = new LockMethod(uri, scope, Type.WRITE, ownerInfo, davTimeout , deep);
execute(method, sessionInfo);
String lockToken = method.getLockToken();
- sessionInfo.addLockToken(lockToken);
+ ((SessionInfoImpl) sessionInfo).addLockToken(lockToken, sessionScoped);
LockDiscovery disc = method.getResponseAsLockDiscovery();
return retrieveLockInfo(disc, sessionInfo, nodeId, null);
@@ -1299,10 +1310,11 @@
* @see RepositoryService#refreshLock(SessionInfo, NodeId)
*/
public void refreshLock(SessionInfo sessionInfo, NodeId nodeId) throws RepositoryException {
+ checkSessionInfo(sessionInfo);
String uri = getItemUri(nodeId, sessionInfo);
// since sessionInfo does not allow to retrieve token by NodeId,
// pass all available lock tokens to the LOCK method (TODO: correct?)
- LockMethod method = new LockMethod(uri, INFINITE_TIMEOUT, sessionInfo.getLockTokens());
+ LockMethod method = new LockMethod(uri, INFINITE_TIMEOUT, ((SessionInfoImpl) sessionInfo).getAllLockTokens());
execute(method, sessionInfo);
}
@@ -1310,23 +1322,23 @@
* @see RepositoryService#unlock(SessionInfo, NodeId)
*/
public void unlock(SessionInfo sessionInfo, NodeId nodeId) throws RepositoryException {
+ checkSessionInfo(sessionInfo);
String uri = getItemUri(nodeId, sessionInfo);
// Note: since sessionInfo does not allow to identify the id of the
// lock holding node, we need to access the token via lockInfo
// TODO: review this.
- LockInfo lInfo = getLockInfo(sessionInfo, nodeId);
+ LockInfoImpl lInfo = (LockInfoImpl) getLockInfo(sessionInfo, nodeId);
if (lInfo == null) {
throw new LockException("No Lock present on Node with id " + saveGetIdString(nodeId, sessionInfo));
}
- String lockToken = lInfo.getLockToken();
-
- // TODO: ev. additional check if lt is present on the sessionInfo?
+ String lockToken = lInfo.getActiveLock().getToken();
+ boolean isSessionScoped = lInfo.isSessionScoped();
UnLockMethod method = new UnLockMethod(uri, lockToken);
execute(method, sessionInfo);
- sessionInfo.removeLockToken(lockToken);
+ ((SessionInfoImpl) sessionInfo).removeLockToken(lockToken, isSessionScoped);
}
private LockInfo retrieveLockInfo(LockDiscovery lockDiscovery, SessionInfo sessionInfo,
Modified: jackrabbit/sandbox/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/SessionInfoImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/SessionInfoImpl.java?rev=753248&r1=753247&r2=753248&view=diff
==============================================================================
--- jackrabbit/sandbox/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/SessionInfoImpl.java (original)
+++ jackrabbit/sandbox/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/SessionInfoImpl.java Fri Mar 13 13:45:04 2009
@@ -30,6 +30,7 @@
private final CredentialsWrapper credentials;
private final String workspaceName;
private final Set lockTokens = new HashSet();
+ private final Set sessionScopedTokens = new HashSet();
private String lastBatchId;
private NamePathResolver resolver;
@@ -107,4 +108,35 @@
void setNamePathResolver(NamePathResolver resolver) {
this.resolver = resolver;
}
+
+ /**
+ * @return All tokens that this session info needs to communicate with
+ * the DAV-server. This includes all tokens obtained through both LOCK
+ * request(s) as well as those tokens that have been added to the
+ * corresponding JCR session.
+ * Note, that the <code>sessionScopedTokens</code> are only used for
+ * communiation with the DAV server and are never exposed through the
+ * JCR API for they belong to session-scoped locks.
+ */
+ String[] getAllLockTokens() {
+ Set s = new HashSet(lockTokens);
+ s.addAll(sessionScopedTokens);
+ return (String[]) s.toArray(new String[s.size()]);
+ }
+
+ void addLockToken(String token, boolean sessionScoped) {
+ if (sessionScoped) {
+ sessionScopedTokens.add(token);
+ } else {
+ lockTokens.add(token);
+ }
+ }
+
+ void removeLockToken(String token, boolean sessionScoped) {
+ if (sessionScoped) {
+ sessionScopedTokens.remove(token);
+ } else {
+ lockTokens.remove(token);
+ }
+ }
}
\ No newline at end of file