jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r265703 - in /incubator/jackrabbit/trunk/core/src: java/org/apache/jackrabbit/core/state/ItemState.java test/org/apache/jackrabbit/core/ConcurrencyTest.java
Date Thu, 01 Sep 2005 12:02:45 GMT
Author: stefan
Date: Thu Sep  1 05:02:39 2005
New Revision: 265703

URL: http://svn.apache.org/viewcvs?rev=265703&view=rev
Log:
fixing concurrency issue that could cause incorrect InvalidItemStateExceptions being thrown
under heavy load

Modified:
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/state/ItemState.java
    incubator/jackrabbit/trunk/core/src/test/org/apache/jackrabbit/core/ConcurrencyTest.java

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/state/ItemState.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/state/ItemState.java?rev=265703&r1=265702&r2=265703&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/state/ItemState.java
(original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/state/ItemState.java
Thu Sep  1 05:02:39 2005
@@ -203,6 +203,7 @@
         // prepare this instance so it can be gc'ed
         listeners.clear();
         disconnect();
+        overlayedState = null;
         status = STATUS_UNDEFINED;
     }
 
@@ -211,19 +212,36 @@
      */
     protected void connect(ItemState overlayedState) {
         if (this.overlayedState != null) {
-            throw new IllegalStateException("Item state already connected: " + this);
+            if (this.overlayedState != overlayedState) {
+                throw new IllegalStateException("Item state already connected to another
underlying state: " + this);
+            }
         }
         this.overlayedState = overlayedState;
         this.overlayedState.addListener(this);
     }
 
     /**
+     * Reconnect this state to the overlayed state that it has been
+     * disconnected from earlier.
+     */
+    protected void reconnect() {
+        if (this.overlayedState == null) {
+            throw new IllegalStateException("Item state cannot be reconnected because there's
no underlying state to reconnect to: " + this);
+        }
+        this.overlayedState.addListener(this);
+    }
+
+    /**
      * Disconnect this state from the underlying overlayed state.
      */
     protected void disconnect() {
         if (overlayedState != null) {
+            // de-register listener on overlayed state...
             overlayedState.removeListener(this);
-            overlayedState = null;
+            // ...but still keep reference to overlayed state to allow
+            // reconnecting at a later stage and to make sure
+            // it is not accidentally collected by the gc
+            //overlayedState = null;
         }
     }
 

Modified: incubator/jackrabbit/trunk/core/src/test/org/apache/jackrabbit/core/ConcurrencyTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/test/org/apache/jackrabbit/core/ConcurrencyTest.java?rev=265703&r1=265702&r2=265703&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/test/org/apache/jackrabbit/core/ConcurrencyTest.java
(original)
+++ incubator/jackrabbit/trunk/core/src/test/org/apache/jackrabbit/core/ConcurrencyTest.java
Thu Sep  1 05:02:39 2005
@@ -28,7 +28,7 @@
 public class ConcurrencyTest extends AbstractJCRTest {
 
     private static final int NUM_ITERATIONS = 2;
-    private static final int NUM_SESSIONS = 5;
+    private static final int NUM_SESSIONS = 100;
     private static final int NUM_NODES = 100;
 
     final ArrayList exceptions = new ArrayList();
@@ -145,6 +145,7 @@
                 session.save();
             } catch (Exception e) {
                 log.println("Exception while " + state + ": " + e.getMessage());
+                //e.printStackTrace();
                 exceptions.add(e);
             } finally {
                 session.logout();



Mime
View raw message