diff --git a/hbase-noop-htrace/pom.xml b/hbase-noop-htrace/pom.xml
index 2cab03c..114bcfd 100644
--- a/hbase-noop-htrace/pom.xml
+++ b/hbase-noop-htrace/pom.xml
@@ -96,6 +96,10 @@
true
+
+ org.apache.maven.plugins
+ maven-source-plugin
+
diff --git a/hbase-unsafe/pom.xml b/hbase-unsafe/pom.xml
index 555b54f..a621f99 100644
--- a/hbase-unsafe/pom.xml
+++ b/hbase-unsafe/pom.xml
@@ -87,6 +87,10 @@
true
+
+ org.apache.maven.plugins
+ maven-source-plugin
+
diff --git a/hbase-unsafe/src/main/java/org/apache/hadoop/hbase/unsafe/HBaseUnsafe.java b/hbase-unsafe/src/main/java/org/apache/hadoop/hbase/unsafe/HBasePlatformDependent.java
similarity index 94%
rename from hbase-unsafe/src/main/java/org/apache/hadoop/hbase/unsafe/HBaseUnsafe.java
rename to hbase-unsafe/src/main/java/org/apache/hadoop/hbase/unsafe/HBasePlatformDependent.java
index aa142b9..ffb07c5 100644
--- a/hbase-unsafe/src/main/java/org/apache/hadoop/hbase/unsafe/HBaseUnsafe.java
+++ b/hbase-unsafe/src/main/java/org/apache/hadoop/hbase/unsafe/HBasePlatformDependent.java
@@ -22,17 +22,19 @@
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.ProtectionDomain;
+import java.util.function.BiConsumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * Delegate all methods of {@link HBaseUnsafeInternal}, so we will not touch the actual
- * {@code sun.misc.Unsafe} class until we actually call the methods.
+ * Delegate all methods of {@link HBaseUnsafeInternal} and {@link HBaseSignalInternal} so we will
+ * not touch the actual {@code sun.misc.Unsafe} and {@code sun.misc.Signal} classes until we
+ * actually call the methods.
*/
-public final class HBaseUnsafe {
+public final class HBasePlatformDependent {
private static final String CLASS_NAME = "sun.misc.Unsafe";
- private static final Logger LOG = LoggerFactory.getLogger(HBaseUnsafe.class);
+ private static final Logger LOG = LoggerFactory.getLogger(HBasePlatformDependent.class);
private static final boolean AVAIL;
private static final boolean UNALIGNED;
@@ -174,9 +176,8 @@ private static boolean checkUnaligned() {
m.setAccessible(true);
return (Boolean) m.invoke(null);
} catch (Exception e) {
- LOG.warn("java.nio.Bits#unaligned() check failed."
- + "Unsafe based read/write of primitive types won't be used",
- e);
+ LOG.warn("java.nio.Bits#unaligned() check failed." +
+ "Unsafe based read/write of primitive types won't be used", e);
}
return false;
}
@@ -185,7 +186,7 @@ private static boolean checkUnaligned() {
* @return true when running JVM is having sun's Unsafe package available in it and it is
* accessible.
*/
- public static boolean isAvailable() {
+ public static boolean isUnsafeAvailable() {
return AVAIL;
}
@@ -197,7 +198,7 @@ public static boolean unaligned() {
return UNALIGNED;
}
- private HBaseUnsafe() {
+ private HBasePlatformDependent() {
// private constructor to avoid instantiation
}
@@ -354,7 +355,7 @@ public static void setMemory(long address, long bytes, byte value) {
}
public static void copyMemory(Object srcBase, long srcOffset, Object destBase, long destOffset,
- long bytes) {
+ long bytes) {
HBaseUnsafeInternal.copyMemory(srcBase, srcOffset, destBase, destOffset, bytes);
}
@@ -403,7 +404,7 @@ public static int pageSize() {
}
public static Class> defineClass(String name, byte[] b, int off, int len, ClassLoader loader,
- ProtectionDomain protectionDomain) {
+ ProtectionDomain protectionDomain) {
return HBaseUnsafeInternal.defineClass(name, b, off, len, loader, protectionDomain);
}
@@ -559,4 +560,13 @@ public static void fullFence() {
HBaseUnsafeInternal.fullFence();
}
+ /**
+ * Delegate {@code sun.misc.Signal}.
+ * @param signal the name of the signal, such as 'HUP'.
+ * @param handler the handler of the signal, the first parameter is the number of the signal,
+ * while the second one is the name of the sinal.
+ */
+ public static void handle(String signal, BiConsumer handler) {
+ HBaseSignalInternal.handle(signal, handler);
+ }
}
diff --git a/hbase-unsafe/src/main/java/org/apache/hadoop/hbase/unsafe/HBaseSignalInternal.java b/hbase-unsafe/src/main/java/org/apache/hadoop/hbase/unsafe/HBaseSignalInternal.java
new file mode 100644
index 0000000..cbd4f34
--- /dev/null
+++ b/hbase-unsafe/src/main/java/org/apache/hadoop/hbase/unsafe/HBaseSignalInternal.java
@@ -0,0 +1,35 @@
+/**
+ * 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.hbase.unsafe;
+
+import java.util.function.BiConsumer;
+import sun.misc.Signal;
+
+/**
+ * Delegation of {@code sun.misc.Signal}.
+ */
+@SuppressWarnings("restriction")
+public final class HBaseSignalInternal {
+
+ private HBaseSignalInternal() {
+ }
+
+ public static void handle(String signal, BiConsumer handler) {
+ Signal.handle(new Signal(signal), s -> handler.accept(s.getNumber(), s.getName()));
+ }
+}
diff --git a/hbase-unsafe/src/test/java/org/apache/hadoop/hbase/unsafe/TestHBaseUnsafe.java b/hbase-unsafe/src/test/java/org/apache/hadoop/hbase/unsafe/TestHBaseUnsafe.java
index 699996b..78cbcb6 100644
--- a/hbase-unsafe/src/test/java/org/apache/hadoop/hbase/unsafe/TestHBaseUnsafe.java
+++ b/hbase-unsafe/src/test/java/org/apache/hadoop/hbase/unsafe/TestHBaseUnsafe.java
@@ -26,10 +26,10 @@ public class TestHBaseUnsafe {
@Test
public void test() {
- assumeTrue(HBaseUnsafe.isAvailable());
+ assumeTrue(HBasePlatformDependent.isUnsafeAvailable());
byte[] arr = new byte[4];
- int arrayBaseOffset = HBaseUnsafe.arrayBaseOffset(arr.getClass());
- HBaseUnsafe.putInt(arr, arrayBaseOffset, 123456);
- assertEquals(123456, HBaseUnsafe.getInt(arr, arrayBaseOffset));
+ int arrayBaseOffset = HBasePlatformDependent.arrayBaseOffset(arr.getClass());
+ HBasePlatformDependent.putInt(arr, arrayBaseOffset, 123456);
+ assertEquals(123456, HBasePlatformDependent.getInt(arr, arrayBaseOffset));
}
}