Class NettyResponseFuture<V>

  • Type Parameters:
    V - the result type
    All Implemented Interfaces:
    Future<V>, ListenableFuture<V>

    public final class NettyResponseFuture<V>
    extends Object
    implements ListenableFuture<V>
    A Future that can be used to track when an asynchronous HTTP request has been fully processed.
    • Field Detail

      • pendingException

        public Throwable pendingException
    • Method Detail

      • takePartitionKeyLock

        public Object takePartitionKeyLock()
      • isDone

        public boolean isDone()
        Specified by:
        isDone in interface Future<V>
      • isCancelled

        public boolean isCancelled()
        Specified by:
        isCancelled in interface Future<V>
      • cancel

        public boolean cancel​(boolean force)
        Specified by:
        cancel in interface Future<V>
      • done

        public void done()
        Description copied from interface: ListenableFuture
        Terminate and if there is no exception, mark this Future as done and release the internal lock.
        Specified by:
        done in interface ListenableFuture<V>
      • touch

        public void touch()
        Description copied from interface: ListenableFuture
        Touch the current instance to prevent external service to times out.
        Specified by:
        touch in interface ListenableFuture<V>
      • addListener

        public ListenableFuture<V> addListener​(Runnable listener,
                                               Executor exec)
        Description copied from interface: ListenableFuture
        Adds a listener and executor to the ListenableFuture. The listener will be passed to the executor for execution when the Future's computation is complete.
        Executor can be null, in that case executor will be executed in the thread where completion happens.
        There is no guaranteed ordering of execution of listeners, they may get called in the order they were added, and they may get called out of order, but any listener added through this method is guaranteed to be called once the computation is complete.
        Specified by:
        addListener in interface ListenableFuture<V>
        Parameters:
        listener - the listener to run when the computation is complete.
        exec - the executor to run the listener in.
        Returns:
        this Future
      • getUri

        public Uri getUri()
      • setProxyServer

        public void setProxyServer​(ProxyServer proxyServer)
        Points this future at the proxy serving its current target, recomputing the partition key so the key names the route actually in use. Only a replay onto a different origin needs this. Setting it without recomputing, or recomputing before it is set, files a proxied connection under the direct key for the new host, and the next direct request to that host then draws a socket that runs through the proxy.
      • cancelTimeouts

        public void cancelTimeouts()
      • getTargetRequest

        public Request getTargetRequest()
      • setTargetRequest

        public void setTargetRequest​(Request targetRequest)
      • getCurrentRequest

        public Request getCurrentRequest()
      • setCurrentRequest

        public void setCurrentRequest​(Request currentRequest)
      • setNettyRequest

        public void setNettyRequest​(NettyRequest nettyRequest)
      • setAsyncHandler

        public void setAsyncHandler​(AsyncHandler<V> asyncHandler)
      • isKeepAlive

        public boolean isKeepAlive()
      • setKeepAlive

        public void setKeepAlive​(boolean keepAlive)
      • incrementAndGetCurrentRedirectCount

        public int incrementAndGetCurrentRedirectCount()
      • setTimeoutsHolder

        public void setTimeoutsHolder​(TimeoutsHolder timeoutsHolder)
      • isInAuth

        public boolean isInAuth()
      • setInAuth

        public void setInAuth​(boolean inAuth)
      • isAndSetInAuth

        public boolean isAndSetInAuth​(boolean set)
      • isInProxyAuth

        public boolean isInProxyAuth()
      • setInProxyAuth

        public void setInProxyAuth​(boolean inProxyAuth)
      • isAndSetInProxyAuth

        public boolean isAndSetInProxyAuth​(boolean inProxyAuth)
      • setChannelState

        public void setChannelState​(ChannelState channelState)
      • isStreamConsumed

        public boolean isStreamConsumed()
      • setStreamConsumed

        public void setStreamConsumed​(boolean streamConsumed)
      • getLastTouch

        public long getLastTouch()
      • isHeadersAlreadyWrittenOnContinue

        public boolean isHeadersAlreadyWrittenOnContinue()
      • setHeadersAlreadyWrittenOnContinue

        public void setHeadersAlreadyWrittenOnContinue​(boolean headersAlreadyWrittenOnContinue)
      • isDontWriteBodyBecauseExpectContinue

        public boolean isDontWriteBodyBecauseExpectContinue()
      • setDontWriteBodyBecauseExpectContinue

        public void setDontWriteBodyBecauseExpectContinue​(boolean dontWriteBodyBecauseExpectContinue)
      • isConnectAllowed

        public boolean isConnectAllowed()
      • setConnectAllowed

        public void setConnectAllowed​(boolean allowConnect)
      • isTunnelEstablished

        public boolean isTunnelEstablished()
        Whether a proxy CONNECT on the currently attached channel succeeded, so the socket now carries a tunnel to the origin rather than a plaintext hop to the proxy. Only ConnectSuccessInterceptor sets this, and setNettyRequest(org.asynchttpclient.netty.request.NettyRequest) clears it again the moment another CONNECT is attached, so it always describes the CONNECT in flight rather than an earlier one.
      • setTunnelEstablished

        public void setTunnelEstablished​(boolean tunnelEstablished)
      • attachChannel

        public void attachChannel​(io.netty.channel.Channel channel,
                                  boolean reuseChannel)
      • channel

        public io.netty.channel.Channel channel()
      • isReuseChannel

        public boolean isReuseChannel()
      • setReuseChannel

        public void setReuseChannel​(boolean reuseChannel)
      • incrementRetryAndCheck

        public boolean incrementRetryAndCheck()
      • isReplayPossible

        public boolean isReplayPossible()
        Return true if the Future can be recovered. There is some scenario where a connection can be closed by an unexpected IOException, and in some situation we can recover from that exception.
        Returns:
        true if that Future cannot be recovered.
      • getStart

        public long getStart()
      • getPartitionKey

        public Object getPartitionKey()
      • basePartitionKey

        public Object basePartitionKey()
        The per-host base partition key, ignoring any round-robin IP-aware override. This is the key used to acquire the connection semaphore (so maxConnectionsPerHost stays per host, not per IP: the permit is taken before the target IP is known and the connector may fail over to a different IP than the one initially selected), to offer the channel back to the pool, and to register/poll the HTTP/2 connection registry; in round-robin mode it is also the base that the per-IP override (RoundRobinPartitionKey) wraps.

        Note: the pool/H2 poll paths (NettyRequestSender pollPooledChannel/waitForHttp2Connection) intentionally derive their key from the live request rather than this value, because a filter replay can reuse a future without updating its targetRequest.

        Computed eagerly at construction and recomputed by setTargetRequest(Request); this accessor is a plain read of the memoized value.

      • getPartitionKeyOverride

        public Object getPartitionKeyOverride()
        Returns:
        the IP-aware partition key set for LoadBalance.ROUND_ROBIN, or null when not in round-robin mode
      • setPartitionKeyOverride

        public void setPartitionKeyOverride​(Object partitionKeyOverride)
      • getRoundRobinAddresses

        public List<InetSocketAddress> getRoundRobinAddresses()
        Returns:
        the resolved addresses to connect to (round-robin-ordered), or null to resolve lazily as usual
      • setRoundRobinAddresses

        public void setRoundRobinAddresses​(List<InetSocketAddress> roundRobinAddresses)
      • getRoundRobinBaseUri

        public Uri getRoundRobinBaseUri()
        Returns:
        the base URI (scheme, host and port) the round-robin overrides were computed for, used to detect base changes on redirects — including same-host scheme/port changes such as an HTTP-to-HTTPS upgrade, whose resolved addresses and partition key differ from the cached ones
      • setRoundRobinBaseUri

        public void setRoundRobinBaseUri​(Uri roundRobinBaseUri)
      • clearRoundRobinOverrides

        public void clearRoundRobinOverrides()
        Drops any round-robin overrides, e.g. when this future is reused for a cross-host redirect whose target is not eligible for round-robin.
      • repinRoundRobinAddress

        public void repinRoundRobinAddress​(InetAddress actualAddress)
        Re-pins the round-robin partition key to the IP actually connected to. The connector may have failed over from the initially selected IP to a later one; keying connection reuse by the real peer IP keeps the pool / HTTP/2 registry correct. No-op outside round-robin mode.
      • acquirePartitionLockLazily

        public void acquirePartitionLockLazily()
                                        throws IOException
        Throws:
        IOException
      • acquirePartitionLockLazily

        public void acquirePartitionLockLazily​(boolean nonBlocking)
                                        throws IOException
        Lazily acquires this request's per-host connection permit.
        Parameters:
        nonBlocking - when true, acquire the permit without waiting (fail fast) — required when called on a Netty event-loop thread, where a blocking acquire would freeze the loop. Off the loop (the initial execute() on the caller thread) pass false to keep the configured acquire-timeout wait.
        Throws:
        IOException
      • getRealm

        public Realm getRealm()
      • setRealm

        public void setRealm​(Realm realm)
      • getProxyRealm

        public Realm getProxyRealm()
      • setProxyRealm

        public void setProxyRealm​(Realm proxyRealm)
      • setScramContext

        public void setScramContext​(ScramContext scramContext)