@Override public void operationComplete(Future<Channel> future) throws Exception { if (future.isSuccess()) { future.getNow().close(); } } });
for (int i = 0, n = futureList.size(); i < n; i++) { try { datanodeList.add(futureList.get(i).syncUninterruptibly().getNow()); } catch (Exception e) {
@Override public void operationComplete(Future<AddressedEnvelope<DnsResponse, InetSocketAddress>> future) { if (future.isSuccess()) { future.getNow().release(); } } };
@Override public void operationComplete(Future<List<InetAddress>> future) throws Exception { if (future.isSuccess()) { List<InetAddress> inetAddresses = future.getNow(); List<InetSocketAddress> socketAddresses = new ArrayList<InetSocketAddress>(inetAddresses.size()); for (InetAddress inetAddress : inetAddresses) { socketAddresses.add(new InetSocketAddress(inetAddress, unresolvedAddress.getPort())); } promise.setSuccess(socketAddresses); } else { promise.setFailure(future.cause()); } } });
@Override public void operationComplete(Future<InetAddress> future) throws Exception { if (future.isSuccess()) { promise.setSuccess(new InetSocketAddress(future.getNow(), unresolvedAddress.getPort())); } else { promise.setFailure(future.cause()); } } });
@Override public void operationComplete(Future<List<T>> future) throws Exception { if (future.isSuccess()) { promise.setSuccess(future.getNow()); } else { doResolveAllRec(inetHost, promise, resolverIndex + 1, future.cause()); } } });
@Override public void operationComplete(Future<T> future) throws Exception { if (future.isSuccess()) { promise.setSuccess(future.getNow()); } else { doResolveRec(inetHost, promise, resolverIndex + 1, future.cause()); } } });
@Override public void operationComplete(Future<List<InetAddress>> future) throws Exception { if (future.isSuccess()) { List<InetAddress> inetAddresses = future.getNow(); int numAddresses = inetAddresses.size(); if (numAddresses > 0) { // if there are multiple addresses: we shall pick one by one // to support the round robin distribution promise.setSuccess(inetAddresses.get(randomIndex(numAddresses))); } else { promise.setFailure(new UnknownHostException(inetHost)); } } else { promise.setFailure(future.cause()); } } });
/** * Adds the channel back to the pool only if the channel is healthy. * @param channel the channel to put back to the pool * @param promise offer operation promise. * @param future the future that contains information fif channel is healthy or not. * @throws Exception in case when failed to notify handler about release operation. */ private void releaseAndOfferIfHealthy(Channel channel, Promise<Void> promise, Future<Boolean> future) throws Exception { if (future.getNow()) { //channel turns out to be healthy, offering and releasing it. releaseAndOffer(channel, promise); } else { //channel not healthy, just releasing it. handler.channelReleased(channel); promise.setSuccess(null); } }
@Override public void operationComplete(Future<List<InetAddress>> future) throws Exception { if (future.isSuccess()) { List<InetAddress> inetAddresses = future.getNow(); if (!inetAddresses.isEmpty()) { // create a copy to make sure that it's modifiable random access collection List<InetAddress> result = new ArrayList<InetAddress>(inetAddresses); // rotate by different distance each time to force round robin distribution Collections.rotate(result, randomIndex(inetAddresses.size())); promise.setSuccess(result); } else { promise.setSuccess(inetAddresses); } } else { promise.setFailure(future.cause()); } } });
@Override public int pendingTasks() { // As we use a MpscQueue we need to ensure pendingTasks() is only executed from within the EventLoop as // otherwise we may see unexpected behavior (as size() is only allowed to be called by a single consumer). // See https://github.com/netty/netty/issues/5297 if (inEventLoop()) { return super.pendingTasks(); } else { return submit(pendingTasksCallable).syncUninterruptibly().getNow(); } } /**
@Override public void operationComplete(Future<SocketAddress> future) throws Exception { if (future.cause() != null) { channel.close(); promise.setFailure(future.cause()); } else { doConnect(future.getNow(), localAddress, promise); } } });
private static <T> void transferResult(Future<T> src, Promise<T> dst) { if (src.isSuccess()) { dst.trySuccess(src.getNow()); } else { dst.tryFailure(src.cause()); } }
@Override public int pendingTasks() { // As we use a MpscQueue we need to ensure pendingTasks() is only executed from within the EventLoop as // otherwise we may see unexpected behavior (as size() is only allowed to be called by a single consumer). // See https://github.com/netty/netty/issues/5297 if (inEventLoop()) { return super.pendingTasks(); } else { return submit(pendingTasksCallable).syncUninterruptibly().getNow(); } }
@Override public int pendingTasks() { // As we use a MpscQueue we need to ensure pendingTasks() is only executed from within the EventLoop as // otherwise we may see unexpected behavior (as size() is only allowed to be called by a single consumer). // See https://github.com/netty/netty/issues/5297 return inEventLoop() ? super.pendingTasks() : submit(pendingTasksCallable).syncUninterruptibly().getNow(); }
@Override public void operationComplete(Future<Channel> future) throws Exception { if (future.isSuccess()) { newHandshakePromise.setSuccess(future.getNow()); } else { newHandshakePromise.setFailure(future.cause()); } } });
@Override public void operationComplete(Future<T> future) throws Exception { if (future.isSuccess()) { promise.trySuccess(future.getNow()); } else if (count < parent.searchDomains().length) { doSearchDomainQuery(count++, this); } else { promise.tryFailure(new SearchDomainUnknownHostException(future.cause(), hostname)); } } });
@Override protected final void onLookupComplete(ChannelHandlerContext ctx, String hostname, Future<SslContext> future) throws Exception { if (!future.isSuccess()) { final Throwable cause = future.cause(); if (cause instanceof Error) { throw (Error) cause; } throw new DecoderException("failed to get the SslContext for " + hostname, cause); } SslContext sslContext = future.getNow(); selection = new Selection(sslContext, hostname); try { replaceHandler(ctx, hostname, sslContext); } catch (Throwable cause) { selection = EMPTY_SELECTION; PlatformDependent.throwException(cause); } }
public static <X> void cascadeTo(Future<X> completedFuture, Promise<? super X> promise) { if (completedFuture.isSuccess()) { if (!promise.trySuccess(completedFuture.getNow())) { logger.warn("Failed to mark a promise as success because it is done already: {}", promise); } } else if (completedFuture.isCancelled()) { if (!promise.cancel(false)) { logger.warn("Failed to cancel a promise because it is done already: {}", promise); } } else { if (!promise.tryFailure(completedFuture.cause())) { logger.warn("Failed to mark a promise as failure because it's done already: {}", promise, completedFuture.cause()); } } } }
private void notifyHealthCheck(Future<Boolean> future, Channel ch, Promise<Channel> promise) { assert ch.eventLoop().inEventLoop(); if (future.isSuccess()) { if (future.getNow()) { try { ch.attr(POOL_KEY).set(this); handler.channelAcquired(ch); promise.setSuccess(ch); } catch (Throwable cause) { closeAndFail(ch, cause, promise); } } else { closeChannel(ch); acquireHealthyFromPoolOrNew(promise); } } else { closeChannel(ch); acquireHealthyFromPoolOrNew(promise); } }