use of javax.servlet.AsyncEvent in project metrics by dropwizard.
the class InstrumentedHandler method doStart.
@Override
protected void doStart() throws Exception {
super.doStart();
final String prefix = this.prefix == null ? name(getHandler().getClass(), name) : name(this.prefix, name);
this.requests = metricRegistry.timer(name(prefix, "requests"));
this.dispatches = metricRegistry.timer(name(prefix, "dispatches"));
this.activeRequests = metricRegistry.counter(name(prefix, "active-requests"));
this.activeDispatches = metricRegistry.counter(name(prefix, "active-dispatches"));
this.activeSuspended = metricRegistry.counter(name(prefix, "active-suspended"));
this.asyncDispatches = metricRegistry.meter(name(prefix, "async-dispatches"));
this.asyncTimeouts = metricRegistry.meter(name(prefix, "async-timeouts"));
this.responses = new Meter[] { // 1xx
metricRegistry.meter(name(prefix, "1xx-responses")), // 2xx
metricRegistry.meter(name(prefix, "2xx-responses")), // 3xx
metricRegistry.meter(name(prefix, "3xx-responses")), // 4xx
metricRegistry.meter(name(prefix, "4xx-responses")), // 5xx
metricRegistry.meter(name(prefix, "5xx-responses")) };
this.getRequests = metricRegistry.timer(name(prefix, "get-requests"));
this.postRequests = metricRegistry.timer(name(prefix, "post-requests"));
this.headRequests = metricRegistry.timer(name(prefix, "head-requests"));
this.putRequests = metricRegistry.timer(name(prefix, "put-requests"));
this.deleteRequests = metricRegistry.timer(name(prefix, "delete-requests"));
this.optionsRequests = metricRegistry.timer(name(prefix, "options-requests"));
this.traceRequests = metricRegistry.timer(name(prefix, "trace-requests"));
this.connectRequests = metricRegistry.timer(name(prefix, "connect-requests"));
this.moveRequests = metricRegistry.timer(name(prefix, "move-requests"));
this.otherRequests = metricRegistry.timer(name(prefix, "other-requests"));
metricRegistry.register(name(prefix, "percent-4xx-1m"), new RatioGauge() {
@Override
protected Ratio getRatio() {
return Ratio.of(responses[3].getOneMinuteRate(), requests.getOneMinuteRate());
}
});
metricRegistry.register(name(prefix, "percent-4xx-5m"), new RatioGauge() {
@Override
protected Ratio getRatio() {
return Ratio.of(responses[3].getFiveMinuteRate(), requests.getFiveMinuteRate());
}
});
metricRegistry.register(name(prefix, "percent-4xx-15m"), new RatioGauge() {
@Override
protected Ratio getRatio() {
return Ratio.of(responses[3].getFifteenMinuteRate(), requests.getFifteenMinuteRate());
}
});
metricRegistry.register(name(prefix, "percent-5xx-1m"), new RatioGauge() {
@Override
protected Ratio getRatio() {
return Ratio.of(responses[4].getOneMinuteRate(), requests.getOneMinuteRate());
}
});
metricRegistry.register(name(prefix, "percent-5xx-5m"), new RatioGauge() {
@Override
protected Ratio getRatio() {
return Ratio.of(responses[4].getFiveMinuteRate(), requests.getFiveMinuteRate());
}
});
metricRegistry.register(name(prefix, "percent-5xx-15m"), new RatioGauge() {
@Override
protected Ratio getRatio() {
return Ratio.of(responses[4].getFifteenMinuteRate(), requests.getFifteenMinuteRate());
}
});
this.listener = new AsyncListener() {
private long startTime;
@Override
public void onTimeout(AsyncEvent event) throws IOException {
asyncTimeouts.mark();
}
@Override
public void onStartAsync(AsyncEvent event) throws IOException {
startTime = System.currentTimeMillis();
event.getAsyncContext().addListener(this);
}
@Override
public void onError(AsyncEvent event) throws IOException {
}
@Override
public void onComplete(AsyncEvent event) throws IOException {
final AsyncContextState state = (AsyncContextState) event.getAsyncContext();
final HttpServletRequest request = (HttpServletRequest) state.getRequest();
final HttpServletResponse response = (HttpServletResponse) state.getResponse();
updateResponses(request, response, startTime);
if (state.getHttpChannelState().getState() != HttpChannelState.State.DISPATCHED) {
activeSuspended.dec();
}
}
};
}
use of javax.servlet.AsyncEvent in project chassis by Kixeye.
the class InstrumentedHandler method doStart.
@Override
protected void doStart() throws Exception {
super.doStart();
final String prefix = name(getHandler().getClass(), name);
this.requests = timer(name(prefix, "requests"));
this.dispatches = timer(name(prefix, "dispatches"));
this.activeRequests = metricRegistry.counter(name(prefix, "active-requests"));
this.activeDispatches = metricRegistry.counter(name(prefix, "active-dispatches"));
this.activeSuspended = metricRegistry.counter(name(prefix, "active-suspended"));
this.asyncDispatches = metricRegistry.meter(name(prefix, "async-dispatches"));
this.asyncTimeouts = metricRegistry.meter(name(prefix, "async-timeouts"));
this.responses = new Meter[] { // 1xx
metricRegistry.meter(name(prefix, "1xx-responses")), // 2xx
metricRegistry.meter(name(prefix, "2xx-responses")), // 3xx
metricRegistry.meter(name(prefix, "3xx-responses")), // 4xx
metricRegistry.meter(name(prefix, "4xx-responses")), // 5xx
metricRegistry.meter(name(prefix, "5xx-responses")) };
this.getRequests = timer(name(prefix, "get-requests"));
this.postRequests = timer(name(prefix, "post-requests"));
this.headRequests = timer(name(prefix, "head-requests"));
this.putRequests = timer(name(prefix, "put-requests"));
this.deleteRequests = timer(name(prefix, "delete-requests"));
this.optionsRequests = timer(name(prefix, "options-requests"));
this.traceRequests = timer(name(prefix, "trace-requests"));
this.connectRequests = timer(name(prefix, "connect-requests"));
this.moveRequests = timer(name(prefix, "move-requests"));
this.otherRequests = timer(name(prefix, "other-requests"));
this.listener = new AsyncListener() {
@Override
public void onTimeout(AsyncEvent event) throws IOException {
asyncTimeouts.mark();
}
@Override
public void onStartAsync(AsyncEvent event) throws IOException {
event.getAsyncContext().addListener(this);
}
@Override
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);
if (!(state.getHttpChannelState().getState() == State.DISPATCHED)) {
activeSuspended.dec();
}
}
};
}
use of javax.servlet.AsyncEvent in project undertow by undertow-io.
the class OnCompleteServlet method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
final AsyncContext ctx = req.startAsync();
ctx.addListener(new AsyncListener() {
@Override
public void onComplete(AsyncEvent event) throws IOException {
QUEUE.add("onComplete");
}
@Override
public void onTimeout(AsyncEvent event) throws IOException {
QUEUE.add("onTimeout");
}
@Override
public void onError(AsyncEvent event) throws IOException {
QUEUE.add("onError");
}
@Override
public void onStartAsync(AsyncEvent event) throws IOException {
QUEUE.add("onStartAsync");
}
});
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
ctx.dispatch("/message");
}
});
thread.start();
}
use of javax.servlet.AsyncEvent in project undertow by undertow-io.
the class AsyncContextImpl method onAsyncComplete.
private void onAsyncComplete() {
final boolean setupRequired = SecurityActions.currentServletRequestContext() == null;
servletRequestContext.getCurrentServletContext().invokeRunnable(servletRequestContext.getExchange(), new Runnable() {
@Override
public void run() {
//now run request listeners
setupRequestContext(setupRequired);
try {
for (final BoundAsyncListener listener : asyncListeners) {
AsyncEvent event = new AsyncEvent(AsyncContextImpl.this, listener.servletRequest, listener.servletResponse);
try {
listener.asyncListener.onComplete(event);
} catch (IOException e) {
UndertowServletLogger.REQUEST_LOGGER.ioExceptionDispatchingAsyncEvent(e);
}
}
} finally {
tearDownRequestContext(setupRequired);
}
}
});
}
use of javax.servlet.AsyncEvent in project undertow by undertow-io.
the class AsyncContextImpl method onAsyncStart.
private void onAsyncStart(final AsyncContext newAsyncContext) {
final boolean setupRequired = SecurityActions.currentServletRequestContext() == null;
servletRequestContext.getCurrentServletContext().invokeRunnable(servletRequestContext.getExchange(), new Runnable() {
@Override
public void run() {
//now run request listeners
setupRequestContext(setupRequired);
try {
for (final BoundAsyncListener listener : asyncListeners) {
//make sure we use the new async context
AsyncEvent event = new AsyncEvent(newAsyncContext, listener.servletRequest, listener.servletResponse);
try {
listener.asyncListener.onStartAsync(event);
} catch (IOException e) {
UndertowServletLogger.REQUEST_LOGGER.ioExceptionDispatchingAsyncEvent(e);
}
}
} finally {
tearDownRequestContext(setupRequired);
}
}
});
}
Aggregations