[NO ISSUE] Use RuntimeMXBean.getPid() when available

(reapplies 7cc982e5 which was inadvertantly reverted)

Change-Id: I0f4575affd9689f0044bac9959404ad76e133358
Reviewed-on: https://asterix-gerrit.ics.uci.edu/3320
Reviewed-by: Ian Maxon <imaxon@uci.edu>
Integration-Tests: Michael Blow <mblow@apache.org>
Tested-by: Michael Blow <mblow@apache.org>
diff --git a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-common/src/main/java/org/apache/hyracks/control/common/NodeControllerData.java b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-common/src/main/java/org/apache/hyracks/control/common/NodeControllerData.java
index c37acab..24a3e57 100644
--- a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-common/src/main/java/org/apache/hyracks/control/common/NodeControllerData.java
+++ b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-common/src/main/java/org/apache/hyracks/control/common/NodeControllerData.java
@@ -79,7 +79,7 @@
 
     private final Map<String, String> systemProperties;
 
-    private final int pid;
+    private final long pid;
 
     private final HeartbeatSchema hbSchema;
 
diff --git a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-common/src/main/java/org/apache/hyracks/control/common/controllers/NodeRegistration.java b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-common/src/main/java/org/apache/hyracks/control/common/controllers/NodeRegistration.java
index 437b001..474bc0a 100644
--- a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-common/src/main/java/org/apache/hyracks/control/common/controllers/NodeRegistration.java
+++ b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-common/src/main/java/org/apache/hyracks/control/common/controllers/NodeRegistration.java
@@ -75,7 +75,7 @@
 
     private final NetworkAddress messagingPort;
 
-    private final int pid;
+    private final long pid;
 
     private final NodeCapacity capacity;
 
@@ -190,7 +190,7 @@
         return messagingPort;
     }
 
-    public int getPid() {
+    public long getPid() {
         return pid;
     }
 }
diff --git a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/PidHelper.java b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/PidHelper.java
index 5a8edbd..46e77e3 100644
--- a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/PidHelper.java
+++ b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/PidHelper.java
@@ -21,6 +21,7 @@
 import java.lang.management.ManagementFactory;
 import java.lang.management.RuntimeMXBean;
 import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 
 import org.apache.logging.log4j.Level;
@@ -34,11 +35,20 @@
     private PidHelper() {
     }
 
-    public static int getPid() {
+    public static long getPid() {
         return getPid(ManagementFactory.getRuntimeMXBean());
     }
 
-    public static int getPid(RuntimeMXBean runtimeMXBean) {
+    public static long getPid(RuntimeMXBean runtimeMXBean) {
+        // TODO: replace with direct invoke of getPid() once compatibility is at JDK 10 or higher
+        try {
+            Method getPidMethod = runtimeMXBean.getClass().getMethod("getPid");
+            return (Long) getPidMethod.invoke(runtimeMXBean);
+        } catch (NoSuchMethodException e) {
+            LOGGER.debug("ignoring exception trying to find getPid() (expected pre-JDK 10)", e);
+        } catch (IllegalAccessException | InvocationTargetException e) {
+            LOGGER.debug("ignoring exception trying to execute getPid()", e);
+        }
         try {
             Field jvmField = runtimeMXBean.getClass().getDeclaredField("jvm");
             jvmField.setAccessible(true);
diff --git a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/trace/Event.java b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/trace/Event.java
index b5fe3d3..b744198 100644
--- a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/trace/Event.java
+++ b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/trace/Event.java
@@ -28,14 +28,14 @@
     public final long cat;
     public final ITracer.Phase ph;
     public final long ts;
-    public final int pid;
+    public final long pid;
     public final long tid;
     public final ITracer.Scope scope;
     public final String args;
     public final TraceCategoryRegistry registry;
 
-    private Event(String name, long cat, ITracer.Phase ph, long ts, int pid, long tid, ITracer.Scope scope, String args,
-            TraceCategoryRegistry registry) {
+    private Event(String name, long cat, ITracer.Phase ph, long ts, long pid, long tid, ITracer.Scope scope,
+            String args, TraceCategoryRegistry registry) {
         this.name = name;
         this.cat = cat;
         this.ph = ph;
@@ -51,7 +51,7 @@
         return (System.nanoTime() - NANOTIME_DELTA_TO_EPOCH) / 1000;
     }
 
-    public static Event create(String name, long cat, ITracer.Phase ph, int pid, long tid, ITracer.Scope scope,
+    public static Event create(String name, long cat, ITracer.Phase ph, long pid, long tid, ITracer.Scope scope,
             String args, TraceCategoryRegistry registry) {
         return new Event(name, cat, ph, timestamp(), pid, tid, scope, args, registry);
     }
diff --git a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/trace/Tracer.java b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/trace/Tracer.java
index 9019fdf..c1c38cf 100644
--- a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/trace/Tracer.java
+++ b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/trace/Tracer.java
@@ -44,7 +44,7 @@
     private long categories;
     private final TraceCategoryRegistry registry;
 
-    private static final int pid = PidHelper.getPid();
+    private static final long pid = PidHelper.getPid();
 
     public Tracer(String name, long categories, TraceCategoryRegistry registry) {
         final String traceLoggerName = Tracer.class.getName() + ".Traces." + name;