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 <[email protected]> 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 <[email protected]> Reviewed-by: Ali Alsuliman <[email protected]> Integration-Tests: Jenkins <[email protected]> Tested-by: Jenkins <[email protected]> --- .../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); + } + } +}
