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 mr...@apache.org on 2017/06/15 14:08:48 UTC

svn commit: r1798836 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document: DocumentNodeStore.java DocumentNodeStoreMBeanImpl.java

Author: mreutegg
Date: Thu Jun 15 14:08:48 2017
New Revision: 1798836

URL: http://svn.apache.org/viewvc?rev=1798836&view=rev
Log:
OAK-6354: Move DocumentNodeStoreMBean implementation in separate file

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreMBeanImpl.java   (with props)
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java?rev=1798836&r1=1798835&r2=1798836&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java Thu Jun 15 14:08:48 2017
@@ -20,7 +20,6 @@ import static com.google.common.base.Pre
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.base.Preconditions.checkState;
 import static com.google.common.collect.Iterables.filter;
-import static com.google.common.collect.Iterables.toArray;
 import static com.google.common.collect.Iterables.transform;
 import static com.google.common.collect.Lists.newArrayList;
 import static com.google.common.collect.Lists.reverse;
@@ -45,7 +44,6 @@ import java.io.Closeable;
 import java.io.IOException;
 import java.io.InputStream;
 import java.lang.ref.WeakReference;
-import java.text.SimpleDateFormat;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -53,7 +51,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.SortedSet;
-import java.util.TimeZone;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.ExecutionException;
@@ -69,7 +66,6 @@ import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import javax.jcr.PropertyType;
 import javax.management.NotCompliantMBeanException;
-import javax.management.openmbean.CompositeData;
 
 import com.google.common.base.Function;
 import com.google.common.base.Predicate;
@@ -84,9 +80,7 @@ import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
 import com.google.common.util.concurrent.UncheckedExecutionException;
 
-import org.apache.jackrabbit.api.stats.TimeSeries;
 import org.apache.jackrabbit.oak.api.PropertyState;
-import org.apache.jackrabbit.oak.commons.jmx.AnnotatedStandardMBean;
 import org.apache.jackrabbit.oak.core.SimpleCommitContext;
 import org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob;
 import org.apache.jackrabbit.oak.plugins.blob.MarkSweepGarbageCollector;
@@ -126,10 +120,8 @@ import org.apache.jackrabbit.oak.spi.sta
 import org.apache.jackrabbit.oak.spi.state.NodeStateDiff;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
 import org.apache.jackrabbit.oak.stats.Clock;
-import org.apache.jackrabbit.oak.stats.StatisticsProvider;
 import org.apache.jackrabbit.oak.OakVersion;
 import org.apache.jackrabbit.oak.commons.benchmark.PerfLogger;
-import org.apache.jackrabbit.stats.TimeSeriesStatsUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -491,8 +483,6 @@ public final class DocumentNodeStore
 
     private final DocumentNodeStoreStatsCollector nodeStoreStatsCollector;
 
-    private final StatisticsProvider statisticsProvider;
-
     private final BundlingConfigHandler bundlingConfigHandler = new BundlingConfigHandler();
 
     private final BundledDocumentDiffer bundledDocDiffer = new BundledDocumentDiffer(this);
@@ -526,7 +516,6 @@ public final class DocumentNodeStore
             }
         });
         this.blobStore = builder.getBlobStore();
-        this.statisticsProvider = builder.getStatisticsProvider();
         this.nodeStoreStatsCollector = builder.getNodeStoreStatsCollector();
         if (builder.isUseSimpleRevision()) {
             this.simpleRevisionCounter = new AtomicInteger(0);
@@ -707,7 +696,7 @@ public final class DocumentNodeStore
         }
         journalCache = builder.getJournalCache();
 
-        this.mbean = createMBean();
+        this.mbean = createMBean(builder);
         LOG.info("ChangeSetBuilder enabled and size set to maxItems: {}, maxDepth: {}", changeSetMaxItems, changeSetMaxDepth);
         LOG.info("Initialized DocumentNodeStore with clusterNodeId: {}, updateLimit: {} ({})",
                 clusterId, updateLimit,
@@ -2939,144 +2928,20 @@ public final class DocumentNodeStore
         }
     }
 
-    //-----------------------------< DocumentNodeStoreMBean >---------------------------------
-
     public DocumentNodeStoreMBean getMBean() {
         return mbean;
     }
 
-    private DocumentNodeStoreMBean createMBean(){
+    private DocumentNodeStoreMBean createMBean(DocumentMK.Builder builder) {
         try {
-            return new MBeanImpl();
+            return new DocumentNodeStoreMBeanImpl(this,
+                    builder.getStatisticsProvider().getStats(),
+                    clusterNodes.values());
         } catch (NotCompliantMBeanException e) {
             throw new IllegalStateException(e);
         }
     }
 
-    private class MBeanImpl extends AnnotatedStandardMBean implements DocumentNodeStoreMBean {
-        private final String ISO_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS zzz";
-        private final TimeZone TZ_UTC = TimeZone.getTimeZone("UTC");
-
-        protected MBeanImpl() throws NotCompliantMBeanException {
-            super(DocumentNodeStoreMBean.class);
-        }
-
-        @Override
-        public String getRevisionComparatorState() {
-            return "";
-        }
-
-        @Override
-        public String getHead(){
-            return getRoot().getRootRevision().toString();
-        }
-
-        @Override
-        public int getClusterId() {
-            return clusterId;
-        }
-
-        @Override
-        public int getUnmergedBranchCount() {
-            return branches.size();
-        }
-
-        @Override
-        public String[] getInactiveClusterNodes() {
-            return toArray(transform(filter(clusterNodes.values(),
-                    new Predicate<ClusterNodeInfoDocument>() {
-                        @Override
-                        public boolean apply(ClusterNodeInfoDocument input) {
-                            return !input.isActive();
-                        }
-                    }),
-                    new Function<ClusterNodeInfoDocument, String>() {
-                        @Override
-                        public String apply(ClusterNodeInfoDocument input) {
-                            return input.getClusterId() + "=" + input.getCreated();
-                        }
-                    }), String.class);
-        }
-
-        @Override
-        public String[] getActiveClusterNodes() {
-            return toArray(transform(filter(clusterNodes.values(),
-                    new Predicate<ClusterNodeInfoDocument>() {
-                        @Override
-                        public boolean apply(ClusterNodeInfoDocument input) {
-                            return input.isActive();
-                        }
-                    }),
-                    new Function<ClusterNodeInfoDocument, String>() {
-                        @Override
-                        public String apply(ClusterNodeInfoDocument input) {
-                            return input.getClusterId() + "=" + input.getLeaseEndTime();
-                        }
-                    }), String.class);
-        }
-
-        @Override
-        public String[] getLastKnownRevisions() {
-            return toArray(transform(filter(getHeadRevision(), new Predicate<Revision>() {
-                        @Override
-                        public boolean apply(Revision input) {
-                            return input.getClusterId() != getClusterId();
-                        }
-                    }),
-                    new Function<Revision, String>() {
-                        @Override
-                        public String apply(Revision input) {
-                            return input.getClusterId() + "=" + input.toString();
-                        }
-                    }), String.class);
-        }
-
-        @Override
-        public String formatRevision(String rev, boolean utc){
-            Revision r = Revision.fromString(rev);
-            final SimpleDateFormat sdf = new SimpleDateFormat(ISO_FORMAT);
-            if (utc) {
-                sdf.setTimeZone(TZ_UTC);
-            }
-            return sdf.format(r.getTimestamp());
-        }
-
-        @Override
-        public long determineServerTimeDifferenceMillis() {
-            return store.determineServerTimeDifferenceMillis();
-        }
-
-        @Override
-        public CompositeData getMergeSuccessHistory() {
-            return getTimeSeriesData(DocumentNodeStoreStats.MERGE_SUCCESS_COUNT, "Merge Success Count");
-        }
-
-        @Override
-        public CompositeData getMergeFailureHistory() {
-            return getTimeSeriesData(DocumentNodeStoreStats.MERGE_FAILED_EXCLUSIVE, "Merge failure count");
-        }
-
-        @Override
-        public CompositeData getExternalChangeCountHistory() {
-            return getTimeSeriesData(DocumentNodeStoreStats.BGR_NUM_CHANGES_RATE, "Count of nodes modified by other " +
-                    "cluster nodes since last background read");
-        }
-
-        @Override
-        public CompositeData getBackgroundUpdateCountHistory() {
-            return getTimeSeriesData(DocumentNodeStoreStats.BGW_NUM_WRITES_RATE, "Count of nodes updated as part of " +
-                    "background update");
-        }
-
-        private CompositeData getTimeSeriesData(String name, String desc){
-            return TimeSeriesStatsUtil.asCompositeData(getTimeSeries(name), desc);
-        }
-
-        private TimeSeries getTimeSeries(String name) {
-            return statisticsProvider.getStats().getTimeSeries(name, true);
-        }
-    }
-
     private static abstract class NodeStoreTask implements Runnable {
         final WeakReference<DocumentNodeStore> ref;
         private final AtomicBoolean isDisposed;

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreMBeanImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreMBeanImpl.java?rev=1798836&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreMBeanImpl.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreMBeanImpl.java Thu Jun 15 14:08:48 2017
@@ -0,0 +1,175 @@
+/*
+ * 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;
+
+import java.text.SimpleDateFormat;
+import java.util.TimeZone;
+
+import javax.management.NotCompliantMBeanException;
+import javax.management.openmbean.CompositeData;
+
+import com.google.common.base.Function;
+import com.google.common.base.Predicate;
+
+import org.apache.jackrabbit.api.stats.RepositoryStatistics;
+import org.apache.jackrabbit.api.stats.TimeSeries;
+import org.apache.jackrabbit.oak.commons.jmx.AnnotatedStandardMBean;
+import org.apache.jackrabbit.stats.TimeSeriesStatsUtil;
+
+import static com.google.common.collect.Iterables.filter;
+import static com.google.common.collect.Iterables.toArray;
+import static com.google.common.collect.Iterables.transform;
+
+/**
+ * Implementation of a DocumentNodeStoreMBean.
+ */
+final class DocumentNodeStoreMBeanImpl extends AnnotatedStandardMBean implements DocumentNodeStoreMBean {
+
+    private static final String ISO_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS zzz";
+    private static final TimeZone TZ_UTC = TimeZone.getTimeZone("UTC");
+
+    private final DocumentNodeStore nodeStore;
+    private final RepositoryStatistics repoStats;
+    private final Iterable<ClusterNodeInfoDocument> clusterNodes;
+
+    DocumentNodeStoreMBeanImpl(DocumentNodeStore nodeStore,
+                               RepositoryStatistics repoStats,
+                               Iterable<ClusterNodeInfoDocument> clusterNodes)
+            throws NotCompliantMBeanException {
+        super(DocumentNodeStoreMBean.class);
+        this.nodeStore = nodeStore;
+        this.repoStats = repoStats;
+        this.clusterNodes = clusterNodes;
+    }
+
+    @Override
+    public String getRevisionComparatorState() {
+        return "";
+    }
+
+    @Override
+    public String getHead() {
+        return nodeStore.getHeadRevision().toString();
+    }
+
+    @Override
+    public int getClusterId() {
+        return nodeStore.getClusterId();
+    }
+
+    @Override
+    public int getUnmergedBranchCount() {
+        return nodeStore.getBranches().size();
+    }
+
+    @Override
+    public String[] getInactiveClusterNodes() {
+        return toArray(transform(filter(clusterNodes,
+                new Predicate<ClusterNodeInfoDocument>() {
+            @Override
+            public boolean apply(ClusterNodeInfoDocument input) {
+                return !input.isActive();
+            }
+        }), new Function<ClusterNodeInfoDocument, String>() {
+            @Override
+            public String apply(ClusterNodeInfoDocument input) {
+                return input.getClusterId() + "=" + input.getCreated();
+            }
+        }), String.class);
+    }
+
+    @Override
+    public String[] getActiveClusterNodes() {
+        return toArray(transform(filter(clusterNodes,
+                new Predicate<ClusterNodeInfoDocument>() {
+            @Override
+            public boolean apply(ClusterNodeInfoDocument input) {
+                return input.isActive();
+            }
+        }), new Function<ClusterNodeInfoDocument, String>() {
+            @Override
+            public String apply(ClusterNodeInfoDocument input) {
+                return input.getClusterId() + "=" + input.getLeaseEndTime();
+            }
+        }), String.class);
+    }
+
+    @Override
+    public String[] getLastKnownRevisions() {
+        return toArray(transform(filter(nodeStore.getHeadRevision(),
+                new Predicate<Revision>() {
+            @Override
+            public boolean apply(Revision input) {
+                return input.getClusterId() != getClusterId();
+            }
+        }), new Function<Revision, String>() {
+            @Override
+            public String apply(Revision input) {
+                return input.getClusterId() + "=" + input.toString();
+            }
+        }), String.class);
+    }
+
+    @Override
+    public String formatRevision(String rev, boolean utc) {
+        Revision r = Revision.fromString(rev);
+        final SimpleDateFormat sdf = new SimpleDateFormat(ISO_FORMAT);
+        if (utc) {
+            sdf.setTimeZone(TZ_UTC);
+        }
+        return sdf.format(r.getTimestamp());
+    }
+
+    @Override
+    public long determineServerTimeDifferenceMillis() {
+        return nodeStore.getDocumentStore().determineServerTimeDifferenceMillis();
+    }
+
+    @Override
+    public CompositeData getMergeSuccessHistory() {
+        return getTimeSeriesData(DocumentNodeStoreStats.MERGE_SUCCESS_COUNT,
+                "Merge Success Count");
+    }
+
+    @Override
+    public CompositeData getMergeFailureHistory() {
+        return getTimeSeriesData(DocumentNodeStoreStats.MERGE_FAILED_EXCLUSIVE,
+                "Merge failure count");
+    }
+
+    @Override
+    public CompositeData getExternalChangeCountHistory() {
+        return getTimeSeriesData(DocumentNodeStoreStats.BGR_NUM_CHANGES_RATE,
+                "Count of nodes modified by other " +
+                        "cluster nodes since last background read");
+    }
+
+    @Override
+    public CompositeData getBackgroundUpdateCountHistory() {
+        return getTimeSeriesData(DocumentNodeStoreStats.BGW_NUM_WRITES_RATE,
+                "Count of nodes updated as part of " +
+                        "background update");
+    }
+
+    private CompositeData getTimeSeriesData(String name, String desc) {
+        return TimeSeriesStatsUtil.asCompositeData(getTimeSeries(name), desc);
+    }
+
+    private TimeSeries getTimeSeries(String name) {
+        return repoStats.getTimeSeries(name, true);
+    }
+}

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