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(); } } }