Skip to content

Commit

Permalink
Temp patch for #444 ClassCastException in Jetty9 InstrumentedHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
ryantenney committed Feb 11, 2014
1 parent f3ff495 commit 298d76c
Showing 1 changed file with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.codahale.metrics.Meter;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Timer;

import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.server.AsyncContextState;
import org.eclipse.jetty.server.Handler;
Expand All @@ -14,8 +15,10 @@
import javax.servlet.AsyncEvent;
import javax.servlet.AsyncListener;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -137,8 +140,7 @@ public void onError(AsyncEvent event) throws IOException {
@Override
public void onComplete(AsyncEvent event) throws IOException {
final AsyncContextState state = (AsyncContextState) event.getAsyncContext();
final Request request = (Request) state.getRequest();
updateResponses(request);
updateResponses(state.getRequest());
if (!state.getHttpChannelState().isDispatched()) {
activeSuspended.dec();
}
Expand Down Expand Up @@ -220,14 +222,17 @@ private Timer requestTimer(String method) {
}
}

private void updateResponses(Request request) {
final int response = request.getResponse().getStatus() / 100;
if (response >= 1 && response <= 5) {
responses[response - 1].mark();
private void updateResponses(ServletRequest servletRequest) {
if (servletRequest instanceof Request) {
Request request = (Request) servletRequest;
final int response = request.getResponse().getStatus() / 100;
if (response >= 1 && response <= 5) {
responses[response - 1].mark();
}
activeRequests.dec();
final long elapsedTime = System.currentTimeMillis() - request.getTimeStamp();
requests.update(elapsedTime, TimeUnit.MILLISECONDS);
requestTimer(request.getMethod()).update(elapsedTime, TimeUnit.MILLISECONDS);
}
activeRequests.dec();
final long elapsedTime = System.currentTimeMillis() - request.getTimeStamp();
requests.update(elapsedTime, TimeUnit.MILLISECONDS);
requestTimer(request.getMethod()).update(elapsedTime, TimeUnit.MILLISECONDS);
}
}

0 comments on commit 298d76c

Please sign in to comment.