BUG-8143: issue a JVM restart
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / config / yang / config / actor_system_provider / impl / ActorSystemProviderImpl.java
index 1ab67384f17112d0ac527dc00099ed851676be54..5b6e447d0b09e165e66178bb596bf6d813bf5d7d 100644 (file)
@@ -9,10 +9,11 @@ package org.opendaylight.controller.config.yang.config.actor_system_provider.imp
 
 import akka.actor.ActorSystem;
 import akka.actor.Props;
-import akka.japi.Effect;
 import akka.osgi.BundleDelegatingClassLoader;
 import com.typesafe.config.Config;
 import com.typesafe.config.ConfigFactory;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.concurrent.TimeUnit;
 import org.opendaylight.controller.cluster.ActorSystemProvider;
 import org.opendaylight.controller.cluster.ActorSystemProviderListener;
@@ -41,8 +42,9 @@ public class ActorSystemProviderImpl implements ActorSystemProvider, AutoCloseab
 
         final Bundle bundle = bundleContext.getBundle();
 
-        final BundleDelegatingClassLoader classLoader = new BundleDelegatingClassLoader(bundle, Thread.currentThread()
-                .getContextClassLoader());
+        final BundleDelegatingClassLoader classLoader = AccessController.doPrivileged(
+            (PrivilegedAction<BundleDelegatingClassLoader>) () ->
+                new BundleDelegatingClassLoader(bundle, Thread.currentThread().getContextClassLoader()));
 
         final AkkaConfigurationReader configurationReader = new FileAkkaConfigurationReader();
         final Config akkaConfig = ConfigFactory.load(configurationReader.read()).getConfig(CONFIGURATION_NAME);
@@ -51,17 +53,12 @@ public class ActorSystemProviderImpl implements ActorSystemProvider, AutoCloseab
 
         actorSystem.actorOf(Props.create(TerminationMonitor.class), TerminationMonitor.ADDRESS);
 
-        actorSystem.actorOf(QuarantinedMonitorActor.props(new Effect() {
-
-            @Override
-            public void apply() throws Exception {
-                // restart the entire karaf container
-                LOG.warn("Restarting karaf container");
-                System.setProperty("karaf.restart", "true");
-                bundleContext.getBundle(0).stop();
-            }
+        actorSystem.actorOf(QuarantinedMonitorActor.props(() -> {
+            // restart the entire karaf container
+            LOG.warn("Restarting karaf container");
+            System.setProperty("karaf.restart.jvm", "true");
+            bundleContext.getBundle(0).stop();
         }), QuarantinedMonitorActor.ADDRESS);
-
     }
 
     @Override
@@ -76,6 +73,7 @@ public class ActorSystemProviderImpl implements ActorSystemProvider, AutoCloseab
     }
 
     @Override
+    @SuppressWarnings("checkstyle:IllegalCatch")
     public void close() {
         LOG.info("Shutting down ActorSystem");