-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPageServer.java
More file actions
58 lines (48 loc) · 2.32 KB
/
PageServer.java
File metadata and controls
58 lines (48 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* Copyright (c) 2015 Paul Ambrose
*/
package io.haptava.examples.heroku;
import com.codahale.metrics.JmxReporter;
import com.codahale.metrics.MetricRegistry;
import com.sudothought.metrics.MetricUtils;
import com.sudothought.metrics.ObjectNameWithFolders;
import io.haptava.examples.heroku.servlets.DefaultServlet;
import io.haptava.examples.heroku.servlets.DynoContextListener;
import io.haptava.examples.heroku.servlets.HtmlPage;
import io.haptava.examples.heroku.servlets.ResetServlet;
import io.haptava.examples.heroku.servlets.SummaryServlet;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.servlet.Context;
import org.mortbay.jetty.servlet.ServletHolder;
import java.lang.management.ManagementFactory;
import java.util.concurrent.TimeUnit;
public class PageServer {
public static void main(final String[] argv)
throws Exception {
MetricRegistry metricRegistry = new MetricRegistry();
JmxReporter.forRegistry(metricRegistry)
.inDomain(Constants.EXAMPLE_DOMAIN)
.createsObjectNamesWith(ObjectNameWithFolders.OBJECT_NAMES_WITH_FOLDERS)
.convertRatesTo(TimeUnit.MINUTES)
.convertDurationsTo(TimeUnit.MILLISECONDS)
.registerWith(ManagementFactory.getPlatformMBeanServer())
.build()
.start();
MetricUtils.newJvmMetricCollection(metricRegistry, ManagementFactory.getPlatformMBeanServer())
.register();
Context context = new Context(Context.SESSIONS);
context.setContextPath("/");
context.addEventListener(new DynoContextListener());
context.addServlet(new ServletHolder(new HtmlPage(metricRegistry, "hello", "./js/HelloWorld.html")), "/hello");
context.addServlet(new ServletHolder(new HtmlPage(metricRegistry, "dynoRequests", "./js/DynoRequests.html")), "/dynoRequests");
context.addServlet(new ServletHolder(new ResetServlet(metricRegistry, "reset")), "/reset");
context.addServlet(new ServletHolder(new SummaryServlet(metricRegistry, "summary")), "/summary");
context.addServlet(new ServletHolder(new DefaultServlet(metricRegistry, "default")), "/*");
String portVal = System.getenv("PORT");
int port = portVal != null ? Integer.valueOf(portVal) : 8000;
Server server = new Server(port);
server.setHandler(context);
server.start();
server.join();
}
}