InetAddress addr = ((InetSocketAddress) channel.remoteAddress()).getAddress(); if (trustedChannelResolver.isTrusted() || trustedChannelResolver.isTrusted(addr)) { saslPromise.trySuccess(null); return; + ", datanodeId = " + dnInfo); saslPromise.trySuccess(null); } else if (dnInfo.getXferPort() < 1024) { if (LOG.isDebugEnabled()) { + "privileged port for addr = " + addr + ", datanodeId = " + dnInfo); saslPromise.trySuccess(null); } else if (fallbackToSimpleAuth != null && fallbackToSimpleAuth.get()) { if (LOG.isDebugEnabled()) { + "unsecured cluster for addr = " + addr + ", datanodeId = " + dnInfo); saslPromise.trySuccess(null); } else if (saslPropsResolver != null) { if (LOG.isDebugEnabled()) { + "protection configured for addr = " + addr + ", datanodeId = " + dnInfo); saslPromise.trySuccess(null);
@Override protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception { int len = msg.readInt(); if (len == SaslUtil.SWITCH_TO_SIMPLE_AUTH) { saslRpcClient.dispose(); if (saslRpcClient.fallbackAllowed) { saslPromise.trySuccess(false); } else { saslPromise.tryFailure(new FallbackDisallowedException()); } return; } LOG.trace("Reading input token size={} for processing by initSASLContext", len); final byte[] challenge = new byte[len]; msg.readBytes(challenge); byte[] response = ugi.doAs(new PrivilegedExceptionAction<byte[]>() { @Override public byte[] run() throws Exception { return saslRpcClient.evaluateChallenge(challenge); } }); if (response != null) { writeResponse(ctx, response); } tryComplete(ctx); }
promise.trySuccess(ctx.channel());
promise.trySuccess(null); break;
@Override protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception { int len = msg.readInt(); if (len == SaslUtil.SWITCH_TO_SIMPLE_AUTH) { saslRpcClient.dispose(); if (saslRpcClient.fallbackAllowed) { saslPromise.trySuccess(false); } else { saslPromise.tryFailure(new FallbackDisallowedException()); } return; } LOG.trace("Reading input token size={} for processing by initSASLContext", len); final byte[] challenge = new byte[len]; msg.readBytes(challenge); byte[] response = ugi.doAs(new PrivilegedExceptionAction<byte[]>() { @Override public byte[] run() throws Exception { return saslRpcClient.evaluateChallenge(challenge); } }); if (response != null) { writeResponse(ctx, response); } tryComplete(ctx); }
@Override public List<Runnable> shutdownNow() { List<Runnable> tasks = super.shutdownNow(); terminationFuture.trySuccess(null); return tasks; }
@Override public void shutdown() { super.shutdown(); terminationFuture.trySuccess(null); }
@Override public void operationComplete(Future<Object> future) throws Exception { // Inefficient, but works. if (isTerminated()) { terminationFuture.trySuccess(null); } } };
private static <T> void trySuccess(Promise<T> promise, T result) { if (!promise.trySuccess(result)) { logger.warn("Failed to notify success ({}) to a promise: {}", result, promise); } }
private boolean tryPromise() { return (cause == null) ? aggregatePromise.trySuccess(null) : aggregatePromise.tryFailure(cause); }
@Override boolean finishResolve( Class<? extends InetAddress> addressType, List<DnsCacheEntry> resolvedEntries, Promise<List<InetAddress>> promise) { List<InetAddress> result = null; final int numEntries = resolvedEntries.size(); for (int i = 0; i < numEntries; i++) { final InetAddress a = resolvedEntries.get(i).address(); if (addressType.isInstance(a)) { if (result == null) { result = new ArrayList<InetAddress>(numEntries); } result.add(a); } } if (result != null) { promise.trySuccess(result); return true; } return false; } }
@Override @Deprecated public void shutdown() { shuttingDown = true; for (EventLoop l: activeChildren) { l.shutdown(); } for (EventLoop l: idleChildren) { l.shutdown(); } // Notify the future if there was no children. if (isTerminated()) { terminationFuture.trySuccess(null); } }
/** * Try to mark the {@link Promise} as success and log if {@code logger} is not {@code null} in case this fails. */ public static <V> void trySuccess(Promise<? super V> p, V result, InternalLogger logger) { if (!p.trySuccess(result) && logger != null) { Throwable err = p.cause(); if (err == null) { logger.warn("Failed to mark a promise as success because it has succeeded already: {}", p); } else { logger.warn( "Failed to mark a promise as success because it has failed already: {}, unnotified cause:", p, err); } } }
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 Future<?> shutdownGracefully(long quietPeriod, long timeout, TimeUnit unit) { shuttingDown = true; for (EventLoop l: activeChildren) { l.shutdownGracefully(quietPeriod, timeout, unit); } for (EventLoop l: idleChildren) { l.shutdownGracefully(quietPeriod, timeout, unit); } // Notify the future if there was no children. if (isTerminated()) { terminationFuture.trySuccess(null); } return terminationFuture(); }
private void notifyConnect(ChannelFuture future, Promise<Channel> promise) { if (future.isSuccess()) { Channel channel = future.channel(); if (!promise.trySuccess(channel)) { // Promise was completed in the meantime (like cancelled), just release the channel again release(channel); } } else { promise.tryFailure(future.cause()); } }
/** * Notify all the handshake futures about the successfully handshake */ private void setHandshakeSuccess() { handshakePromise.trySuccess(ctx.channel()); if (logger.isDebugEnabled()) { logger.debug("{} HANDSHAKEN: {}", ctx.channel(), engine.getSession().getCipherSuite()); } ctx.fireUserEventTriggered(SslHandshakeCompletionEvent.SUCCESS); if (readDuringHandshake && !ctx.channel().config().isAutoRead()) { readDuringHandshake = false; ctx.read(); } }
@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)); } } });
private void setSuccess(AddressedEnvelope<? extends DnsResponse, InetSocketAddress> envelope) { parent.queryContextManager.remove(nameServerAddr(), id); // Cancel the timeout task. final ScheduledFuture<?> timeoutFuture = this.timeoutFuture; if (timeoutFuture != null) { timeoutFuture.cancel(false); } Promise<AddressedEnvelope<DnsResponse, InetSocketAddress>> promise = this.promise; if (promise.setUncancellable()) { @SuppressWarnings("unchecked") AddressedEnvelope<DnsResponse, InetSocketAddress> castResponse = (AddressedEnvelope<DnsResponse, InetSocketAddress>) envelope.retain(); if (!promise.trySuccess(castResponse)) { // We failed to notify the promise as it was failed before, thus we need to release the envelope envelope.release(); } } }
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()); } } } }