summaryrefslogtreecommitdiffstats
path: root/infra
diff options
context:
space:
mode:
authorMarek Gradzki <mgradzki@cisco.com>2018-03-07 15:03:35 +0100
committerMarek Gradzki <mgradzki@cisco.com>2018-03-07 15:06:37 +0100
commita8b9c1ad9df23ff33beea1ba80caadcca19391c5 (patch)
treeaf26760d955183208830fbf440d96465e7d97d86 /infra
parent9659d28f1083f8ce9c67db3fb708f5b96740fba4 (diff)
Fix Restconf server shutdown
Change-Id: Ia7c0fc2d269ae88170297ef22476c8a61121238a Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'infra')
-rw-r--r--infra/northbound/restconf/src/main/java/io/fd/honeycomb/northbound/restconf/JettyServerStarter.java47
-rw-r--r--infra/northbound/restconf/src/main/java/io/fd/honeycomb/northbound/restconf/RestconfModule.java4
2 files changed, 36 insertions, 15 deletions
diff --git a/infra/northbound/restconf/src/main/java/io/fd/honeycomb/northbound/restconf/JettyServerStarter.java b/infra/northbound/restconf/src/main/java/io/fd/honeycomb/northbound/restconf/JettyServerStarter.java
index 1bd50bb..7f5673c 100644
--- a/infra/northbound/restconf/src/main/java/io/fd/honeycomb/northbound/restconf/JettyServerStarter.java
+++ b/infra/northbound/restconf/src/main/java/io/fd/honeycomb/northbound/restconf/JettyServerStarter.java
@@ -23,6 +23,7 @@ import com.google.inject.Inject;
import com.google.inject.name.Named;
import io.fd.honeycomb.binding.init.ProviderTrait;
+import io.fd.honeycomb.data.init.ShutdownHandler;
import javax.annotation.Nullable;
import org.eclipse.jetty.server.Server;
@@ -31,7 +32,7 @@ import org.opendaylight.netconf.sal.rest.api.RestConnector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-class JettyServerStarter extends ProviderTrait<JettyServerStarter.ServerInit> {
+class JettyServerStarter extends ProviderTrait<JettyServerStarter.RestconfJettyServer> {
private static final Logger LOG = LoggerFactory.getLogger(JettyServerStarter.class);
@@ -54,21 +55,41 @@ class JettyServerStarter extends ProviderTrait<JettyServerStarter.ServerInit> {
@Named(RESTCONF_HTTPS)
private ServerConnector httpsConnectorInit;
+ @Inject
+ private ShutdownHandler shutdownHandler;
+
@Override
- protected ServerInit create() {
- try {
- LOG.info("Starting RESTCONF Jetty server");
- server.start();
- LOG.info("RESTCONF Jetty server successfully started");
- } catch (Exception e) {
- LOG.error("Unable to start RESTCONF Jetty server", e);
- throw new IllegalStateException("Unable to start RESTCONF Jetty server", e);
+ protected RestconfJettyServer create() {
+ final RestconfJettyServer jettyServer = new RestconfJettyServer(server);
+ jettyServer.start();
+ shutdownHandler.register(RestconfJettyServer.class.getCanonicalName(), jettyServer);
+ return jettyServer;
+ }
+
+ final class RestconfJettyServer implements AutoCloseable {
+ private final Server server;
+
+ private RestconfJettyServer(final Server server) {
+ this.server = server;
}
- return new ServerInit() {
- };
- }
+ private void start() {
+ try {
+ LOG.info("Starting RESTCONF Jetty server");
+ server.start();
+ LOG.info("RESTCONF Jetty server successfully started");
+ } catch (Exception e) {
+ LOG.error("Unable to start RESTCONF Jetty server", e);
+ throw new IllegalStateException("Unable to start RESTCONF Jetty server", e);
+ }
+ }
- interface ServerInit {
+ @Override
+ public void close() throws Exception {
+ LOG.info("Stopping RESTCONF Jetty server");
+ server.stop();
+ server.destroy();
+ LOG.info("RESTCONF Jetty server successfully stopped");
+ }
}
}
diff --git a/infra/northbound/restconf/src/main/java/io/fd/honeycomb/northbound/restconf/RestconfModule.java b/infra/northbound/restconf/src/main/java/io/fd/honeycomb/northbound/restconf/RestconfModule.java
index 9f9ecf7..1a59b72 100644
--- a/infra/northbound/restconf/src/main/java/io/fd/honeycomb/northbound/restconf/RestconfModule.java
+++ b/infra/northbound/restconf/src/main/java/io/fd/honeycomb/northbound/restconf/RestconfModule.java
@@ -19,7 +19,7 @@ package io.fd.honeycomb.northbound.restconf;
import com.google.inject.Singleton;
import com.google.inject.name.Names;
import io.fd.honeycomb.northbound.NorthboundAbstractModule;
-import io.fd.honeycomb.northbound.restconf.JettyServerStarter.ServerInit;
+import io.fd.honeycomb.northbound.restconf.JettyServerStarter.RestconfJettyServer;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.opendaylight.netconf.sal.rest.api.RestConnector;
@@ -54,6 +54,6 @@ public class RestconfModule extends NorthboundAbstractModule<RestconfConfigurati
.toProvider(HttpsConnectorProvider.class)
.in(Singleton.class);
bind(RestConnector.class).toProvider(RestconfProvider.class).in(Singleton.class);
- bind(ServerInit.class).toProvider(JettyServerStarter.class).asEagerSingleton();
+ bind(RestconfJettyServer.class).toProvider(JettyServerStarter.class).asEagerSingleton();
}
}