@Override public void onSuccess(MessageContext context) { context.addAttribute(SUCCESSFUL, context.getResponse().getStatus().code() < 400); }
@Override protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest httpRequest) throws Exception { logger.trace("Received a {} message {} from the remote address {}", configuration.getScheme().name(), httpRequest, ctx.channel().remoteAddress()); URI baseUri = HttpUtil.createURI(configuration.getScheme().name(), httpRequest.headers().get(HttpHeaders.Names.HOST), "//"); MessageContext context = new MessageContext(httpRequest, baseUri); ctx.attr(MESSAGE_CONTEXT).set(context); listener.onReceived(context); router.route(context); listener.onSuccess(context); ctx.writeAndFlush(context.getResponse()).addListener(ChannelFutureListener.CLOSE); listener.onComplete(context); } }
@Override public void onComplete(MessageContext context) { String name = null; Boolean successful = (Boolean) context.getAttribute(SUCCESSFUL); if (successful == null) { name = MetricRegistry.name(context.getApplication().getConfiguration().getName(), EXCEPTIONS); MetricRegistries.getRegistry(context.getApplication().getConfiguration().getName()).meter(name).mark(); } else { if (! successful) { name = getMetricName(context, Integer.toString(context.getResponse().getStatus().code())); MetricRegistries.getRegistry(context.getApplication().getConfiguration().getName()).meter(name).mark(); } name = getMetricName(context, RESPONSE_TIME); Timer timer = MetricRegistries.getRegistry(context.getApplication().getConfiguration().getName()).timer(name); timer.update(clock.getTick() - (Long) context.getAttribute(START_TIME), TimeUnit.NANOSECONDS); } } }