Author: frm
Date: Tue Apr 26 14:13:45 2016
New Revision: 1741034
URL: http://svn.apache.org/viewvc?rev=1741034&view=rev
Log:
OAK-4310 - Avoid instanceof checks in SegmentDiscoveryLiteService
Added:
jackrabbit/oak/trunk/oak-segment-next/src/main/java/org/apache/jackrabbit/oak/segment/SegmentDiscoveryLiteDescriptors.java
(with props)
jackrabbit/oak/trunk/oak-segment/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentDiscoveryLiteDescriptors.java
(with props)
Removed:
jackrabbit/oak/trunk/oak-segment-next/src/main/java/org/apache/jackrabbit/oak/segment/SegmentDiscoveryLiteService.java
jackrabbit/oak/trunk/oak-segment/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentDiscoveryLiteService.java
Modified:
jackrabbit/oak/trunk/oak-segment-next/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreService.java
jackrabbit/oak/trunk/oak-segment/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java
Added:
jackrabbit/oak/trunk/oak-segment-next/src/main/java/org/apache/jackrabbit/oak/segment/SegmentDiscoveryLiteDescriptors.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-next/src/main/java/org/apache/jackrabbit/oak/segment/SegmentDiscoveryLiteDescriptors.java?rev=1741034&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-segment-next/src/main/java/org/apache/jackrabbit/oak/segment/SegmentDiscoveryLiteDescriptors.java
(added)
+++
jackrabbit/oak/trunk/oak-segment-next/src/main/java/org/apache/jackrabbit/oak/segment/SegmentDiscoveryLiteDescriptors.java
Tue Apr 26 14:13:45 2016
@@ -0,0 +1,92 @@
+/*
+ * 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;
+
+import javax.jcr.Value;
+
+import org.apache.jackrabbit.commons.SimpleValueFactory;
+import org.apache.jackrabbit.oak.api.Descriptors;
+import org.apache.jackrabbit.oak.plugins.identifier.ClusterRepositoryInfo;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
+
+/**
+ * This provides the 'clusterView' repository descriptors
+ **/
+class SegmentDiscoveryLiteDescriptors implements Descriptors {
+
+ /**
+ * Name of the repository descriptor via which the clusterView is
published - which is the raison d'etre of the
+ * DocumentDiscoveryLiteService TODO: move this constant to a generic
place for both segment and document
+ **/
+ private static final String OAK_DISCOVERYLITE_CLUSTERVIEW =
"oak.discoverylite.clusterview";
+
+ private final SimpleValueFactory factory = new SimpleValueFactory();
+
+ private final NodeStore store;
+
+ SegmentDiscoveryLiteDescriptors(NodeStore store) {
+ this.store = store;
+ }
+
+ @Override
+ public String[] getKeys() {
+ return new String[] {OAK_DISCOVERYLITE_CLUSTERVIEW};
+ }
+
+ @Override
+ public boolean isStandardDescriptor(String key) {
+ return OAK_DISCOVERYLITE_CLUSTERVIEW.equals(key);
+ }
+
+ @Override
+ public boolean isSingleValueDescriptor(String key) {
+ return OAK_DISCOVERYLITE_CLUSTERVIEW.equals(key);
+ }
+
+ @Override
+ public Value getValue(String key) {
+ if (!OAK_DISCOVERYLITE_CLUSTERVIEW.equals(key)) {
+ return null;
+ }
+ return factory.createValue(getClusterViewAsDescriptorValue());
+ }
+
+ @Override
+ public Value[] getValues(String key) {
+ if (!OAK_DISCOVERYLITE_CLUSTERVIEW.equals(key)) {
+ return null;
+ }
+ return new Value[] {getValue(key)};
+ }
+
+ private String getClusterViewAsDescriptorValue() {
+ // since currently segment node store is not running in a cluster
+ // we can hard-code a single-vm descriptor here:
+ //
{"seq":4,"final":true,"me":1,"active":[1],"deactivating":[],"inactive":[2]}
+ // OAK-3672 : 'id' is now allowed to be null (supported by upper
layers),
+ // and for tarMk we're doing exactly that (id==null) -
indicating
+ // to upper layers that we're not really in a cluster and
that
+ // this low level descriptor doesn't manage the 'cluster
id'
+ // in such a case.
+ // OAK-4006: but ClusterRepositoryInfo now provides a persistent
clusterId,
+ // so that is now used also for discovery-lite via exactly
below 'id'
+ String clusterId = ClusterRepositoryInfo.getOrCreateId(store);
+ return "{\"seq\":1,\"final\":true,\"me\":1,\"id\":\"" + clusterId +
"\",\"active\":[1],\"deactivating\":[],\"inactive\":[]}";
+ }
+
+}
Propchange:
jackrabbit/oak/trunk/oak-segment-next/src/main/java/org/apache/jackrabbit/oak/segment/SegmentDiscoveryLiteDescriptors.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
jackrabbit/oak/trunk/oak-segment-next/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreService.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-next/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreService.java?rev=1741034&r1=1741033&r2=1741034&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-segment-next/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreService.java
(original)
+++
jackrabbit/oak/trunk/oak-segment-next/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreService.java
Tue Apr 26 14:13:45 2016
@@ -236,6 +236,8 @@ public class SegmentNodeStoreService ext
private WhiteboardExecutor executor;
private boolean customBlobStore;
+ private Registration discoveryLiteDescriptorRegistration;
+
/**
* Blob modified before this time duration would be considered for Blob GC
*/
@@ -475,6 +477,13 @@ public class SegmentNodeStoreService ext
ClusterRepositoryInfo.getOrCreateId(segmentNodeStore)), true, false);
whiteboard.register(Descriptors.class, clusterIdDesc,
Collections.emptyMap());
+ // Register "discovery lite" descriptors
+ discoveryLiteDescriptorRegistration = whiteboard.register(
+ Descriptors.class,
+ new SegmentDiscoveryLiteDescriptors(segmentNodeStore),
+ Collections.emptyMap()
+ );
+
// If a shared data store register the repo id in the data store
String repoId = "";
if (SharedDataStoreUtils.isShared(blobStore)) {
@@ -510,6 +519,10 @@ public class SegmentNodeStoreService ext
}
private void unregisterNodeStore() {
+ if (discoveryLiteDescriptorRegistration != null) {
+ discoveryLiteDescriptorRegistration.unregister();
+ discoveryLiteDescriptorRegistration = null;
+ }
if (segmentCacheMBean != null) {
segmentCacheMBean.unregister();
segmentCacheMBean = null;
@@ -518,11 +531,11 @@ public class SegmentNodeStoreService ext
stringCacheMBean.unregister();
stringCacheMBean = null;
}
- if(providerRegistration != null){
+ if (providerRegistration != null) {
providerRegistration.unregister();
providerRegistration = null;
}
- if(storeRegistration != null){
+ if (storeRegistration != null) {
storeRegistration.unregister();
storeRegistration = null;
}
Added:
jackrabbit/oak/trunk/oak-segment/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentDiscoveryLiteDescriptors.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentDiscoveryLiteDescriptors.java?rev=1741034&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-segment/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentDiscoveryLiteDescriptors.java
(added)
+++
jackrabbit/oak/trunk/oak-segment/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentDiscoveryLiteDescriptors.java
Tue Apr 26 14:13:45 2016
@@ -0,0 +1,92 @@
+/*
+ * 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.segment;
+
+import javax.jcr.Value;
+
+import org.apache.jackrabbit.commons.SimpleValueFactory;
+import org.apache.jackrabbit.oak.api.Descriptors;
+import org.apache.jackrabbit.oak.plugins.identifier.ClusterRepositoryInfo;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
+
+/**
+ * This provides the 'clusterView' repository descriptors
+ **/
+class SegmentDiscoveryLiteDescriptors implements Descriptors {
+
+ /**
+ * Name of the repository descriptor via which the clusterView is
published - which is the raison d'etre of the
+ * DocumentDiscoveryLiteService TODO: move this constant to a generic
place for both segment and document
+ **/
+ private static final String OAK_DISCOVERYLITE_CLUSTERVIEW =
"oak.discoverylite.clusterview";
+
+ private final SimpleValueFactory factory = new SimpleValueFactory();
+
+ private final NodeStore store;
+
+ SegmentDiscoveryLiteDescriptors(NodeStore store) {
+ this.store = store;
+ }
+
+ @Override
+ public String[] getKeys() {
+ return new String[] {OAK_DISCOVERYLITE_CLUSTERVIEW};
+ }
+
+ @Override
+ public boolean isStandardDescriptor(String key) {
+ return OAK_DISCOVERYLITE_CLUSTERVIEW.equals(key);
+ }
+
+ @Override
+ public boolean isSingleValueDescriptor(String key) {
+ return OAK_DISCOVERYLITE_CLUSTERVIEW.equals(key);
+ }
+
+ @Override
+ public Value getValue(String key) {
+ if (!OAK_DISCOVERYLITE_CLUSTERVIEW.equals(key)) {
+ return null;
+ }
+ return factory.createValue(getClusterViewAsDescriptorValue());
+ }
+
+ @Override
+ public Value[] getValues(String key) {
+ if (!OAK_DISCOVERYLITE_CLUSTERVIEW.equals(key)) {
+ return null;
+ }
+ return new Value[] {getValue(key)};
+ }
+
+ private String getClusterViewAsDescriptorValue() {
+ // since currently segment node store is not running in a cluster
+ // we can hard-code a single-vm descriptor here:
+ //
{"seq":4,"final":true,"me":1,"active":[1],"deactivating":[],"inactive":[2]}
+ // OAK-3672 : 'id' is now allowed to be null (supported by upper
layers),
+ // and for tarMk we're doing exactly that (id==null) -
indicating
+ // to upper layers that we're not really in a cluster and
that
+ // this low level descriptor doesn't manage the 'cluster
id'
+ // in such a case.
+ // OAK-4006: but ClusterRepositoryInfo now provides a persistent
clusterId,
+ // so that is now used also for discovery-lite via exactly
below 'id'
+ String clusterId = ClusterRepositoryInfo.getOrCreateId(store);
+ return "{\"seq\":1,\"final\":true,\"me\":1,\"id\":\"" + clusterId +
"\",\"active\":[1],\"deactivating\":[],\"inactive\":[]}";
+ }
+
+}
Propchange:
jackrabbit/oak/trunk/oak-segment/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentDiscoveryLiteDescriptors.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
jackrabbit/oak/trunk/oak-segment/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java?rev=1741034&r1=1741033&r2=1741034&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-segment/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java
(original)
+++
jackrabbit/oak/trunk/oak-segment/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java
Tue Apr 26 14:13:45 2016
@@ -280,6 +280,8 @@ public class SegmentNodeStoreService ext
private WhiteboardExecutor executor;
private boolean customBlobStore;
+ private Registration discoveryLiteDescriptorRegistration;
+
/**
* Blob modified before this time duration would be considered for Blob GC
*/
@@ -548,6 +550,13 @@ public class SegmentNodeStoreService ext
ClusterRepositoryInfo.getOrCreateId(segmentNodeStore)), true, false);
whiteboard.register(Descriptors.class, clusterIdDesc,
Collections.emptyMap());
+ // Register "discovery lite" descriptors
+ discoveryLiteDescriptorRegistration = whiteboard.register(
+ Descriptors.class,
+ new SegmentDiscoveryLiteDescriptors(segmentNodeStore),
+ Collections.emptyMap()
+ );
+
// If a shared data store register the repo id in the data store
String repoId = "";
if (SharedDataStoreUtils.isShared(blobStore)) {
@@ -583,6 +592,10 @@ public class SegmentNodeStoreService ext
}
private void unregisterNodeStore() {
+ if (discoveryLiteDescriptorRegistration != null) {
+ discoveryLiteDescriptorRegistration.unregister();
+ discoveryLiteDescriptorRegistration = null;
+ }
if (segmentCacheMBean != null) {
segmentCacheMBean.unregister();
segmentCacheMBean = null;
@@ -591,11 +604,11 @@ public class SegmentNodeStoreService ext
stringCacheMBean.unregister();
stringCacheMBean = null;
}
- if(providerRegistration != null){
+ if (providerRegistration != null) {
providerRegistration.unregister();
providerRegistration = null;
}
- if(storeRegistration != null){
+ if (storeRegistration != null) {
storeRegistration.unregister();
storeRegistration = null;
}