tihom88 commented on code in PR #2234: URL: https://github.com/apache/jackrabbit-oak/pull/2234#discussion_r2066923850
########## oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/query/inference/InferenceConfig.java: ########## @@ -0,0 +1,231 @@ +/* + * 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.index.elastic.query.inference; + +import org.apache.jackrabbit.oak.commons.PathUtils; +import org.apache.jackrabbit.oak.plugins.index.IndexName; +import org.apache.jackrabbit.oak.query.QueryEngineSettings; +import org.apache.jackrabbit.oak.spi.query.QueryLimits; +import org.apache.jackrabbit.oak.spi.state.NodeState; +import org.apache.jackrabbit.oak.spi.state.NodeStore; +import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.nio.file.Path; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; +import java.util.function.Function; + +import static org.apache.jackrabbit.oak.plugins.index.search.util.ConfigUtil.getOptionalValue; + +/** + * Data model class representing the inference configuration stored under /oak:index/:inferenceConfig (default path) + */ +public class InferenceConfig { + private static final Logger LOG = LoggerFactory.getLogger(InferenceConfig.class.getName()); + private static final ReadWriteLock lock = new ReentrantReadWriteLock(true); + private static final InferenceConfig INSTANCE = new InferenceConfig(); + public static final String TYPE = "inferenceConfig"; + /** + * Semantic search is enabled if this flag is true + */ + private boolean enabled; + /** + * Map of index names to their respective inference configurations + */ + private Map<String, InferenceIndexConfig> indexConfigs; + private NodeStore nodeStore; + private String inferenceConfigPath; + private String currentInferenceConfig; + private volatile String activeInferenceConfig; + private boolean isInferenceEnabled; + + public boolean isInferenceEnabled() { + return isInferenceEnabled; + } + + /** + * Loads configuration from the given NodeState + * + * @return InferenceConfiguration instance + */ + + private InferenceConfig() { + lock.writeLock().lock(); + try { + if (INSTANCE == null) { Review Comment: The reason for complexity is because of multithreaded use of this object. To make it simple we are keeping one element as volatile to know if we need to reinitialize this config in a multi threaded environemt. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: oak-dev-unsubscr...@jackrabbit.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org