private static void initialize(Configuration conf, Channel channel, DatanodeInfo dnInfo, Enum<?> storageType, OpWriteBlockProto.Builder writeBlockProtoBuilder, int timeoutMs, DFSClient client, Token<BlockTokenIdentifier> accessToken, Promise<Channel> promise) throws IOException { Promise<Void> saslPromise = channel.eventLoop().newPromise(); trySaslNegotiate(conf, channel, dnInfo, timeoutMs, client, accessToken, saslPromise); saslPromise.addListener(new FutureListener<Void>() { @Override public void operationComplete(Future<Void> future) throws Exception { if (future.isSuccess()) { // setup response processing pipeline first, then send request. processWriteBlockResponse(channel, dnInfo, promise, timeoutMs); requestWriteBlock(channel, storageType, writeBlockProtoBuilder); } else { promise.tryFailure(future.cause()); } } }); }
@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); }
private void tryComplete(ChannelHandlerContext ctx) { if (!saslRpcClient.isComplete()) { return; } saslRpcClient.setupSaslHandler(ctx.pipeline()); setCryptoAESOption(); saslPromise.setSuccess(true); }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { promise.tryFailure(cause); } });
@Override protected void doResolve(String inetHost, Promise<InetAddress> promise) throws Exception { try { promise.setSuccess(SocketUtils.addressByName(inetHost)); } catch (UnknownHostException e) { promise.setFailure(e); } }
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);
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()); } } } }
closePromise = promise; } else { closePromise.addListener(new UnaryPromiseNotifier<Void>(promise)); promise.trySuccess(null); return promise;
private void applyHandshakeTimeout(Promise<Channel> p) { final Promise<Channel> promise = p == null ? handshakePromise : p; // Set timeout if necessary. final long handshakeTimeoutMillis = this.handshakeTimeoutMillis; if (handshakeTimeoutMillis <= 0 || promise.isDone()) { return; } final ScheduledFuture<?> timeoutFuture = ctx.executor().schedule(new Runnable() { @Override public void run() { if (promise.isDone()) { return; } try { notifyHandshakeFailure(HANDSHAKE_TIMED_OUT); } finally { releaseAndFailAll(HANDSHAKE_TIMED_OUT); } } }, handshakeTimeoutMillis, TimeUnit.MILLISECONDS); // Cancel the handshake timeout when handshake is finished. promise.addListener(new FutureListener<Channel>() { @Override public void operationComplete(Future<Channel> f) throws Exception { timeoutFuture.cancel(false); } }); }
/** * 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); } } }
/** * Try to mark the {@link Promise} as failure and log if {@code logger} is not {@code null} in case this fails. */ public static void tryFailure(Promise<?> p, Throwable cause, InternalLogger logger) { if (!p.tryFailure(cause) && logger != null) { Throwable err = p.cause(); if (err == null) { logger.warn("Failed to mark a promise as failure because it has succeeded already: {}", p, cause); } else { logger.warn( "Failed to mark a promise as failure because it has failed already: {}, unnotified cause: {}", p, ThrowableUtil.stackTraceToString(err), cause); } } }
@Override public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { promise.setSuccess(streamChannel); } else if (future.isCancelled()) { promise.cancel(false); } else { if (streamChannel.isRegistered()) { streamChannel.close(); } else { streamChannel.unsafe().closeForcibly(); } promise.setFailure(future.cause()); } } });
promise.setFailure(POOL_CLOSED_ON_ACQUIRE_EXCEPTION); return; AcquireListener l = new AcquireListener(promise); l.acquired(); p.addListener(l); super.acquire(p); } else { if (pendingAcquireCount >= maxPendingAcquires) { promise.setFailure(FULL_EXCEPTION); } else { AcquireTask task = new AcquireTask(promise); promise.setFailure(FULL_EXCEPTION);
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(); } } }
/** * Try to cancel the {@link Promise} and log if {@code logger} is not {@code null} in case this fails. */ public static void tryCancel(Promise<?> p, InternalLogger logger) { if (!p.cancel(false) && logger != null) { Throwable err = p.cause(); if (err == null) { logger.warn("Failed to cancel promise because it has succeeded already: {}", p); } else { logger.warn( "Failed to cancel promise because it has failed already: {}, unnotified cause:", p, err); } } }
final DnsQueryLifecycleObserver queryLifecycleObserver, final Promise<T> promise) { if (nameServerAddrStreamIndex >= nameServerAddrStream.size() || allowedQueries == 0 || promise.isCancelled()) { tryToFinishResolve(nameServerAddrStream, nameServerAddrStreamIndex, question, queryLifecycleObserver, promise);
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { saslPromise.tryFailure(cause); }
@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); } }
promise.trySuccess(ctx.channel());
if (earlyPromise != null) { if (earlyPromise.isDone()) { transferResult(earlyPromise, promise); } else { earlyPromise.addListener(new FutureListener<U>() { @Override public void operationComplete(Future<U> f) throws Exception { if (promise.isDone()) { resolveMap.remove(inetHost); } else { promise.addListener(new FutureListener<U>() { @Override public void operationComplete(Future<U> f) throws Exception {