Skip to content

Commit 85c87b5

Browse files
committed
code cleanup in async request executors; fixed interface downcast ot its implementation
1 parent e1ebe30 commit 85c87b5

2 files changed

Lines changed: 21 additions & 20 deletions

File tree

httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2MultiplexingRequester.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,14 @@ public void failed(final Exception cause) {
266266
};
267267
final int max = maxCommandsPerConnection;
268268
if (max > 0) {
269-
final int current = ioSession.getPendingCommandCount();
270-
if (current >= 0 && current >= max) {
271-
exchangeHandler.failed(new RejectedExecutionException(
272-
"Maximum number of pending commands per connection reached (max=" + max + ")"));
273-
exchangeHandler.releaseResources();
269+
final int pending = ioSession.getPendingCommandCount();
270+
if (pending >= 0 && pending >= max) {
271+
try {
272+
exchangeHandler.failed(new RejectedExecutionException(
273+
"Maximum number of pending commands per connection reached (max=" + max + ")"));
274+
} finally {
275+
exchangeHandler.releaseResources();
276+
}
274277
return;
275278
}
276279
}

httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -289,21 +289,6 @@ public void execute(
289289

290290
@Override
291291
public void completed(final AsyncClientEndpoint endpoint) {
292-
final int max = maxPendingCommandsPerConnection;
293-
if (max > 0) {
294-
final IOSession ioSession = ((InternalAsyncClientEndpoint) endpoint).getIOSession();
295-
final int pending = ioSession.getPendingCommandCount();
296-
if (pending >= 0 && pending >= max) {
297-
try {
298-
endpoint.releaseAndReuse();
299-
exchangeHandler.failed(new RejectedExecutionException(
300-
"Maximum number of pending requests per connection reached (max=" + max + ")"));
301-
} finally {
302-
exchangeHandler.releaseResources();
303-
}
304-
return;
305-
}
306-
}
307292
endpoint.execute(new AsyncClientExchangeHandler() {
308293

309294
@Override
@@ -521,6 +506,19 @@ public void execute(
521506
final HandlerFactory<AsyncPushConsumer> pushHandlerFactory,
522507
final HttpContext context) {
523508
final IOSession ioSession = getIOSession();
509+
final int max = maxPendingCommandsPerConnection;
510+
if (max > 0) {
511+
final int pending = ioSession.getPendingCommandCount();
512+
if (pending >= 0 && pending >= max) {
513+
try {
514+
exchangeHandler.failed(new RejectedExecutionException(
515+
"Maximum number of pending commands per connection reached (max=" + max + ")"));
516+
} finally {
517+
exchangeHandler.releaseResources();
518+
}
519+
return;
520+
}
521+
}
524522
ioSession.enqueue(
525523
new RequestExecutionCommand(exchangeHandler, pushHandlerFactory, context),
526524
Command.Priority.NORMAL);

0 commit comments

Comments
 (0)