sentry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sp...@apache.org
Subject sentry git commit: SENTRY-2444: SigUtils signal handler needs a way to unregister functions. (Brian Towles, reviewed by Sergio Pena, Stephen Moist)
Date Mon, 03 Dec 2018 16:09:36 GMT
Repository: sentry
Updated Branches:
  refs/heads/master 0a609faba -> aeeb8ab5a


SENTRY-2444: SigUtils signal handler needs a way to unregister functions. (Brian Towles, reviewed
by Sergio Pena, Stephen Moist)


Project: http://git-wip-us.apache.org/repos/asf/sentry/repo
Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/aeeb8ab5
Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/aeeb8ab5
Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/aeeb8ab5

Branch: refs/heads/master
Commit: aeeb8ab5aaa749a12f43fcf639f95846985112e0
Parents: 0a609fa
Author: Sergio Pena <sergio.pena@cloudera.com>
Authored: Mon Dec 3 10:08:53 2018 -0600
Committer: Sergio Pena <sergio.pena@cloudera.com>
Committed: Mon Dec 3 10:08:53 2018 -0600

----------------------------------------------------------------------
 .../sentry/core/common/utils/SigUtils.java      | 24 +++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sentry/blob/aeeb8ab5/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/utils/SigUtils.java
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/utils/SigUtils.java
b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/utils/SigUtils.java
index d621c74..3c6c142 100644
--- a/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/utils/SigUtils.java
+++ b/sentry-core/sentry-core-common/src/main/java/org/apache/sentry/core/common/utils/SigUtils.java
@@ -20,6 +20,7 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
+import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import sun.misc.Signal;
@@ -64,6 +65,11 @@ public final class SigUtils {
     public void addListener(SigListener sigListener){
       listeners.add(sigListener);
     }
+
+    public void removeListener(SigListener sigListener){
+      listeners.remove(sigListener);
+    }
+
     @Override
     public void handle(Signal sig) {
       if (sig != null) {
@@ -96,12 +102,12 @@ public final class SigUtils {
    * @throws IllegalArgumentException if invalid signal name or a signal is already handled
by OS or JVM
    */
   public static void registerSigListener(String sigName, SigListener sigListener) {
+    if (StringUtils.isEmpty(sigName)) {
+      throw new IllegalArgumentException("NULL signal name");
+    }
     if (sigListener == null) {
       throw new IllegalArgumentException("NULL signal listener");
     }
-    if (sigName == null) {
-      throw new IllegalArgumentException("NULL signal name");
-    }
     if (!sigHandlerMap.containsKey(sigName)){
       sigHandlerMap.put(sigName, new SigHandler());
     }
@@ -110,4 +116,16 @@ public final class SigUtils {
     Signal.handle(new Signal(sigName), sigHandler);
     LOGGER.info("Signal Listener registered for signal " + sigName);
   }
+
+  public static void unregisterSigListener(String sigName, SigListener sigListener){
+    if (StringUtils.isEmpty(sigName)) {
+      throw new IllegalArgumentException("NULL signal name");
+    }
+    if (sigListener == null) {
+      throw new IllegalArgumentException("NULL signal listener");
+    }
+    if (!sigHandlerMap.containsKey(sigName)){
+      sigHandlerMap.get(sigName).removeListener(sigListener);
+    }
+  }
 }


Mime
View raw message