You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by md...@apache.org on 2016/06/07 07:31:44 UTC

svn commit: r1747157 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/spi/gc/ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/compaction/ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/

Author: mduerig
Date: Tue Jun  7 07:31:43 2016
New Revision: 1747157

URL: http://svn.apache.org/viewvc?rev=1747157&view=rev
Log:
OAK-4283: Align GCMonitor API with implementation
Refactor delegating gcmonitor and logging gcmonitor

Added:
    jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/compaction/LoggingGCMonitor.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/gc/DelegatingGCMonitor.java
    jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/gc/DelegatingGCMonitor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/gc/DelegatingGCMonitor.java?rev=1747157&r1=1747156&r2=1747157&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/gc/DelegatingGCMonitor.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/gc/DelegatingGCMonitor.java Tue Jun  7 07:31:43 2016
@@ -22,10 +22,12 @@ package org.apache.jackrabbit.oak.spi.gc
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.collect.Sets.newConcurrentHashSet;
 
+import java.util.Collection;
 import java.util.Set;
 
 import javax.annotation.Nonnull;
 
+import com.google.common.collect.Sets;
 import org.apache.jackrabbit.oak.spi.whiteboard.Registration;
 
 /**
@@ -33,7 +35,23 @@ import org.apache.jackrabbit.oak.spi.whi
  * to registered monitors.
  */
 public class DelegatingGCMonitor implements GCMonitor {
-    private final Set<GCMonitor> gcMonitors = newConcurrentHashSet();
+    private final Set<GCMonitor> gcMonitors;
+
+    /**
+     * New instance with an initial set of delegates (which cannot be unregistered).
+     * @param gcMonitors
+     */
+    public DelegatingGCMonitor(@Nonnull Collection<? extends GCMonitor> gcMonitors) {
+        this.gcMonitors = newConcurrentHashSet();
+        this.gcMonitors.addAll(gcMonitors);
+    }
+
+    /**
+     * New instance without any delegate.
+     */
+    public DelegatingGCMonitor() {
+        this(Sets.<GCMonitor>newConcurrentHashSet());
+    }
 
     /**
      * Register a {@link GCMonitor}.

Added: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/compaction/LoggingGCMonitor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/compaction/LoggingGCMonitor.java?rev=1747157&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/compaction/LoggingGCMonitor.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/compaction/LoggingGCMonitor.java Tue Jun  7 07:31:43 2016
@@ -0,0 +1,71 @@
+/*
+ * 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.segment.compaction;
+
+import org.apache.jackrabbit.oak.spi.gc.GCMonitor;
+import org.slf4j.Logger;
+
+/**
+ * This {@code GCMonitor} implementation logs all calls to its
+ * {@link #info(String, Object...)}, {@link #warn(String, Object...)},
+ * {@link #error(String, Exception)} and {@link #skipped(String, Object...)}
+ * methods at the respective levels using the logger instance passed to the
+ * constructor.
+ */
+public class LoggingGCMonitor implements GCMonitor {
+    private final Logger log;
+
+    /**
+     * New instance logging to {@code log}
+     * @param log
+     */
+    public LoggingGCMonitor(Logger log) {
+        this.log = log;
+    }
+
+    @Override
+    public void info(String message, Object... arguments) {
+        log.info(message, arguments);
+    }
+
+    @Override
+    public void warn(String message, Object... arguments) {
+        log.warn(message, arguments);
+    }
+
+    @Override
+    public void error(String message, Exception exception) {
+        log.error(message, exception);
+    }
+
+    @Override
+    public void skipped(String reason, Object... arguments) {
+        log.info(reason, arguments);
+    }
+
+    @Override
+    public void compacted(
+            long[] segmentCounts, long[] recordCounts, long[] compactionMapWeights) {
+    }
+
+    @Override
+    public void cleaned(long reclaimedSize, long currentSize) {
+    }
+}

Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java?rev=1747157&r1=1747156&r2=1747157&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java (original)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStore.java Tue Jun  7 07:31:43 2016
@@ -30,6 +30,7 @@ import static java.lang.String.format;
 import static java.lang.Thread.currentThread;
 import static java.nio.ByteBuffer.wrap;
 import static java.util.Collections.emptyMap;
+import static java.util.Collections.singleton;
 import static java.util.Collections.singletonMap;
 import static java.util.concurrent.TimeUnit.MILLISECONDS;
 import static java.util.concurrent.TimeUnit.MINUTES;
@@ -91,8 +92,10 @@ import org.apache.jackrabbit.oak.segment
 import org.apache.jackrabbit.oak.segment.SegmentTracker;
 import org.apache.jackrabbit.oak.segment.SegmentVersion;
 import org.apache.jackrabbit.oak.segment.SegmentWriter;
+import org.apache.jackrabbit.oak.segment.compaction.LoggingGCMonitor;
 import org.apache.jackrabbit.oak.segment.compaction.SegmentGCOptions;
 import org.apache.jackrabbit.oak.spi.blob.BlobStore;
+import org.apache.jackrabbit.oak.spi.gc.DelegatingGCMonitor;
 import org.apache.jackrabbit.oak.spi.gc.GCMonitor;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
@@ -247,7 +250,8 @@ public class FileStore implements Segmen
 
         private boolean memoryMapping;
 
-        private final LoggingGCMonitor gcMonitor = new LoggingGCMonitor();
+        private final DelegatingGCMonitor gcMonitor = new DelegatingGCMonitor(
+                singleton(new LoggingGCMonitor(log)));
 
         private StatisticsProvider statsProvider = StatisticsProvider.NOOP;
 
@@ -332,7 +336,7 @@ public class FileStore implements Segmen
          */
         @Nonnull
         public Builder withGCMonitor(@Nonnull GCMonitor gcMonitor) {
-            this.gcMonitor.delegatee = checkNotNull(gcMonitor);
+            this.gcMonitor.registerGCMonitor(checkNotNull(gcMonitor));
             return this;
         }
 
@@ -1605,40 +1609,4 @@ public class FileStore implements Segmen
         }
     }
 
-    private static class LoggingGCMonitor implements GCMonitor {
-        public GCMonitor delegatee = GCMonitor.EMPTY;
-
-        @Override
-        public void info(String message, Object... arguments) {
-            log.info(message, arguments);
-            delegatee.info(message, arguments);
-        }
-
-        @Override
-        public void warn(String message, Object... arguments) {
-            log.warn(message, arguments);
-            delegatee.warn(message, arguments);
-        }
-
-        @Override
-        public void error(String message, Exception exception) {
-            delegatee.error(message, exception);
-        }
-
-        @Override
-        public void skipped(String reason, Object... arguments) {
-            log.info(reason, arguments);
-            delegatee.skipped(reason, arguments);
-        }
-
-        @Override
-        public void compacted(long[] segmentCounts, long[] recordCounts, long[] compactionMapWeights) {
-            delegatee.compacted(segmentCounts, recordCounts, compactionMapWeights);
-        }
-
-        @Override
-        public void cleaned(long reclaimedSize, long currentSize) {
-            delegatee.cleaned(reclaimedSize, currentSize);
-        }
-    }
 }