Skip to content

Instantly share code, notes, and snippets.

@abhirockzz
Created December 18, 2018 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhirockzz/12033adb8166c8654021751ca40baa3f to your computer and use it in GitHub Desktop.
Save abhirockzz/12033adb8166c8654021751ca40baa3f to your computer and use it in GitHub Desktop.
private static void bootstrap() throws IOException {
String hostname = "0.0.0.0";
String port = "9090";
URI baseUri = UriBuilder.fromUri("http://" + hostname + "/").port(Integer.parseInt(port)).build();
ResourceConfig config = new ResourceConfig(ServiceManagerResource.class);
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, config);
LOGGER.log(Level.INFO, "Application accessible at {0}", baseUri.toString());
//gracefully exit Grizzly services when app is shut down
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
LOGGER.log(Level.INFO, "Exiting......");
try {
server.shutdownNow();
LOGGER.log(Level.INFO, "REST services stopped");
ServiceLifecycleManager.getInstance().stop();
LOGGER.log(Level.INFO, "Twitter producer stopped");
} catch (Exception ex) {
//log & continue....
LOGGER.log(Level.SEVERE, ex, ex::getMessage);
}
}
}));
server.start();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment