Skip to content

Commit

Permalink
Downgrade back to Vertx 2.0
Browse files Browse the repository at this point in the history
Vertx 3.x requires Java 8 and we still want Java 7 support

This reverts commit 09d4136.
  • Loading branch information
ajsquared committed Mar 16, 2016
1 parent 9d0752c commit 1f36c1b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 53 deletions.
7 changes: 1 addition & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,7 @@
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web</artifactId>
<version>3.2.0</version>
<version>2.1.5</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.etsy.statsd.profiler.server;

import com.etsy.statsd.profiler.Profiler;
import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpServer;
import io.vertx.ext.web.impl.RouterImpl;
import org.vertx.java.core.AsyncResult;
import org.vertx.java.core.Handler;
import org.vertx.java.core.Vertx;
import org.vertx.java.core.VertxFactory;
import org.vertx.java.core.http.HttpServer;

import java.util.LinkedList;
import java.util.Map;
Expand All @@ -20,7 +20,7 @@
*/
public final class ProfilerServer {
private static final Logger LOGGER = Logger.getLogger(ProfilerServer.class.getName());
private static final Vertx VERTX = Vertx.factory.vertx();
private static final Vertx VERTX = VertxFactory.newVertx();

private ProfilerServer() { }

Expand All @@ -32,7 +32,7 @@ private ProfilerServer() { }
*/
public static void startServer(final Map<String, ScheduledFuture<?>> runningProfilers, final Map<String, Profiler> activeProfilers, final int port, final AtomicReference<Boolean> isRunning, final LinkedList<String> errors) {
final HttpServer server = VERTX.createHttpServer();
server.requestHandler(RequestHandler.getMatcher(new RouterImpl(VERTX), runningProfilers, activeProfilers, isRunning, errors));
server.requestHandler(RequestHandler.getMatcher(runningProfilers, activeProfilers, isRunning, errors));
server.listen(port, new Handler<AsyncResult<HttpServer>>() {
@Override
public void handle(AsyncResult<HttpServer> event) {
Expand Down
73 changes: 33 additions & 40 deletions src/main/java/com/etsy/statsd/profiler/server/RequestHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
import com.google.common.base.Joiner;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import io.vertx.core.Handler;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.RoutingContext;
import org.vertx.java.core.Handler;
import org.vertx.java.core.http.HttpServerRequest;
import org.vertx.java.core.http.RouteMatcher;

import java.util.Collection;
import java.util.LinkedList;
Expand All @@ -31,31 +29,26 @@ private RequestHandler() { }
* @param activeProfilers The active profilers
* @return A RouteMatcher that matches all supported routes
*/
public static Handler<HttpServerRequest> getMatcher(final Router router, final Map<String, ScheduledFuture<?>> runningProfilers, Map<String, Profiler> activeProfilers, AtomicReference<Boolean> isRunning, LinkedList<String> errors) {
router.route(HttpMethod.GET, "/profilers").handler(RequestHandler.handleGetProfilers(runningProfilers));
router.route(HttpMethod.GET, "/disable/:profiler").handler(RequestHandler.handleDisableProfiler(runningProfilers));
router.route(HttpMethod.GET, "/status/profiler/:profiler").handler(RequestHandler.handleProfilerStatus(activeProfilers));
router.route(HttpMethod.GET, "/errors").handler(RequestHandler.handleErrorMessages(errors));
router.route(HttpMethod.GET, "/isRunning").handler(RequestHandler.isRunning(isRunning));

return new Handler<HttpServerRequest>() {
@Override
public void handle(HttpServerRequest httpServerRequest) {
router.accept(httpServerRequest);
}
};
public static RouteMatcher getMatcher(final Map<String, ScheduledFuture<?>> runningProfilers, Map<String, Profiler> activeProfilers, AtomicReference<Boolean> isRunning, LinkedList<String> errors) {
RouteMatcher matcher = new RouteMatcher();
matcher.get("/profilers", RequestHandler.handleGetProfilers(runningProfilers));
matcher.get("/disable/:profiler", RequestHandler.handleDisableProfiler(runningProfilers));
matcher.get("/status/profiler/:profiler", RequestHandler.handleProfilerStatus(activeProfilers));
matcher.get("/errors", RequestHandler.handleErrorMessages(errors));
matcher.get("/isRunning", RequestHandler.isRunning(isRunning));
return matcher;
}

/**
* Handle a GET to /isRunning
*
* @return A Handler that returns all running profilers
*/
public static Handler<RoutingContext> isRunning(final AtomicReference<Boolean> isRunning) {
return new Handler<RoutingContext>() {
public static Handler<HttpServerRequest> isRunning(final AtomicReference<Boolean> isRunning) {
return new Handler<HttpServerRequest>() {
@Override
public void handle(RoutingContext routingContext) {
routingContext.response().end(String.format("isRunning: %b", isRunning.get()));
public void handle(HttpServerRequest httpServerRequest) {
httpServerRequest.response().end(String.format("isRunning: %b", isRunning.get()));
}
};
}
Expand All @@ -65,11 +58,11 @@ public void handle(RoutingContext routingContext) {
*
* @return A Handler that handles a request to the /profilers endpoint
*/
public static Handler<RoutingContext> handleGetProfilers(final Map<String, ScheduledFuture<?>> runningProfilers) {
return new Handler<RoutingContext>() {
public static Handler<HttpServerRequest> handleGetProfilers(final Map<String, ScheduledFuture<?>> runningProfilers) {
return new Handler<HttpServerRequest>() {
@Override
public void handle(RoutingContext routingContext) {
routingContext.response().end(Joiner.on("\n").join(getEnabledProfilers(runningProfilers)));
public void handle(HttpServerRequest httpServerRequest) {
httpServerRequest.response().end(Joiner.on("\n").join(getEnabledProfilers(runningProfilers)));
}
};
}
Expand All @@ -79,11 +72,11 @@ public void handle(RoutingContext routingContext) {
*
* @return The last 10 error stacktraces
*/
public static Handler<RoutingContext> handleErrorMessages(final LinkedList<String> errors) {
return new Handler<RoutingContext>() {
public static Handler<HttpServerRequest> handleErrorMessages(final LinkedList<String> errors) {
return new Handler<HttpServerRequest>() {
@Override
public void handle(RoutingContext routingContext) {
routingContext.response().end("Errors: " + Joiner.on("\n").join(errors));
public void handle(HttpServerRequest httpServerRequest) {
httpServerRequest.response().end("Errors: " + Joiner.on("\n").join(errors));
}
};
}
Expand All @@ -94,14 +87,14 @@ public void handle(RoutingContext routingContext) {
* @param activeProfilers The active profilers
* @return A Handler that handles a request to the /disable/:profiler endpoint
*/
public static Handler<RoutingContext> handleDisableProfiler(final Map<String, ScheduledFuture<?>> activeProfilers) {
return new Handler<RoutingContext>() {
public static Handler<HttpServerRequest> handleDisableProfiler(final Map<String, ScheduledFuture<?>> activeProfilers) {
return new Handler<HttpServerRequest>() {
@Override
public void handle(RoutingContext routingContext) {
String profilerToDisable = routingContext.request().params().get("profiler");
public void handle(HttpServerRequest httpServerRequest) {
String profilerToDisable = httpServerRequest.params().get("profiler");
ScheduledFuture<?> future = activeProfilers.get(profilerToDisable);
future.cancel(false);
routingContext.response().end(String.format("Disabled profiler %s", profilerToDisable));
httpServerRequest.response().end(String.format("Disabled profiler %s", profilerToDisable));
}
};
}
Expand All @@ -112,13 +105,13 @@ public void handle(RoutingContext routingContext) {
* @param activeProfilers The active profilers
* @return A Handler that handles a request to the /disable/:profiler endpoint
*/
public static Handler<RoutingContext> handleProfilerStatus(final Map<String, Profiler> activeProfilers) {
return new Handler<RoutingContext>() {
public static Handler<HttpServerRequest> handleProfilerStatus(final Map<String, Profiler> activeProfilers) {
return new Handler<HttpServerRequest>() {
@Override
public void handle(RoutingContext routingContext) {
String profilerName = routingContext.request().params().get("profiler");
public void handle(HttpServerRequest httpServerRequest) {
String profilerName = httpServerRequest.params().get("profiler");
Profiler profiler = activeProfilers.get(profilerName);
routingContext.response().end(String.format("Recorded stats %d\n", profiler.getRecordedStats()));
httpServerRequest.response().end(String.format("Recorded stats %d\n", profiler.getRecordedStats()));
}
};
}
Expand Down

0 comments on commit 1f36c1b

Please sign in to comment.