Move Shutdown Hook to NCDriver

Change-Id: Iaef38818e195453eba120a46b5fa7d38b166fd70
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1326
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Yingyi Bu <buyingyi@gmail.com>
diff --git a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/NCDriver.java b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/NCDriver.java
index cbd8edd..2323d71 100644
--- a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/NCDriver.java
+++ b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/NCDriver.java
@@ -39,12 +39,13 @@
                 System.exit(1);
             }
             ncConfig.loadConfigAndApplyDefaults();
-            final NodeControllerService nService = new NodeControllerService(ncConfig);
+            final NodeControllerService ncService = new NodeControllerService(ncConfig);
             if (LOGGER.isLoggable(Level.SEVERE)) {
-                LOGGER.severe("Setting uncaught exception handler " + nService.getLifeCycleComponentManager());
+                LOGGER.severe("Setting uncaught exception handler " + ncService.getLifeCycleComponentManager());
             }
-            Thread.currentThread().setUncaughtExceptionHandler(nService.getLifeCycleComponentManager());
-            nService.start();
+            Thread.currentThread().setUncaughtExceptionHandler(ncService.getLifeCycleComponentManager());
+            ncService.start();
+            Runtime.getRuntime().addShutdownHook(new NCShutdownHook(ncService));
             while (true) {
                 Thread.sleep(10000);
             }
diff --git a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/NodeControllerService.java b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/NodeControllerService.java
index 39a2554..21bf9c2 100644
--- a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/NodeControllerService.java
+++ b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/NodeControllerService.java
@@ -324,9 +324,6 @@
         if (ncAppEntryPoint != null) {
             ncAppEntryPoint.notifyStartupComplete();
         }
-
-        //add JVM shutdown hook
-        Runtime.getRuntime().addShutdownHook(new NCShutdownHook(this));
     }
 
     private void startApplication() throws Exception {