Dropwizard: How to disable a service programmatically (in-process)?

What is the best practice to disable the Dropwizard software programmatically, for example, if a fuzzy exception occurs on any thread, I would like to terminate my Dropwizard service?


FYI: Similar but unrelated questions on StackOverflow:

This Dropwizard question : How to stop a service programmatically refers to the module testing your service

See this question How to disable dropwizard app? refers to how to disable the service out of process.

+3


source to share


2 answers


I don't think there is any best practice out there.

System.exit(0);

      



This is what CTRL-C does. It triggers shutdown hooks and leads to graceful shutdown.

+1


source


You can do this as DropwizardClientRule

and DropwizardAppRule

do: stop Jetty, calling the service org.eclipse.jetty.server.Server#stop()

.

To get a Jetty instance, you need to register a lifecycle callback handler:



environment.lifecycle().addServerLifecycleListener(new ServerLifecycleListener() {
    @Override
    public void serverStarted(Server server) {
        myJettyServer = server;
    }
});

      

+3


source







All Articles