jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r956901 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: SessionImpl.java session/ActiveSessionState.java session/SanityCheck.java session/SessionOperation.java
Date Tue, 22 Jun 2010 14:10:42 GMT
Author: jukka
Date: Tue Jun 22 14:10:42 2010
New Revision: 956901

URL: http://svn.apache.org/viewvc?rev=956901&view=rev
Log:
JCR-890: concurrent read-only access to a session

Simplify use of SessionOperations. Turn Session.refresh() into a managed operation.

Removed:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SanityCheck.java
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/SessionOperation.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=956901&r1=956900&r2=956901&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 14:10:42 2010
@@ -39,7 +39,6 @@ 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;
@@ -384,7 +383,7 @@ public class SessionImpl extends Abstrac
      *                             been closed explicitly or if it has expired)
      */
     protected void sanityCheck() throws RepositoryException {
-        state.perform(SanityCheck.INSTANCE);
+        state.perform(new SessionOperation("sanity check"));
     }
 
     /**
@@ -893,12 +892,9 @@ public class SessionImpl extends Abstrac
     /**
      * {@inheritDoc}
      */
-    public void save()
-            throws AccessDeniedException, ItemExistsException,
-            ConstraintViolationException, InvalidItemStateException,
-            VersionException, LockException, NoSuchNodeTypeException,
-            RepositoryException {
-        state.perform(new SessionOperation() {
+    public void save() throws RepositoryException {
+        state.perform(new SessionOperation("save") {
+            @Override
             public void perform() throws RepositoryException {
                 // JCR-2425: check whether session is allowed to read root node
                 if (hasPermission("/", ACTION_READ)) {
@@ -914,28 +910,30 @@ public class SessionImpl extends Abstrac
     /**
      * {@inheritDoc}
      */
-    public void refresh(boolean keepChanges) throws RepositoryException {
-        // check sanity of this session
-        sanityCheck();
+    public void refresh(final boolean keepChanges) throws RepositoryException {
+        state.perform(new SessionOperation("refresh") {
+            @Override
+            public void perform() throws RepositoryException {
+                // JCR-1753: Ensure that we are up to date with cluster changes
+                ClusterNode cluster = repositoryContext.getClusterNode();
+                if (cluster != null && clusterSyncOnRefresh()) {
+                    try {
+                        cluster.sync();
+                    } catch (ClusterException e) {
+                        throw new RepositoryException(
+                                "Unable to synchronize with the cluster", e);
+                    }
+                }
 
-        // JCR-1753: Ensure that we are up to date with cluster changes
-        ClusterNode cluster = repositoryContext.getClusterNode();
-        if (cluster != null && clusterSyncOnRefresh()) {
-            try {
-                cluster.sync();
-            } catch (ClusterException e) {
-                throw new RepositoryException(
-                        "Unable to synchronize with the cluster", e);
+                if (!keepChanges) {
+                    itemStateMgr.disposeAllTransientItemStates();
+                } else {
+                    // FIXME should reset Item#status field to STATUS_NORMAL
+                    // of all non-transient instances; maybe also
+                    // have to reset stale ItemState instances
+                }
             }
-        }
-
-        if (!keepChanges) {
-            itemStateMgr.disposeAllTransientItemStates();
-        } else {
-            /** todo FIXME should reset Item#status field to STATUS_NORMAL
-             * of all non-transient instances; maybe also
-             * have to reset stale ItemState instances */
-        }
+        });
     }
 
     /**

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=956901&r1=956900&r2=956901&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 14:10:42 2010
@@ -56,7 +56,8 @@ public class ActiveSessionState implemen
      */
     public void perform(SessionOperation operation) throws RepositoryException {
         if (!lock.tryLock()) {
-            log.warn("Attempt to concurrently access a single session");
+            log.warn("Attempt to perform a {} operation while another thread"
+                    + " is concurrently accessing the session", operation);
             lock.lock();
         }
         try {

Modified: 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=956901&r1=956900&r2=956901&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionOperation.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionOperation.java
Tue Jun 22 14:10:42 2010
@@ -23,13 +23,30 @@ import javax.jcr.RepositoryException;
  * {@link SessionState} interface to implement generic controls like
  * synchronization and liveness checks on all session operation.
  */
-public interface SessionOperation {
+public class SessionOperation {
+
+    private final String name;
+
+    public SessionOperation(String name) {
+        this.name = name;
+    }
 
     /**
-     * Performs this operation.
+     * Performs this operation. The default implementation does nothing;
+     * subclasses should override this method to implement custom operations.
      *
      * @throws RepositoryException if the operation fails
      */
-    void perform() throws RepositoryException;
+    public void perform() throws RepositoryException {
+    }
+
+    /**
+     * Returns the name of this operation.
+     *
+     * @return operation name
+     */
+    public String toString() {
+        return name;
+    }
 
 }



Mime
View raw message