List of usage examples for io.netty.channel ChannelProgressiveFuture isSuccess
boolean isSuccess();
From source file:com.addthis.hydra.query.tracker.TrackerHandler.java
License:Apache License
@Override public void operationComplete(ChannelProgressiveFuture future) throws Exception { if (future == queryPromise) { // only care about operation progressed events for the gathering promise return;/*from w w w .j a v a2 s . c om*/ } else if (future == opPromise) { // tell aggregator about potential early termination from the op promise if (future.isSuccess()) { queryPromise.trySuccess(); } else { queryPromise.tryFailure(opPromise.cause()); } return; } // else the entire request is over; either from an error the last http write completing // tell the op processor about potential early termination (which may tell the gatherer in turn) if (future.isSuccess()) { opPromise.trySuccess(); } else { opPromise.tryFailure(future.cause()); } QueryEntry runE = queryTracker.running.remove(query.uuid()); if (runE == null) { log.warn("failed to remove running for {}", query.uuid()); } Promise<QueryEntryInfo> promise = new DefaultPromise<>(ctx.executor()); queryEntry.getDetailedQueryEntryInfo(promise); QueryEntryInfo entryInfo = promise.getNow(); if (entryInfo == null) { log.warn("Failed to get detailed status for completed query {}; defaulting to brief", query.uuid()); entryInfo = queryEntry.getStat(); } try { StringMapHelper queryLine = new StringMapHelper().put("query.path", query.getPaths()[0]) .put("query.ops", Arrays.toString(opsLog)).put("sources", query.getParameter("sources")) .put("time", System.currentTimeMillis()).put("time.run", entryInfo.runTime) .put("job.id", query.getJob()).put("job.alias", query.getParameter("track.alias")) .put("query.id", query.uuid()).put("lines", entryInfo.lines) .put("sender", query.getParameter("sender")); if (!future.isSuccess()) { Throwable queryFailure = future.cause(); queryLine.put("type", "query.error").put("error", queryFailure.getMessage()); queryTracker.queryErrors.inc(); } else { queryLine.put("type", "query.done"); queryTracker.recentlyCompleted.put(query.uuid(), entryInfo); } queryTracker.log(queryLine); queryTracker.queryMeter.update(entryInfo.runTime, TimeUnit.MILLISECONDS); } catch (Exception e) { log.error("Error while doing record keeping for a query.", e); } }
From source file:com.king.platform.net.http.netty.request.HttpClientRequestHandler.java
License:Apache License
private void writeHttpBody(final ChannelHandlerContext ctx, final HttpRequestContext httpRequestContext, HttpBody httpBody, final RequestEventBus requestEventBus) { try {//from w w w .java 2 s .c o m httpRequestContext.getTimeRecorder().startWriteBody(); ChannelFuture channelFuture = httpBody.writeContent(ctx); channelFuture.addListener(new ChannelProgressiveFutureListener() { @Override public void operationProgressed(ChannelProgressiveFuture future, long progress, long total) throws Exception { requestEventBus.triggerEvent(Event.TOUCH); requestEventBus.triggerEvent(Event.onWroteContentProgressed, progress, total); } @Override public void operationComplete(ChannelProgressiveFuture future) throws Exception { logger.trace("Wrote content operation completed, future: {}", future); if (future.isSuccess()) { httpRequestContext.getTimeRecorder().completedWriteBody(); writeLastHttpContent(ctx, httpRequestContext, requestEventBus); requestEventBus.triggerEvent(Event.TOUCH); } else { logger.error("Failed to write http body, future: " + future); requestEventBus.triggerEvent(Event.ERROR, httpRequestContext, future.cause()); } } }); } catch (IOException e) { requestEventBus.triggerEvent(Event.ERROR, httpRequestContext, new IOException("Failed to write body to server", e)); } }