Author: chetanm
Date: Tue Jun 21 06:21:05 2016
New Revision: 1749441

URL: http://svn.apache.org/viewvc?rev=1749441&view=rev
Log:
OAK-4180 - Use another NodeStore as a local cache for a remote Document store

Simplify the construction logic via a builder which provides the default values

Added:
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreBuilder.java
   (with props)
Modified:
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreCache.java
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreCacheService.java
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreObserver.java
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreCacheTest.java
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreObserverTest.java

Added: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreBuilder.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreBuilder.java?rev=1749441&view=auto
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreBuilder.java
 (added)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreBuilder.java
 Tue Jun 21 06:21:05 2016
@@ -0,0 +1,67 @@
+/*
+ * 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.oak.plugins.document.secondary;
+
+import java.util.Collections;
+
+import org.apache.jackrabbit.oak.plugins.document.NodeStateDiffer;
+import org.apache.jackrabbit.oak.plugins.index.PathFilter;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
+import org.apache.jackrabbit.oak.stats.StatisticsProvider;
+
+import static java.util.Collections.singletonList;
+
+public class SecondaryStoreBuilder {
+    private final NodeStore store;
+    private PathFilter pathFilter = new PathFilter(singletonList("/"), 
Collections.<String>emptyList());
+    private NodeStateDiffer differ = NodeStateDiffer.DEFAULT_DIFFER;
+    private StatisticsProvider statsProvider = StatisticsProvider.NOOP;
+
+    public SecondaryStoreBuilder(NodeStore nodeStore) {
+        this.store = nodeStore;
+    }
+
+    public SecondaryStoreBuilder pathFilter(PathFilter filter) {
+        this.pathFilter = filter;
+        return this;
+    }
+
+    public SecondaryStoreBuilder differ(NodeStateDiffer differ) {
+        this.differ = differ;
+        return this;
+    }
+
+    public SecondaryStoreBuilder statisticsProvider(StatisticsProvider 
statisticsProvider) {
+        this.statsProvider = statisticsProvider;
+        return this;
+    }
+
+    public SecondaryStoreCache buildCache() {
+        return new SecondaryStoreCache(store, differ, pathFilter, 
statsProvider);
+    }
+
+    public SecondaryStoreObserver buildObserver(){
+        return buildObserver(SecondaryStoreRootObserver.NOOP);
+    }
+
+    public SecondaryStoreObserver buildObserver(SecondaryStoreRootObserver 
secondaryStoreRootObserver) {
+        return new SecondaryStoreObserver(store, differ, pathFilter, 
statsProvider, secondaryStoreRootObserver);
+    }
+}

Propchange: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreCache.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreCache.java?rev=1749441&r1=1749440&r2=1749441&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreCache.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreCache.java
 Tue Jun 21 06:21:05 2016
@@ -56,14 +56,10 @@ class SecondaryStoreCache implements Doc
     private final EvictingQueue<AbstractDocumentNodeState> queue;
     private volatile AbstractDocumentNodeState[] previousRoots = EMPTY;
 
-    public SecondaryStoreCache(NodeStore store, PathFilter pathFilter, 
NodeStateDiffer differ) {
-        this(store, pathFilter, StatisticsProvider.NOOP, differ);
-    }
-
-    public SecondaryStoreCache(NodeStore store, PathFilter pathFilter, 
StatisticsProvider statisticsProvider,
-                               NodeStateDiffer differ) {
+    public SecondaryStoreCache(NodeStore nodeStore, NodeStateDiffer differ, 
PathFilter pathFilter,
+                               StatisticsProvider statisticsProvider) {
         this.differ = differ;
-        this.store = store;
+        this.store = nodeStore;
         this.pathFilter = pathFilter;
         this.unknownPaths = 
statisticsProvider.getMeter("DOCUMENT_CACHE_SEC_UNKNOWN", StatsOptions.DEFAULT);
         this.knownMissed = 
statisticsProvider.getMeter("DOCUMENT_CACHE_SEC_KNOWN_MISSED", 
StatsOptions.DEFAULT);

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreCacheService.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreCacheService.java?rev=1749441&r1=1749440&r2=1749441&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreCacheService.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreCacheService.java
 Tue Jun 21 06:21:05 2016
@@ -147,9 +147,12 @@ public class SecondaryStoreCacheService
         pathFilter = new PathFilter(asList(includedPaths), 
asList(excludedPaths));
         NodeStore segStore = secondaryNodeStoreProvider.getSecondaryStore();
 
-        SecondaryStoreCache cache = new SecondaryStoreCache(segStore, 
pathFilter, statisticsProvider, differ);
-        SecondaryStoreObserver observer = new SecondaryStoreObserver(segStore, 
pathFilter,
-                cache, differ, statisticsProvider);
+        SecondaryStoreBuilder builder = new SecondaryStoreBuilder(segStore)
+                .differ(differ)
+                .statisticsProvider(statisticsProvider)
+                .pathFilter(pathFilter);
+        SecondaryStoreCache cache = builder.buildCache();
+        SecondaryStoreObserver observer = builder.buildObserver(cache);
         registerObserver(observer, config);
 
         
regs.add(bundleContext.registerService(DocumentNodeStateCache.class.getName(), 
cache, null));

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreObserver.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreObserver.java?rev=1749441&r1=1749440&r2=1749441&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreObserver.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreObserver.java
 Tue Jun 21 06:21:05 2016
@@ -52,13 +52,11 @@ class SecondaryStoreObserver implements
     private final TimerStats external;
     private boolean firstEventProcessed;
 
-    public SecondaryStoreObserver(NodeStore nodeStore, PathFilter pathFilter, 
NodeStateDiffer differ) {
-        this(nodeStore, pathFilter, SecondaryStoreRootObserver.NOOP, differ, 
StatisticsProvider.NOOP);
-    }
-
-    public SecondaryStoreObserver(NodeStore nodeStore, PathFilter pathFilter,
-                                  SecondaryStoreRootObserver secondaryObserver,
-                                  NodeStateDiffer differ, StatisticsProvider 
statisticsProvider) {
+    public SecondaryStoreObserver(NodeStore nodeStore,
+                                  NodeStateDiffer differ,
+                                  PathFilter pathFilter,
+                                  StatisticsProvider statisticsProvider,
+                                  SecondaryStoreRootObserver 
secondaryObserver) {
         this.nodeStore = nodeStore;
         this.pathFilter = pathFilter;
         this.secondaryObserver = secondaryObserver;

Modified: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreCacheTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreCacheTest.java?rev=1749441&r1=1749440&r2=1749441&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreCacheTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreCacheTest.java
 Tue Jun 21 06:21:05 2016
@@ -38,13 +38,11 @@ import org.apache.jackrabbit.oak.spi.com
 import org.apache.jackrabbit.oak.spi.state.EqualsDiff;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
-import org.apache.jackrabbit.oak.stats.StatisticsProvider;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
 import static com.google.common.collect.ImmutableList.of;
-import static 
org.apache.jackrabbit.oak.plugins.document.NodeStateDiffer.DEFAULT_DIFFER;
 import static 
org.apache.jackrabbit.oak.plugins.document.secondary.SecondaryStoreObserverTest.create;
 import static 
org.apache.jackrabbit.oak.plugins.document.secondary.SecondaryStoreObserverTest.documentState;
 import static org.junit.Assert.assertEquals;
@@ -168,9 +166,8 @@ public class SecondaryStoreCacheTest {
     @Test
     public void readWithSecondaryLagging() throws Exception{
         PathFilter pathFilter = new PathFilter(of("/a"), empty);
-        SecondaryStoreCache cache = new SecondaryStoreCache(secondary, 
pathFilter, DEFAULT_DIFFER);
-        SecondaryStoreObserver observer = new 
SecondaryStoreObserver(secondary, pathFilter, cache,
-                DEFAULT_DIFFER, StatisticsProvider.NOOP);
+        SecondaryStoreCache cache = createBuilder(pathFilter).buildCache();
+        SecondaryStoreObserver observer = 
createBuilder(pathFilter).buildObserver(cache);
 
         NodeBuilder nb = primary.getRoot().builder();
         create(nb, "/a/b", "/a/c");
@@ -202,14 +199,18 @@ public class SecondaryStoreCacheTest {
     }
 
     private SecondaryStoreCache createCache(PathFilter pathFilter){
-        SecondaryStoreCache cache = new SecondaryStoreCache(secondary, 
pathFilter, DEFAULT_DIFFER);
-        SecondaryStoreObserver observer = new 
SecondaryStoreObserver(secondary, pathFilter, cache,
-                DEFAULT_DIFFER, StatisticsProvider.NOOP);
+        SecondaryStoreBuilder builder = createBuilder(pathFilter);
+        SecondaryStoreCache cache = builder.buildCache();
+        SecondaryStoreObserver observer = builder.buildObserver(cache);
         primary.addObserver(observer);
 
         return cache;
     }
 
+    private SecondaryStoreBuilder createBuilder(PathFilter pathFilter) {
+        return new SecondaryStoreBuilder(secondary).pathFilter(pathFilter);
+    }
+
     private AbstractDocumentNodeState merge(NodeBuilder nb) throws 
CommitFailedException {
         return (AbstractDocumentNodeState) primary.merge(nb, 
EmptyHook.INSTANCE, CommitInfo.EMPTY);
     }

Modified: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreObserverTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreObserverTest.java?rev=1749441&r1=1749440&r2=1749441&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreObserverTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreObserverTest.java
 Tue Jun 21 06:21:05 2016
@@ -62,7 +62,7 @@ public class SecondaryStoreObserverTest
     @Test
     public void basicSetup() throws Exception{
         PathFilter pathFilter = new PathFilter(of("/a"), empty);
-        SecondaryStoreObserver observer = new 
SecondaryStoreObserver(secondary, pathFilter, NodeStateDiffer.DEFAULT_DIFFER);
+        SecondaryStoreObserver observer = 
createBuilder(pathFilter).buildObserver();
         primary.addObserver(observer);
 
         NodeBuilder nb = primary.getRoot().builder();
@@ -78,7 +78,7 @@ public class SecondaryStoreObserverTest
     @Test
     public void childNodeAdded() throws Exception{
         PathFilter pathFilter = new PathFilter(of("/a"), empty);
-        SecondaryStoreObserver observer = new 
SecondaryStoreObserver(secondary, pathFilter, NodeStateDiffer.DEFAULT_DIFFER);
+        SecondaryStoreObserver observer = 
createBuilder(pathFilter).buildObserver();
         primary.addObserver(observer);
 
         NodeBuilder nb = primary.getRoot().builder();
@@ -96,7 +96,7 @@ public class SecondaryStoreObserverTest
     @Test
     public void childNodeChangedAndExclude() throws Exception{
         PathFilter pathFilter = new PathFilter(of("/a"), of("a/b"));
-        SecondaryStoreObserver observer = new 
SecondaryStoreObserver(secondary, pathFilter, NodeStateDiffer.DEFAULT_DIFFER);
+        SecondaryStoreObserver observer = 
createBuilder(pathFilter).buildObserver();
         primary.addObserver(observer);
 
         NodeBuilder nb = primary.getRoot().builder();
@@ -113,7 +113,7 @@ public class SecondaryStoreObserverTest
     @Test
     public void childNodeDeleted() throws Exception{
         PathFilter pathFilter = new PathFilter(of("/a"), empty);
-        SecondaryStoreObserver observer = new 
SecondaryStoreObserver(secondary, pathFilter, NodeStateDiffer.DEFAULT_DIFFER);
+        SecondaryStoreObserver observer = 
createBuilder(pathFilter).buildObserver();
         primary.addObserver(observer);
 
         NodeBuilder nb = primary.getRoot().builder();
@@ -131,6 +131,11 @@ public class SecondaryStoreObserverTest
         return DelegatingDocumentNodeState.wrap(secondary.getRoot(), 
NodeStateDiffer.DEFAULT_DIFFER);
     }
 
+    private SecondaryStoreBuilder createBuilder(PathFilter pathFilter) {
+        return new SecondaryStoreBuilder(secondary).pathFilter(pathFilter);
+    }
+
+
     private static void assertMetaState(NodeState root1, NodeState root2, 
String path){
         assertMetaState(documentState(root1, path), documentState(root2, 
path));
     }


Reply via email to