Clarified HttpReceiver.responseFailure().

Added javadocs to relevant methods in HttpChannel.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
Simone Bordet 2022-12-07 23:50:39 +01:00
parent 119996c16f
commit bc0b4149ff
No known key found for this signature in database
GPG Key ID: 1677D141BCF3584D
2 changed files with 21 additions and 11 deletions

View File

@ -78,6 +78,12 @@ public abstract class HttpChannel implements CyclicTimeouts.Expirable
return result;
}
/**
* <p>Disassociates the exchange from this channel.</p>
*
* @param exchange the current exchange that must be already completed
* @return true if the exchange was disassociated, false otherwise
*/
public boolean disassociate(HttpExchange exchange)
{
boolean result = false;
@ -97,6 +103,14 @@ public abstract class HttpChannel implements CyclicTimeouts.Expirable
return result;
}
/**
* <p>Returns the {@code HttpExchange} currently associated
* with this channel, possibly {@code null}.</p>
* <p>The exchange may be completed and disassociated concurrently,
* so callers must act atomically on the exchange.</p>
*
* @return the {@code HttpExchange} currently associated with this channel, possibly {@code null}.
*/
public HttpExchange getHttpExchange()
{
try (AutoLock l = _lock.lock())

View File

@ -386,24 +386,20 @@ public abstract class HttpReceiver
LOG.debug("Failing with {} on {}", failure, this);
HttpExchange exchange = getHttpExchange();
// In case of a response error, the failure has already been notified
// and it is possible that a further attempt to read in the receive
// loop throws an exception that reenters here but without exchange;
// or, the server could just have timed out the connection.
if (exchange == null)
{
promise.succeeded(false);
return;
}
// Mark atomically the response as completed, with respect
// to concurrency between response success and response failure.
boolean completed = exchange.responseComplete(failure);
if (completed)
if (exchange != null && exchange.responseComplete(failure))
{
abort(exchange, failure, promise);
}
else
{
// The response was already completed (either successfully
// or with a failure) by a previous event, bail out.
promise.succeeded(false);
}
}
private void terminateResponse(HttpExchange exchange)
{