You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by mb...@apache.org on 2025/09/20 12:24:07 UTC
(asterixdb) 05/27: [NO ISSUE][*HYR][MISC] += Lazy helper for deferred initialization
This is an automated email from the ASF dual-hosted git repository.
mblow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git
commit 15067de0e0de840eb8f8e421696f79171c445484
Author: Michael Blow <mi...@couchbase.com>
AuthorDate: Wed Sep 3 16:32:47 2025 -0400
[NO ISSUE][*HYR][MISC] += Lazy helper for deferred initialization
Ext-ref: MB-68256
Change-Id: I9912c03cf3949dae86eb8af4f159143f660061d4
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/20287
Reviewed-by: Michael Blow <mb...@apache.org>
Reviewed-by: Ali Alsuliman <al...@gmail.com>
Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
---
.../java/org/apache/hyracks/api/util/Lazy.java | 43 ++++++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/Lazy.java b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/Lazy.java
new file mode 100644
index 0000000000..28dbf75a3c
--- /dev/null
+++ b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/util/Lazy.java
@@ -0,0 +1,43 @@
+/*
+ * 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.hyracks.api.util;
+
+import java.util.concurrent.FutureTask;
+import java.util.function.Supplier;
+
+/**
+ * A thread-safe lazy initializer.
+ * @param <T>
+ */
+public class Lazy<T> {
+ private final FutureTask<T> task;
+
+ public Lazy(Supplier<T> supplier) {
+ this.task = new FutureTask<>(supplier::get);
+ }
+
+ public T get() {
+ task.run(); // idempotent
+ try {
+ return task.get();
+ } catch (Exception e) {
+ throw new RuntimeException("Lazy initialization failed", e);
+ }
+ }
+}