jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r956898 - /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/ActiveSessionState.java
Date Tue, 22 Jun 2010 13:56:14 GMT
Author: jukka
Date: Tue Jun 22 13:56:13 2010
New Revision: 956898

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

Use an explicit lock instead of Java synchronization to be able to log warnings about concurrent
session use.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/ActiveSessionState.java

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=956898&r1=956897&r2=956898&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:56:13 2010
@@ -16,11 +16,31 @@
  */
 package org.apache.jackrabbit.core.session;
 
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
 import javax.jcr.RepositoryException;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 public class ActiveSessionState implements SessionState {
 
     /**
+     * Logger instance.
+     */
+    private static final Logger log =
+        LoggerFactory.getLogger(ActiveSessionState.class);
+
+    /**
+     * The lock used to guarantee synchronized execution of repository
+     * operations. An explicit lock is used instead of normal Java
+     * synchronization in order to be able to log attempts to concurrently
+     * use a session. TODO: Check if this is a performance issue!
+     */
+    private final Lock lock = new ReentrantLock();
+
+    /**
      * Returns <code>true</code>; the session is alive.
      *
      * @return <code>true</code>
@@ -34,9 +54,16 @@ public class ActiveSessionState implemen
      *
      * @throws RepositoryException if the operation fails
      */
-    public synchronized void perform(SessionOperation operation)
-            throws RepositoryException {
-        operation.perform();
+    public void perform(SessionOperation operation) throws RepositoryException {
+        if (!lock.tryLock()) {
+            log.warn("Attempt to concurrently access a single session");
+            lock.lock();
+        }
+        try {
+            operation.perform();
+        } finally {
+            lock.unlock();
+        }
     }
 
 }



Mime
View raw message