@Override protected void doResolve(SocketAddress unresolvedAddress, Promise<SocketAddress> promise) throws Exception { promise.setSuccess(unresolvedAddress); }
@Override protected void doResolveAll( SocketAddress unresolvedAddress, Promise<List<SocketAddress>> promise) throws Exception { promise.setSuccess(Collections.singletonList(unresolvedAddress)); } }
@Override public void operationComplete(Future<Object> future) throws Exception { if (terminatedChildren.incrementAndGet() == children.length) { terminationFuture.setSuccess(null); } } };
@Override protected void doResolveAll( SocketAddress unresolvedAddress, Promise<List<SocketAddress>> promise) throws Exception { promise.setSuccess(Collections.singletonList(unresolvedAddress)); } }
@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()); } } });
/** * Mark the underlying {@link Promise} successfully and recycle this instance. */ public boolean successAndRecycle() { if (promise != null) { promise.setSuccess(null); } return recycle(); }
@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<T>> future) throws Exception { if (future.isSuccess()) { promise.setSuccess(future.getNow()); } else { doResolveAllRec(inetHost, promise, resolverIndex + 1, 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<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<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 protected void doResolveAll(String inetHost, Promise<List<InetAddress>> promise) throws Exception { try { promise.setSuccess(Arrays.asList(SocketUtils.allAddressesByName(inetHost))); } catch (UnknownHostException e) { promise.setFailure(e); } } }
@Override protected void doResolve(String inetHost, Promise<InetAddress> promise) throws Exception { try { promise.setSuccess(SocketUtils.addressByName(inetHost)); } catch (UnknownHostException e) { promise.setFailure(e); } }
@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()); } } });
@Override protected void doResolveAll(String inetHost, Promise<List<InetAddress>> promise) throws Exception { try { promise.setSuccess(Arrays.asList(SocketUtils.allAddressesByName(inetHost))); } catch (UnknownHostException e) { promise.setFailure(e); } } }
@Override public Future<SslContext> map(String input, Promise<SslContext> promise) { final SslContext context; try { context = mapping.map(input); } catch (Throwable cause) { return promise.setFailure(cause); } return promise.setSuccess(context); } }
private void releaseAndOffer(Channel channel, Promise<Void> promise) throws Exception { if (offerChannel(channel)) { handler.channelReleased(channel); promise.setSuccess(null); } else { closeAndFail(channel, FULL_EXCEPTION, promise); } }
/** * 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); } }
private void releaseAndOffer(Channel channel, Promise<Void> promise) throws Exception { if (offerChannel(channel)) { handler.channelReleased(channel); promise.setSuccess(null); } else { closeAndFail(channel, FULL_EXCEPTION, promise); } }