diff options
Diffstat (limited to 'infra/northbound/restconf/src/main/java/io/fd/honeycomb/northbound/restconf/JettyServerStarter.java')
-rw-r--r-- | infra/northbound/restconf/src/main/java/io/fd/honeycomb/northbound/restconf/JettyServerStarter.java | 47 |
1 files changed, 34 insertions, 13 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 1bd50bb22..7f5673caf 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"); + } } } |