package com.emc.mongoose;

import io.prometheus.client.exporter.MetricsServlet;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;

/**
 @author veronika K. on 05.10.18 */
public class Server {

	final org.eclipse.jetty.server.Server server;

	public Server() {
		this(1234);  //default port
	}

	public Server(final int port) {
		server = new org.eclipse.jetty.server.Server(port);
		ServletContextHandler context = new ServletContextHandler();
		context.setContextPath("/");
		server.setHandler(context);
		context.addServlet(new ServletHolder(new MetricsServlet()), "/metrics");
	}

	public Server start() {
		try {
			server.start();
		} catch(Exception e) {
			e.printStackTrace();
		}
		return this;
	}

	public void stop() {
		try {
			server.stop();
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
}

@@ -178,16 +178,42 @@
 older;%0A%0A
+import java.util.Arrays;%0A%0A
 /**%0A @au
@@ -826,24 +826,192 @@
 ver.stop();%0A
+%09%09%09Arrays.asList(server.getChildHandlers()).stream().peek(handler -%3E %7B%0A%09%09%09%09try %7B%0A%09%09%09%09%09handler.stop();%0A%09%09%09%09%7D catch(Exception e) %7B%0A%09%09%09%09%09e.printStackTrace();%0A%09%09%09%09%7D%0A%09%09%09%7D);%0A
 %09%09%7D catch(Ex

save [skip ci]