Skip to content

Commit

Permalink
Remove accidental use of completedFuture
Browse files Browse the repository at this point in the history
  • Loading branch information
io7m committed Apr 27, 2023
1 parent f3e1751 commit f5f76df
Showing 1 changed file with 27 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,41 +145,21 @@ private void runCommandProcessing()
private void executeClose(
final OpType.Close<X, C, R, RS, RF, E, CR> close)
{
/*
* Cancel all pending operations in the queue. The guard on the "closed"
* atomic boolean prevents new operations from being submitted after a
* close request has been submitted, so there should be no risk of
* operations submitted after closing hanging forever.
*/

try {
if (LOG.isTraceEnabled()) {
LOG.trace("close op executing");
}
try {
if (LOG.isTraceEnabled()) {
LOG.trace("close op executing");
}

this.operationQueue.forEach(op -> {
if (!Objects.equals(close.future, op.future())) {
op.future().cancel(true);
try {
this.delegate.close();
} catch (final Exception e) {
LOG.debug("close op: ", e);
}
});
try {
this.delegate.close();
} catch (final Exception e) {
LOG.debug("close op: ", e);
} finally {
this.executeCloseShutdownExecutor();
}
} finally {
if (LOG.isTraceEnabled()) {
LOG.trace("close op shutting down executor");
}

this.commandExecutor.shutdown();

try {
this.commandExecutor.awaitTermination(1L, TimeUnit.SECONDS);
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
}

close.future.complete(null);

if (LOG.isTraceEnabled()) {
Expand All @@ -188,6 +168,21 @@ private void executeClose(
}
}

private void executeCloseShutdownExecutor()
{
if (LOG.isTraceEnabled()) {
LOG.trace("close op shutting down executor");
}

this.commandExecutor.shutdown();

try {
this.commandExecutor.awaitTermination(1L, TimeUnit.SECONDS);
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
}
}

private void executeDisconnect(
final OpType.Disconnect<X, C, R, RS, RF, E, CR> disconnect)
{
Expand Down Expand Up @@ -316,8 +311,7 @@ public final void close()
LOG.trace("close scheduled");
}

final var future =
CompletableFuture.completedFuture(null);
final var future = new CompletableFuture<Void>();
this.operationQueue.add(new OpType.Close<>(future));

try {
Expand Down Expand Up @@ -403,7 +397,7 @@ record Close<
RF extends R,
E extends HBEventType,
CR extends HBCredentialsType>(
CompletableFuture<Object> future)
CompletableFuture<Void> future)
implements HBClientAsynchronousAbstract.OpType<X, C, R, RS, RF, E, CR>
{

Expand Down

0 comments on commit f5f76df

Please sign in to comment.