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 re...@apache.org on 2025/08/18 11:11:16 UTC
(jackrabbit-oak) 01/01: OAK-11656: Remove usage of Guava Suppliers.memoize
This is an automated email from the ASF dual-hosted git repository.
reschke pushed a commit to branch OAK-11656
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
commit 3dfe0c24892f9e8ba39db25667ad60167bdff0b7
Author: Julian Reschke <ju...@gmx.de>
AuthorDate: Mon Aug 18 12:10:47 2025 +0100
OAK-11656: Remove usage of Guava Suppliers.memoize
---
.../oak/commons/pconcurrent/Suppliers.java | 48 ++++++++++++++++++++++
.../oak/commons/pconcurrent/package-info.java | 22 ++++++++++
.../index/property/PropertyIndexEditor.java | 2 +-
.../plugins/index/reference/ReferenceEditor.java | 3 +-
.../strategy/ContentMirrorStoreStrategyTest.java | 2 +-
.../strategy/UniqueEntryStoreStrategyTest.java | 2 +-
.../oak/run/osgi/RunnableJobTracker.java | 2 +-
.../jackrabbit/oak/segment/SegmentNodeState.java | 2 +-
.../jackrabbit/oak/segment/WriterCacheManager.java | 2 +-
.../plugins/document/DocumentNodeStoreBuilder.java | 4 +-
.../mongo/MongoDocumentNodeStoreBuilderBase.java | 2 +-
.../document/rdb/RDBDocumentNodeStoreBuilder.java | 2 +-
12 files changed, 81 insertions(+), 12 deletions(-)
diff --git a/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/pconcurrent/Suppliers.java b/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/pconcurrent/Suppliers.java
new file mode 100644
index 0000000000..b300faa420
--- /dev/null
+++ b/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/pconcurrent/Suppliers.java
@@ -0,0 +1,48 @@
+/*
+ * 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.commons.pconcurrent;
+
+import java.util.function.Supplier;
+
+public class Suppliers {
+
+ private Suppliers() {
+ }
+
+ /**
+ * Transforms a {@code Supplier} based on a wrapper around a lazily and only-tine
+ * single time evaluation of the given {@code Supplier}.
+ *
+ * @param <T> return type
+ * @return Supplier based on the given Supplier
+ */
+ public static <T> Supplier<T> memoize(final Supplier<T> computeOnce) {
+ return new Supplier<>() {
+ T result = null;
+
+ @Override
+ public synchronized T get() {
+ if (result == null) {
+ result = computeOnce.get();
+ }
+ return result;
+ }
+ };
+ }
+}
diff --git a/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/pconcurrent/package-info.java b/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/pconcurrent/package-info.java
new file mode 100644
index 0000000000..a8f2e9ced2
--- /dev/null
+++ b/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/pconcurrent/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+@Version("1.0.0")
+@Internal
+package org.apache.jackrabbit.oak.commons.pconcurrent;
+
+import org.apache.jackrabbit.oak.commons.annotations.Internal;
+import org.osgi.annotation.versioning.Version;
diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditor.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditor.java
index f843010e85..605eb1af20 100644
--- a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditor.java
+++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditor.java
@@ -16,7 +16,6 @@
*/
package org.apache.jackrabbit.oak.plugins.index.property;
-import static org.apache.jackrabbit.guava.common.base.Suppliers.memoize;
import static java.util.Collections.singleton;
import static org.apache.jackrabbit.JcrConstants.JCR_MIXINTYPES;
import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
@@ -24,6 +23,7 @@ import static org.apache.jackrabbit.oak.api.CommitFailedException.CONSTRAINT;
import static org.apache.jackrabbit.oak.api.Type.NAME;
import static org.apache.jackrabbit.oak.api.Type.NAMES;
import static org.apache.jackrabbit.oak.commons.PathUtils.concat;
+import static org.apache.jackrabbit.oak.commons.pconcurrent.Suppliers.memoize;
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.DECLARING_NODE_TYPES;
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_CONTENT_NODE_NAME;
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.PROPERTY_NAMES;
diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/reference/ReferenceEditor.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/reference/ReferenceEditor.java
index ae339d7ffb..fb86984293 100644
--- a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/reference/ReferenceEditor.java
+++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/reference/ReferenceEditor.java
@@ -16,8 +16,6 @@
*/
package org.apache.jackrabbit.oak.plugins.index.reference;
-import static org.apache.jackrabbit.guava.common.base.Suppliers.memoize;
-
import static java.util.Collections.emptySet;
import static javax.jcr.PropertyType.REFERENCE;
import static javax.jcr.PropertyType.WEAKREFERENCE;
@@ -27,6 +25,7 @@ import static org.apache.jackrabbit.oak.api.Type.STRING;
import static org.apache.jackrabbit.oak.api.Type.STRINGS;
import static org.apache.jackrabbit.oak.commons.PathUtils.concat;
import static org.apache.jackrabbit.oak.commons.PathUtils.isAbsolute;
+import static org.apache.jackrabbit.oak.commons.pconcurrent.Suppliers.memoize;
import static org.apache.jackrabbit.oak.plugins.index.reference.NodeReferenceConstants.REF_NAME;
import static org.apache.jackrabbit.oak.plugins.index.reference.NodeReferenceConstants.WEAK_REF_NAME;
import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.MISSING_NODE;
diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/ContentMirrorStoreStrategyTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/ContentMirrorStoreStrategyTest.java
index 5e56e0a426..e3d9091607 100644
--- a/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/ContentMirrorStoreStrategyTest.java
+++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/ContentMirrorStoreStrategyTest.java
@@ -18,7 +18,7 @@ package org.apache.jackrabbit.oak.plugins.index.property.strategy;
import static java.util.Arrays.asList;
-import static org.apache.jackrabbit.guava.common.base.Suppliers.memoize;
+import static org.apache.jackrabbit.oak.commons.pconcurrent.Suppliers.memoize;
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.ENTRY_COUNT_PROPERTY_NAME;
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_CONTENT_NODE_NAME;
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.KEY_COUNT_PROPERTY_NAME;
diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/UniqueEntryStoreStrategyTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/UniqueEntryStoreStrategyTest.java
index 9952b78633..c1cd10172a 100644
--- a/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/UniqueEntryStoreStrategyTest.java
+++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/strategy/UniqueEntryStoreStrategyTest.java
@@ -16,7 +16,7 @@
*/
package org.apache.jackrabbit.oak.plugins.index.property.strategy;
-import static org.apache.jackrabbit.guava.common.base.Suppliers.memoize;
+import static org.apache.jackrabbit.oak.commons.pconcurrent.Suppliers.memoize;
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_CONTENT_NODE_NAME;
import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
import static org.hamcrest.Matchers.containsInAnyOrder;
diff --git a/oak-pojosr/src/main/java/org/apache/jackrabbit/oak/run/osgi/RunnableJobTracker.java b/oak-pojosr/src/main/java/org/apache/jackrabbit/oak/run/osgi/RunnableJobTracker.java
index 02adefc769..3a1cc06700 100644
--- a/oak-pojosr/src/main/java/org/apache/jackrabbit/oak/run/osgi/RunnableJobTracker.java
+++ b/oak-pojosr/src/main/java/org/apache/jackrabbit/oak/run/osgi/RunnableJobTracker.java
@@ -43,7 +43,7 @@ public class RunnableJobTracker extends ServiceTracker<Runnable, Future>
* Lazily loaded executor
*/
private final Supplier<ScheduledExecutorService> executor =
- Suppliers.memoize(() -> Oak.defaultScheduledExecutor());
+ Suppliers.memoize(Oak::defaultScheduledExecutor);
public RunnableJobTracker(BundleContext context) {
super(context, createFilter(), null);
diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeState.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeState.java
index c546b16f13..2014756d6e 100644
--- a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeState.java
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeState.java
@@ -22,7 +22,6 @@ import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static java.util.Objects.requireNonNull;
import static org.apache.jackrabbit.oak.commons.conditions.Validate.checkArgument;
-import static org.apache.jackrabbit.guava.common.base.Suppliers.memoize;
import static org.apache.jackrabbit.JcrConstants.JCR_MIXINTYPES;
import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
import static org.apache.jackrabbit.oak.api.Type.BOOLEAN;
@@ -31,6 +30,7 @@ import static org.apache.jackrabbit.oak.api.Type.NAME;
import static org.apache.jackrabbit.oak.api.Type.NAMES;
import static org.apache.jackrabbit.oak.api.Type.STRING;
import static org.apache.jackrabbit.oak.api.Type.STRINGS;
+import static org.apache.jackrabbit.oak.commons.pconcurrent.Suppliers.memoize;
import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.MISSING_NODE;
import static org.apache.jackrabbit.oak.spi.state.AbstractNodeState.checkValidName;
diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/WriterCacheManager.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/WriterCacheManager.java
index 702e911ed1..524caaca82 100644
--- a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/WriterCacheManager.java
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/WriterCacheManager.java
@@ -19,8 +19,8 @@
package org.apache.jackrabbit.oak.segment;
import static java.util.Objects.requireNonNull;
-import static org.apache.jackrabbit.guava.common.base.Suppliers.memoize;
import static java.lang.Integer.getInteger;
+import static org.apache.jackrabbit.oak.commons.pconcurrent.Suppliers.memoize;
import static org.apache.jackrabbit.oak.segment.RecordCache.newRecordCache;
import java.util.Iterator;
diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBuilder.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBuilder.java
index c221769e21..666ee427e7 100644
--- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBuilder.java
+++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBuilder.java
@@ -35,7 +35,6 @@ import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
import java.util.function.Supplier;
-import org.apache.jackrabbit.guava.common.base.Suppliers;
import org.apache.jackrabbit.guava.common.cache.Cache;
import org.apache.jackrabbit.guava.common.cache.CacheBuilder;
import org.apache.jackrabbit.guava.common.cache.RemovalCause;
@@ -47,6 +46,7 @@ import org.apache.jackrabbit.oak.cache.CacheStats;
import org.apache.jackrabbit.oak.cache.CacheValue;
import org.apache.jackrabbit.oak.cache.EmpiricalWeigher;
import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.commons.pconcurrent.Suppliers;
import org.apache.jackrabbit.oak.plugins.blob.BlobStoreStats;
import org.apache.jackrabbit.oak.plugins.blob.CachingBlobStore;
import org.apache.jackrabbit.oak.plugins.blob.ReferencedBlob;
@@ -117,7 +117,7 @@ public class DocumentNodeStoreBuilder<T extends DocumentNodeStoreBuilder<T>> {
*/
static final int UPDATE_LIMIT = Integer.getInteger("update.limit", DEFAULT_UPDATE_LIMIT);
- protected Supplier<DocumentStore> documentStoreSupplier = Suppliers.memoize(() -> new MemoryDocumentStore());
+ protected Supplier<DocumentStore> documentStoreSupplier = Suppliers.memoize(MemoryDocumentStore::new);
protected Supplier<BlobStore> blobStoreSupplier;
private DiffCache diffCache;
private int clusterId = Integer.getInteger("oak.documentMK.clusterId", 0);
diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentNodeStoreBuilderBase.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentNodeStoreBuilderBase.java
index 7a636c5886..023be7eb8f 100644
--- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentNodeStoreBuilderBase.java
+++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentNodeStoreBuilderBase.java
@@ -32,7 +32,7 @@ import org.apache.jackrabbit.oak.plugins.document.VersionGCSupport;
import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection;
import org.jetbrains.annotations.NotNull;
-import static org.apache.jackrabbit.guava.common.base.Suppliers.memoize;
+import static org.apache.jackrabbit.oak.commons.pconcurrent.Suppliers.memoize;
import static org.apache.jackrabbit.oak.plugins.document.mongo.MongoDBConnection.newMongoDBConnection;
/**
diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentNodeStoreBuilder.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentNodeStoreBuilder.java
index cede15f1b7..f62bcb8f8c 100644
--- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentNodeStoreBuilder.java
+++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentNodeStoreBuilder.java
@@ -17,7 +17,7 @@
package org.apache.jackrabbit.oak.plugins.document.rdb;
import static java.util.Set.of;
-import static org.apache.jackrabbit.guava.common.base.Suppliers.memoize;
+import static org.apache.jackrabbit.oak.commons.pconcurrent.Suppliers.memoize;
import javax.sql.DataSource;