jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1539379 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/kernel/ main/java/org/apache/jackrabbit/oak/plugins/mongomk/ main/java/org/apache/jackrabbit/oak/plugins/segment/ test/java/org/apache/jackrabbit/oak/ tes...
Date Wed, 06 Nov 2013 16:10:51 GMT
Author: mduerig
Date: Wed Nov  6 16:10:51 2013
New Revision: 1539379

URL: http://svn.apache.org/r1539379
Log:
OAK-1143  [scala] Repository init throws "illegal cyclic reference involving class ChangeDispatcher"
Remove "old" mechanism to inject observers into NodeStore implementations in favour of the
new method

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoMK.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoNodeStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/NodeStoreFixture.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/NodeStoreTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java?rev=1539379&r1=1539378&r2=1539379&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
Wed Nov  6 16:10:51 2013
@@ -41,10 +41,9 @@ import org.apache.jackrabbit.oak.api.Com
 import org.apache.jackrabbit.oak.cache.CacheLIRS;
 import org.apache.jackrabbit.oak.cache.CacheStats;
 import org.apache.jackrabbit.oak.spi.commit.ChangeDispatcher;
-import org.apache.jackrabbit.oak.spi.commit.Observable;
 import org.apache.jackrabbit.oak.spi.commit.CommitHook;
 import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
-import org.apache.jackrabbit.oak.spi.commit.EmptyObserver;
+import org.apache.jackrabbit.oak.spi.commit.Observable;
 import org.apache.jackrabbit.oak.spi.commit.Observer;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
@@ -62,12 +61,6 @@ public class KernelNodeStore implements 
      */
     private final MicroKernel kernel;
 
-    /**
-     * Change observer.
-     */
-    @Nonnull
-    private final Observer observer;
-
     private final LoadingCache<String, KernelNodeState> cache;
 
     private final CacheStats cacheStats;
@@ -84,9 +77,8 @@ public class KernelNodeStore implements 
      */
     private KernelNodeState root;
 
-    public KernelNodeStore(final MicroKernel kernel, long cacheSize, Observer observer) {
+    public KernelNodeStore(final MicroKernel kernel, long cacheSize) {
         this.kernel = checkNotNull(kernel);
-        this.observer = observer;
 
         Weigher<String, KernelNodeState> weigher = new Weigher<String, KernelNodeState>()
{
             @Override
@@ -129,12 +121,8 @@ public class KernelNodeStore implements 
         changeDispatcher = new ChangeDispatcher(this);
     }
 
-    public KernelNodeStore(MicroKernel kernel, long cacheSize) {
-        this(kernel, cacheSize, EmptyObserver.INSTANCE);
-    }
-
     public KernelNodeStore(MicroKernel kernel) {
-        this(kernel, DEFAULT_CACHE_SIZE, EmptyObserver.INSTANCE);
+        this(kernel, DEFAULT_CACHE_SIZE);
     }
 
     /**
@@ -159,7 +147,6 @@ public class KernelNodeStore implements 
         String revision = kernel.getHeadRevision();
         if (!revision.equals(root.getRevision())) {
             root = getRootState(revision);
-            observer.contentChanged(root, null);
         }
         return root;
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoMK.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoMK.java?rev=1539379&r1=1539378&r2=1539379&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoMK.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoMK.java
Wed Nov  6 16:10:51 2013
@@ -25,6 +25,10 @@ import java.util.concurrent.ExecutionExc
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.Weigher;
+import com.mongodb.DB;
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.api.MicroKernelException;
 import org.apache.jackrabbit.mk.blobs.BlobStore;
@@ -41,15 +45,6 @@ import org.apache.jackrabbit.oak.commons
 import org.apache.jackrabbit.oak.plugins.mongomk.Node.Children;
 import org.apache.jackrabbit.oak.plugins.mongomk.blob.MongoBlobStore;
 import org.apache.jackrabbit.oak.plugins.mongomk.util.Utils;
-import org.apache.jackrabbit.oak.spi.commit.EmptyObserver;
-import org.apache.jackrabbit.oak.spi.commit.Observer;
-
-import com.google.common.cache.Cache;
-import com.google.common.cache.CacheBuilder;
-import com.google.common.cache.Weigher;
-import com.mongodb.DB;
-
-import static com.google.common.base.Preconditions.checkNotNull;
 
 /**
  * A MicroKernel implementation that stores the data in a MongoDB.
@@ -622,7 +617,6 @@ public class MongoMK implements MicroKer
         private MongoNodeStore nodeStore;
         private DocumentStore documentStore;
         private BlobStore blobStore;
-        private Observer observer = EmptyObserver.INSTANCE;
         private int clusterId  = Integer.getInteger("oak.mongoMK.clusterId", 0);
         private int asyncDelay = 1000;
         private boolean timing;
@@ -809,16 +803,6 @@ public class MongoMK implements MicroKer
             return splitDocumentAgeMillis;
         }
 
-        public Builder setObserver(@Nonnull Observer observer) {
-            this.observer = checkNotNull(observer);
-            return this;
-        }
-
-        @Nonnull
-        public Observer getObserver() {
-            return observer;
-        }
-
         /**
          * Open the MongoMK instance using the configured options.
          * 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoNodeStore.java?rev=1539379&r1=1539378&r2=1539379&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoNodeStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoNodeStore.java
Wed Nov  6 16:10:51 2013
@@ -219,14 +219,8 @@ public final class MongoNodeStore
      */
     private final BlobStore blobStore;
 
-    /**
-     * The node store observer.
-     */
-    private final Observer observer;
-
     public MongoNodeStore(MongoMK.Builder builder) {
         this.blobStore = builder.getBlobStore();
-        this.observer = builder.getObserver();
         if (builder.isUseSimpleRevision()) {
             this.simpleRevisionCounter = new AtomicInteger(0);
         }
@@ -333,7 +327,6 @@ public final class MongoNodeStore
         if (!checkNotNull(newHead).equals(previous)) {
             // head changed
             headRevision = newHead;
-            observer.contentChanged(getRoot(newHead), null);
         }
         return previous;
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java?rev=1539379&r1=1539378&r2=1539379&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java
Wed Nov  6 16:10:51 2013
@@ -32,10 +32,9 @@ import javax.annotation.Nullable;
 import org.apache.jackrabbit.oak.api.Blob;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.spi.commit.ChangeDispatcher;
-import org.apache.jackrabbit.oak.spi.commit.Observable;
 import org.apache.jackrabbit.oak.spi.commit.CommitHook;
 import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
-import org.apache.jackrabbit.oak.spi.commit.EmptyObserver;
+import org.apache.jackrabbit.oak.spi.commit.Observable;
 import org.apache.jackrabbit.oak.spi.commit.Observer;
 import org.apache.jackrabbit.oak.spi.state.ConflictAnnotatingRebaseDiff;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
@@ -50,35 +49,24 @@ public class SegmentNodeStore implements
 
     private final Journal journal;
 
-    private final Observer observer;
-
     private final ChangeDispatcher changeDispatcher;
 
     private SegmentNodeState head;
 
     private long maximumBackoff = MILLISECONDS.convert(10, SECONDS);
 
-    public SegmentNodeStore(SegmentStore store, String journal, Observer observer) {
+    public SegmentNodeStore(SegmentStore store, String journal) {
         this.store = store;
         this.journal = store.getJournal(journal);
-        this.observer = observer;
         this.head = new SegmentNodeState(
                 store.getWriter().getDummySegment(), this.journal.getHead());
         this.changeDispatcher = new ChangeDispatcher(this);
     }
 
-    public SegmentNodeStore(SegmentStore store, String journal) {
-        this(store, journal, EmptyObserver.INSTANCE);
-    }
-
     public SegmentNodeStore(SegmentStore store) {
         this(store, "root");
     }
 
-    public SegmentNodeStore(SegmentStore store, Observer observer) {
-        this(store, "root", observer);
-    }
-
     void setMaximumBackoff(long max) {
         this.maximumBackoff = max;
     }
@@ -86,7 +74,6 @@ public class SegmentNodeStore implements
     synchronized SegmentNodeState getHead() {
         head = new SegmentNodeState(
                 store.getWriter().getDummySegment(), journal.getHead());
-        observer.contentChanged(head.getChildNode(ROOT), null);
         return head;
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/NodeStoreFixture.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/NodeStoreFixture.java?rev=1539379&r1=1539378&r2=1539379&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/NodeStoreFixture.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/NodeStoreFixture.java
Wed Nov  6 16:10:51 2013
@@ -23,18 +23,12 @@ import static org.apache.jackrabbit.oak.
 import java.io.Closeable;
 import java.io.IOException;
 
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-
 import org.apache.jackrabbit.mk.core.MicroKernelImpl;
-import org.apache.jackrabbit.oak.plugins.mongomk.MongoMK;
 import org.apache.jackrabbit.oak.kernel.KernelNodeStore;
+import org.apache.jackrabbit.oak.plugins.mongomk.MongoMK;
 import org.apache.jackrabbit.oak.plugins.mongomk.MongoNodeStore;
 import org.apache.jackrabbit.oak.plugins.segment.SegmentNodeStore;
 import org.apache.jackrabbit.oak.plugins.segment.memory.MemoryStore;
-import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
-import org.apache.jackrabbit.oak.spi.commit.Observer;
-import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
 
 /**
@@ -43,8 +37,6 @@ import org.apache.jackrabbit.oak.spi.sta
 public abstract class NodeStoreFixture {
 
     public static final NodeStoreFixture SEGMENT_MK = new NodeStoreFixture() {
-        private final ResettableObserver observer = new ResettableObserver();
-
         @Override
         public String toString() {
             return "SegmentMK Fixture";
@@ -52,22 +44,15 @@ public abstract class NodeStoreFixture {
 
         @Override
         public NodeStore createNodeStore() {
-            return new SegmentNodeStore(new MemoryStore(), observer);
+            return new SegmentNodeStore(new MemoryStore());
         }
 
         @Override
         public void dispose(NodeStore nodeStore) {
         }
-
-        @Override
-        public void setObserver(Observer observer) {
-            this.observer.setObserver(observer);
-        }
     };
 
     public static final NodeStoreFixture MONGO_MK = new NodeStoreFixture() {
-        private final ResettableObserver observer = new ResettableObserver();
-
         @Override
         public String toString() {
             return "MongoMK Fixture";
@@ -75,7 +60,7 @@ public abstract class NodeStoreFixture {
 
         @Override
         public NodeStore createNodeStore() {
-            return new CloseableNodeStore(new MongoMK.Builder().open(), observer);
+            return new CloseableNodeStore(new MongoMK.Builder().open());
         }
 
         @Override
@@ -88,16 +73,9 @@ public abstract class NodeStoreFixture {
                 }
             }
         }
-
-        @Override
-        public void setObserver(Observer observer) {
-            this.observer.setObserver(observer);
-        }
     };
 
     public static final NodeStoreFixture MONGO_NS = new NodeStoreFixture() {
-        private final ResettableObserver observer = new ResettableObserver();
-
         @Override
         public String toString() {
             return "MongoNS Fixture";
@@ -105,7 +83,7 @@ public abstract class NodeStoreFixture {
 
         @Override
         public NodeStore createNodeStore() {
-            return new MongoMK.Builder().setObserver(observer).getNodeStore();
+            return new MongoMK.Builder().getNodeStore();
         }
 
         @Override
@@ -114,16 +92,9 @@ public abstract class NodeStoreFixture {
                 ((MongoNodeStore) nodeStore).dispose();
             }
         }
-
-        @Override
-        public void setObserver(Observer observer) {
-            this.observer.setObserver(observer);
-        }
     };
 
     public static final NodeStoreFixture MK_IMPL = new NodeStoreFixture() {
-        private final ResettableObserver observer = new ResettableObserver();
-
         @Override
         public String toString() {
             return "MKImpl Fixture";
@@ -131,32 +102,25 @@ public abstract class NodeStoreFixture {
 
         @Override
         public NodeStore createNodeStore() {
-            return new KernelNodeStore(new MicroKernelImpl(), DEFAULT_CACHE_SIZE, observer);
+            return new KernelNodeStore(new MicroKernelImpl(), DEFAULT_CACHE_SIZE);
         }
 
         @Override
         public void dispose(NodeStore nodeStore) {
         }
-
-        @Override
-        public void setObserver(Observer observer) {
-            this.observer.setObserver(observer);
-        }
     };
 
     public abstract NodeStore createNodeStore();
 
     public abstract void dispose(NodeStore nodeStore);
 
-    public abstract void setObserver(Observer observer);
-
     private static class CloseableNodeStore
             extends KernelNodeStore implements Closeable {
 
         private final MongoMK kernel;
 
-        public CloseableNodeStore(MongoMK kernel, Observer observer) {
-            super(kernel, DEFAULT_CACHE_SIZE, observer);
+        public CloseableNodeStore(MongoMK kernel) {
+            super(kernel, DEFAULT_CACHE_SIZE);
             this.kernel = kernel;
         }
 
@@ -165,21 +129,4 @@ public abstract class NodeStoreFixture {
             kernel.dispose();
         }
     }
-
-    private static class ResettableObserver implements Observer {
-
-        private Observer observer;
-
-        @Override
-        public void contentChanged(
-                @Nonnull NodeState root, @Nullable CommitInfo info) {
-            if (observer != null) {
-                observer.contentChanged(root, info);
-            }
-        }
-
-        public void setObserver(Observer observer) {
-            this.observer = observer;
-        }
-    }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/NodeStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/NodeStoreTest.java?rev=1539379&r1=1539378&r2=1539379&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/NodeStoreTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/NodeStoreTest.java
Wed Nov  6 16:10:51 2013
@@ -31,6 +31,8 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicReference;
 
 import javax.annotation.Nonnull;
@@ -43,12 +45,14 @@ import org.apache.jackrabbit.oak.plugins
 import org.apache.jackrabbit.oak.spi.commit.CommitHook;
 import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
 import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
+import org.apache.jackrabbit.oak.spi.commit.Observable;
 import org.apache.jackrabbit.oak.spi.commit.Observer;
 import org.apache.jackrabbit.oak.spi.state.DefaultNodeStateDiff;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
 import org.junit.After;
+import org.junit.Assume;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -142,14 +146,19 @@ public class NodeStoreTest {
     }
 
     @Test
-    public void afterCommitHook() throws CommitFailedException {
+    public void afterCommitHook() throws CommitFailedException, InterruptedException {
+        Assume.assumeTrue(store instanceof Observable);
+
         final AtomicReference<NodeState> observedRoot =
                 new AtomicReference<NodeState>(null);
-        fixture.setObserver(new Observer() {
+        final CountDownLatch latch = new CountDownLatch(2);
+
+        ((Observable) store).addObserver(new Observer() {
             @Override
             public void contentChanged(
                     @Nonnull NodeState root, @Nullable CommitInfo info) {
                 observedRoot.set(checkNotNull(root));
+                latch.countDown();
             }
         });
 
@@ -159,11 +168,11 @@ public class NodeStoreTest {
         NodeBuilder newNodeBuilder = testBuilder.child("newNode");
 
         newNodeBuilder.setProperty("n", 42);
-
         testBuilder.getChildNode("a").remove();
 
         store.merge(rootBuilder, EmptyHook.INSTANCE, null);
         NodeState newRoot = store.getRoot(); // triggers the observer
+        latch.await(2, TimeUnit.SECONDS);
 
         NodeState after = observedRoot.get();
         assertNotNull(after);



Mime
View raw message