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.
source to share
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;
}
});
source to share