List of usage examples for io.netty.util.concurrent Promise getNow
V getNow();
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 ww.j a v a2 s .c o m*/ } 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.linecorp.armeria.client.HttpRemoteInvoker.java
License:Apache License
static <T> void invoke0(ClientCodec codec, Channel channel, Method method, Object[] args, ClientOptions options, Promise<T> resultPromise, PoolKey poolKey) { final HttpSession session = HttpSessionHandler.get(channel); final SessionProtocol sessionProtocol = session.protocol(); if (sessionProtocol == null) { resultPromise.setFailure(ClosedSessionException.INSTANCE); return;/*w ww . ja va 2 s.co m*/ } final EncodeResult encodeResult = codec.encodeRequest(channel, sessionProtocol, method, args); if (encodeResult.isSuccess()) { ServiceInvocationContext ctx = encodeResult.invocationContext(); Promise<FullHttpResponse> responsePromise = channel.eventLoop().newPromise(); final Invocation invocation = new Invocation(ctx, options, responsePromise, encodeResult.content()); //write request final ChannelFuture writeFuture = writeRequest(channel, invocation, ctx, options); writeFuture.addListener(fut -> { if (!fut.isSuccess()) { ctx.rejectPromise(responsePromise, fut.cause()); } else { long responseTimeoutMillis = options.responseTimeoutPolicy().timeout(ctx); scheduleTimeout(channel, responsePromise, responseTimeoutMillis, false); } }); //handle response if (responsePromise.isSuccess()) { decodeResult(codec, resultPromise, ctx, responsePromise.getNow()); } else { responsePromise.addListener((Future<FullHttpResponse> future) -> { if (future.isSuccess()) { decodeResult(codec, resultPromise, ctx, responsePromise.getNow()); } else { ctx.rejectPromise(resultPromise, future.cause()); } }); } } else { final Throwable cause = encodeResult.cause(); if (!resultPromise.tryFailure(cause)) { logger.warn("Failed to reject an invocation promise ({}) with {}", resultPromise, cause, cause); } } if (!session.onRequestSent()) { // Can't send a request via the current session anymore; do not return the channel to the pool. return; } // Return the channel to the pool. final KeyedChannelPool<PoolKey> pool = KeyedChannelPool.findPool(channel); if (sessionProtocol.isMultiplex()) { pool.release(poolKey, channel); } else { resultPromise.addListener(fut -> pool.release(poolKey, channel)); } }
From source file:org.redisson.connection.RedisClientEntry.java
License:Apache License
private RedisConnection connect() { RedisConnection c = client.connect(); Promise<RedisConnection> future = manager.newPromise(); manager.getConnectListener().onConnect(future, c, null, manager.getConfig()); future.syncUninterruptibly();/* w w w . j a va 2 s . co m*/ return future.getNow(); }