HTTPCORE-672: cleanup of H2 connection validation code

This commit is contained in:
Oleg Kalnichevski 2021-04-02 22:00:52 +02:00
parent f597588198
commit 935abae04e
1 changed files with 25 additions and 24 deletions

View File

@ -243,37 +243,38 @@ public class PoolingAsyncClientConnectionManager implements AsyncClientConnectio
@Override
public void completed(final PoolEntry<HttpRoute, ManagedAsyncClientConnection> poolEntry) {
final ManagedAsyncClientConnection connection = poolEntry.getConnection();
final TimeValue timeValue = PoolingAsyncClientConnectionManager.this.validateAfterInactivity;
if (TimeValue.isNonNegative(timeValue) && connection != null &&
poolEntry.getUpdated() + timeValue.toMilliseconds() <= System.currentTimeMillis()) {
final ProtocolVersion protocolVersion = connection.getProtocolVersion();
if (protocolVersion != null && protocolVersion.greaterEquals(HttpVersion.HTTP_2_0)) {
connection.submitCommand(new PingCommand(new BasicPingHandler(new Callback<Boolean>() {
if (connection != null) {
if (connection.isOpen()) {
final ProtocolVersion protocolVersion = connection.getProtocolVersion();
if (protocolVersion != null && protocolVersion.greaterEquals(HttpVersion.HTTP_2_0)) {
final TimeValue timeValue = PoolingAsyncClientConnectionManager.this.validateAfterInactivity;
if (TimeValue.isNonNegative(timeValue) &&
poolEntry.getUpdated() + timeValue.toMilliseconds() <= System.currentTimeMillis()) {
connection.submitCommand(new PingCommand(new BasicPingHandler(new Callback<Boolean>() {
@Override
public void execute(final Boolean result) {
if (result == null || !result) {
if (LOG.isDebugEnabled()) {
LOG.debug("{} connection {} is stale", id, ConnPoolSupport.getId(connection));
@Override
public void execute(final Boolean result) {
if (result == null || !result) {
if (LOG.isDebugEnabled()) {
LOG.debug("{} connection {} is stale", id, ConnPoolSupport.getId(connection));
}
poolEntry.discardConnection(CloseMode.IMMEDIATE);
}
leaseCompleted(poolEntry);
}
poolEntry.discardConnection(CloseMode.IMMEDIATE);
}
leaseCompleted(poolEntry);
}
})), Command.Priority.IMMEDIATE);
} else {
if (!connection.isOpen()) {
if (LOG.isDebugEnabled()) {
LOG.debug("{} connection {} is closed", id, ConnPoolSupport.getId(connection));
})), Command.Priority.IMMEDIATE);
return;
}
poolEntry.discardConnection(CloseMode.IMMEDIATE);
}
leaseCompleted(poolEntry);
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("{} connection {} is closed", id, ConnPoolSupport.getId(connection));
}
poolEntry.discardConnection(CloseMode.IMMEDIATE);
}
} else {
leaseCompleted(poolEntry);
}
leaseCompleted(poolEntry);
}
@Override