You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ju...@apache.org on 2010/06/22 15:44:27 UTC
svn commit: r956896 - in
/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core:
./ session/
Author: jukka
Date: Tue Jun 22 13:44:27 2010
New Revision: 956896
URL: http://svn.apache.org/viewvc?rev=956896&view=rev
Log:
JCR-890: concurrent read-only access to a session
Add SessionState.perform(SessionOperation) for centralizing the control of any kinds of session operations.
Added:
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SanityCheck.java (with props)
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionOperation.java (with props)
Modified:
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/ActiveSessionState.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/ClosedSessionState.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionState.java
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java?rev=956896&r1=956895&r2=956896&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java Tue Jun 22 13:44:27 2010
@@ -39,6 +39,8 @@ import org.apache.jackrabbit.core.securi
import org.apache.jackrabbit.core.security.authorization.Permission;
import org.apache.jackrabbit.core.session.ActiveSessionState;
import org.apache.jackrabbit.core.session.ClosedSessionState;
+import org.apache.jackrabbit.core.session.SanityCheck;
+import org.apache.jackrabbit.core.session.SessionOperation;
import org.apache.jackrabbit.core.session.SessionState;
import org.apache.jackrabbit.core.state.LocalItemStateManager;
import org.apache.jackrabbit.core.state.NodeState;
@@ -382,7 +384,7 @@ public class SessionImpl extends Abstrac
* been closed explicitly or if it has expired)
*/
protected void sanityCheck() throws RepositoryException {
- state.checkAlive();
+ state.perform(SanityCheck.INSTANCE);
}
/**
@@ -896,16 +898,17 @@ public class SessionImpl extends Abstrac
ConstraintViolationException, InvalidItemStateException,
VersionException, LockException, NoSuchNodeTypeException,
RepositoryException {
- // check sanity of this session
- sanityCheck();
-
- // /JCR-2425: check whether session is allowed to read root node
- if (hasPermission("/", ACTION_READ)) {
- getItemManager().getRootNode().save();
- } else {
- NodeId id = getItemStateManager().getIdOfRootTransientNodeState();
- getItemManager().getItem(id).save();
- }
+ state.perform(new SessionOperation() {
+ public void perform() throws RepositoryException {
+ // JCR-2425: check whether session is allowed to read root node
+ if (hasPermission("/", ACTION_READ)) {
+ getItemManager().getRootNode().save();
+ } else {
+ NodeId id = getItemStateManager().getIdOfRootTransientNodeState();
+ getItemManager().getItem(id).save();
+ }
+ }
+ });
}
/**
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/ActiveSessionState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/ActiveSessionState.java?rev=956896&r1=956895&r2=956896&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/ActiveSessionState.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/ActiveSessionState.java Tue Jun 22 13:44:27 2010
@@ -16,6 +16,8 @@
*/
package org.apache.jackrabbit.core.session;
+import javax.jcr.RepositoryException;
+
public class ActiveSessionState implements SessionState {
/**
@@ -28,9 +30,13 @@ public class ActiveSessionState implemen
}
/**
- * Ignored; the session is alive.
+ * Performs the given operation within a synchronized block.
+ *
+ * @throws RepositoryException if the operation fails
*/
- public void checkAlive() {
+ public synchronized void perform(SessionOperation operation)
+ throws RepositoryException {
+ operation.perform();
}
}
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/ClosedSessionState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/ClosedSessionState.java?rev=956896&r1=956895&r2=956896&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/ClosedSessionState.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/ClosedSessionState.java Tue Jun 22 13:44:27 2010
@@ -43,10 +43,11 @@ public class ClosedSessionState implemen
*
* @throws RepositoryException always thrown
*/
- public void checkAlive() throws RepositoryException {
+ public void perform(SessionOperation operation) throws RepositoryException {
throw new RepositoryException(
- "This session has been closed; see the chained exception"
- + " for where the session was closed", exception);
+ "Unable to perform " + operation + " since this session"
+ + " has been closed. See the chained exception for a trace"
+ + " of where the session was closed", exception);
}
}
Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SanityCheck.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SanityCheck.java?rev=956896&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SanityCheck.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SanityCheck.java Tue Jun 22 13:44:27 2010
@@ -0,0 +1,37 @@
+/*
+ * 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.core.session;
+
+
+/**
+ * Dummy session operation for doing a sanity check on the session state.
+ */
+public class SanityCheck implements SessionOperation {
+
+ public static final SanityCheck INSTANCE = new SanityCheck();
+
+ /**
+ * Does nothing.
+ */
+ public void perform() {
+ }
+
+ public String toString() {
+ return "sanity check";
+ }
+
+}
Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SanityCheck.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionOperation.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionOperation.java?rev=956896&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionOperation.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionOperation.java Tue Jun 22 13:44:27 2010
@@ -0,0 +1,35 @@
+/*
+ * 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.core.session;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * An operation that is performed on a JCR session. Used by the
+ * {@link SessionState} interface to implement generic controls like
+ * synchronization and liveness checks on all session operation.
+ */
+public interface SessionOperation {
+
+ /**
+ * Performs this operation.
+ *
+ * @throws RepositoryException if the operation fails
+ */
+ void perform() throws RepositoryException;
+
+}
Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionOperation.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionState.java?rev=956896&r1=956895&r2=956896&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionState.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionState.java Tue Jun 22 13:44:27 2010
@@ -34,10 +34,12 @@ public interface SessionState {
boolean isAlive();
/**
- * Checks whether this session is alive, and throws an exception if not.
+ * Performs the given session operation.
*
- * @throws RepositoryException if this session is not alive
+ * @param operation the session operation
+ * @throws RepositoryException if the operation fails or can not
+ * for some other reason be performed
*/
- void checkAlive() throws RepositoryException;
+ void perform(SessionOperation operation) throws RepositoryException;
}