summaryrefslogtreecommitdiffstats
path: root/vpp-common/vpp-common-integration/src
diff options
context:
space:
mode:
authorJan Srnicek <jsrnicek@cisco.com>2017-08-11 14:05:30 +0200
committerMarek Gradzki <mgradzki@cisco.com>2017-08-14 08:20:18 +0000
commit2a39a0f17d82ecf7c75840d53960c42c6ea2c6ac (patch)
treebe89dcd0d219dc2ff9c928c77a4fc218458e071f /vpp-common/vpp-common-integration/src
parent72493bf45a8823dbb2bc8e0745ebb7106a7ae01f (diff)
HONEYCOMB-381 - Usage of ShutdownHandler for jvpp components
and notification producer Change-Id: I70e749de5b290c84e86a28625d5ec79c98de80f2 Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'vpp-common/vpp-common-integration/src')
-rw-r--r--vpp-common/vpp-common-integration/src/main/java/io/fd/hc2vpp/common/integration/JVppCoreProvider.java17
-rw-r--r--vpp-common/vpp-common-integration/src/main/java/io/fd/hc2vpp/common/integration/JVppRegistryProvider.java33
-rw-r--r--vpp-common/vpp-common-integration/src/test/java/io/fd/hc2vpp/common/integration/VppCommonModuleTest.java6
3 files changed, 27 insertions, 29 deletions
diff --git a/vpp-common/vpp-common-integration/src/main/java/io/fd/hc2vpp/common/integration/JVppCoreProvider.java b/vpp-common/vpp-common-integration/src/main/java/io/fd/hc2vpp/common/integration/JVppCoreProvider.java
index 4945bb98e..609611252 100644
--- a/vpp-common/vpp-common-integration/src/main/java/io/fd/hc2vpp/common/integration/JVppCoreProvider.java
+++ b/vpp-common/vpp-common-integration/src/main/java/io/fd/hc2vpp/common/integration/JVppCoreProvider.java
@@ -18,11 +18,12 @@ package io.fd.hc2vpp.common.integration;
import com.google.inject.Inject;
import io.fd.honeycomb.binding.init.ProviderTrait;
-import java.io.IOException;
+import io.fd.honeycomb.data.init.ShutdownHandler;
import io.fd.vpp.jvpp.JVppRegistry;
import io.fd.vpp.jvpp.core.JVppCoreImpl;
import io.fd.vpp.jvpp.core.future.FutureJVppCore;
import io.fd.vpp.jvpp.core.future.FutureJVppCoreFacade;
+import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -37,21 +38,15 @@ public final class JVppCoreProvider extends ProviderTrait<FutureJVppCore> {
@Inject
private JVppRegistry registry;
+ @Inject
+ private ShutdownHandler shutdownHandler;
+
@Override
protected FutureJVppCoreFacade create() {
try {
final JVppCoreImpl jVpp = new JVppCoreImpl();
// Free jvpp-core plugin's resources on shutdown
- Runtime.getRuntime().addShutdownHook(new Thread() {
-
- @Override
- public void run() {
- LOG.info("Unloading jvpp-core plugin");
- jVpp.close();
- LOG.info("Successfully unloaded jvpp-core plugin");
- }
- });
-
+ shutdownHandler.register("jvpp-core", jVpp);
LOG.info("Successfully loaded jvpp-core plugin");
return new FutureJVppCoreFacade(registry, jVpp);
} catch (IOException e) {
diff --git a/vpp-common/vpp-common-integration/src/main/java/io/fd/hc2vpp/common/integration/JVppRegistryProvider.java b/vpp-common/vpp-common-integration/src/main/java/io/fd/hc2vpp/common/integration/JVppRegistryProvider.java
index 8837b7fe8..47c512898 100644
--- a/vpp-common/vpp-common-integration/src/main/java/io/fd/hc2vpp/common/integration/JVppRegistryProvider.java
+++ b/vpp-common/vpp-common-integration/src/main/java/io/fd/hc2vpp/common/integration/JVppRegistryProvider.java
@@ -17,11 +17,12 @@
package io.fd.hc2vpp.common.integration;
import com.google.inject.Inject;
-import io.fd.honeycomb.binding.init.ProviderTrait;
import io.fd.hc2vpp.common.translate.util.VppStatusListener;
-import java.io.IOException;
+import io.fd.honeycomb.binding.init.ProviderTrait;
+import io.fd.honeycomb.data.init.ShutdownHandler;
import io.fd.vpp.jvpp.JVppRegistry;
import io.fd.vpp.jvpp.JVppRegistryImpl;
+import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -37,6 +38,8 @@ public final class JVppRegistryProvider extends ProviderTrait<JVppRegistry> {
private VppConfigAttributes config;
@Inject
private VppStatusListener vppStatus;
+ @Inject
+ private ShutdownHandler shutdownHandler;
@Override
protected JVppRegistryImpl create() {
@@ -46,23 +49,19 @@ public final class JVppRegistryProvider extends ProviderTrait<JVppRegistry> {
// Closing JVpp connection with shutdown hook to erase the connection from VPP so HC will be able
// to connect next time. If JVM is force closed, this will not be executed and VPP connection
// with name from config will stay open and prevent next startup of HC to success
- Runtime.getRuntime().addShutdownHook(new Thread() {
- @Override
- public void run() {
- LOG.info("Disconnecting from VPP");
- if (vppStatus.isDown()) {
- LOG.info("VPP is down. JVppRegistry cleanup is not needed. Exiting");
- return;
- }
- try {
- registry.close();
- LOG.info("Successfully disconnected from VPP as {}", config.jvppConnectionName);
- } catch (Exception e) {
- LOG.warn("Unable to properly close jvpp registry", e);
- }
+ shutdownHandler.register("jvpp-registry", () -> {
+ LOG.info("Disconnecting from VPP");
+ if (vppStatus.isDown()) {
+ LOG.info("VPP is down. JVppRegistry cleanup is not needed. Exiting");
+ return;
+ }
+ try {
+ registry.close();
+ LOG.info("Successfully disconnected from VPP as {}", config.jvppConnectionName);
+ } catch (Exception e) {
+ LOG.warn("Unable to properly close jvpp registry", e);
}
});
-
LOG.info("JVpp connection opened successfully as: {}", config.jvppConnectionName);
return registry;
} catch (IOException e) {
diff --git a/vpp-common/vpp-common-integration/src/test/java/io/fd/hc2vpp/common/integration/VppCommonModuleTest.java b/vpp-common/vpp-common-integration/src/test/java/io/fd/hc2vpp/common/integration/VppCommonModuleTest.java
index 540145beb..b1aab05ce 100644
--- a/vpp-common/vpp-common-integration/src/test/java/io/fd/hc2vpp/common/integration/VppCommonModuleTest.java
+++ b/vpp-common/vpp-common-integration/src/test/java/io/fd/hc2vpp/common/integration/VppCommonModuleTest.java
@@ -29,10 +29,10 @@ import com.google.inject.name.Named;
import com.google.inject.testing.fieldbinder.Bind;
import com.google.inject.testing.fieldbinder.BoundFieldModule;
import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer;
+import io.fd.honeycomb.data.init.ShutdownHandler;
import io.fd.honeycomb.translate.read.ReaderFactory;
import java.util.HashSet;
import java.util.Set;
-import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
@@ -44,6 +44,10 @@ public class VppCommonModuleTest {
@Mock
private DataBroker honeycombContext;
+ @Mock
+ @Bind
+ private ShutdownHandler shutdownHandler;
+
@Inject
private Set<ReaderFactory> readerFactories = new HashSet<>();