smengcl commented on code in PR #4315: URL: https://github.com/apache/ozone/pull/4315#discussion_r1125275742
########## hadoop-hdds/rocks-native/src/main/java/org/apache/hadoop/hdds/utils/NativeLibraryLoader.java: ########## @@ -0,0 +1,138 @@ +/* + * 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.hadoop.hdds.utils; + + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Class to load Native Libraries. + */ +public class NativeLibraryLoader { + private static final String OS = System.getProperty("os.name").toLowerCase(); + private Map<String, Boolean> librariesLoaded; + private static volatile NativeLibraryLoader instance; + + public NativeLibraryLoader(final Map<String, Boolean> librariesLoaded) { + this.librariesLoaded = librariesLoaded; + } + + private static synchronized void initNewInstance() { + if (instance == null) { + instance = new NativeLibraryLoader(new ConcurrentHashMap<>()); + } + } + + public static NativeLibraryLoader getInstance() { + if (instance == null) { + initNewInstance(); + } + return instance; + } + + public static String getJniLibraryFileName(String libraryName) { + return appendLibOsSuffix("lib" + libraryName); + } + + public static boolean isMac() { + return OS.contains("mac"); + } + + public static boolean isWindows() { + return OS.contains("win"); + } + + private static String getLibOsSuffix() { + if (isMac()) { + return ".dylib"; + } else if (isWindows()) { + return ".dll"; + } + return ".so"; Review Comment: Better have explicit check for Linux rather than making it the default. Reject if OS name is unknown. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
