Skip to content

Commit

Permalink
apply comments (3rd)
Browse files Browse the repository at this point in the history
  • Loading branch information
t-horikawa committed May 10, 2024
1 parent b1570c2 commit cc4aa4b
Showing 1 changed file with 48 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public void setCloseTimeout(@Nullable Timeout timeout) {

@Override
public synchronized void close() throws IOException, ServerException, InterruptedException {
Exception exception = null;
try {
if (!gotton.getAndSet(true)) {
if (closeTimeout != null) {
Expand All @@ -159,7 +160,8 @@ public synchronized void close() throws IOException, ServerException, Interrupte
sr.close();
}
} catch (TimeoutException e) {
throw new IOException(e);
exception = new ResponseTimeoutException(e);
throw (ResponseTimeoutException) exception;
}
} else {
var obj = get();
Expand All @@ -170,16 +172,53 @@ public synchronized void close() throws IOException, ServerException, Interrupte
}
}
} finally {
var up = unprocessed.getAndSet(null);
if (closeTimeout != null && up != null) {
up.setCloseTimeout(closeTimeout);
try {
var up = unprocessed.getAndSet(null);
if (closeTimeout != null && up != null) {
up.setCloseTimeout(closeTimeout);
}
Owner.close(up);
} catch (IOException | ServerException | InterruptedException e) {
if (exception == null) {
exception = e;
} else {
exception.addSuppressed(e);
}
throwException(exception);
} finally {
try {
if (closeTimeout != null) {
delegate.setCloseTimeout(closeTimeout);
}
delegate.close();
closed.set(true);
} catch (IOException | ServerException | InterruptedException e) {
if (exception == null) {
exception = e;
} else {
exception.addSuppressed(e);
}
throwException(exception);
}
}
}
}

private void throwException(Exception e) throws IOException, ServerException, InterruptedException {
if (e != null) {
if (e instanceof IOException) {
throw (IOException) e;
}
if (e instanceof InterruptedException) {
throw (InterruptedException) e;
}
if (e instanceof ServerException) {
throw (ServerException) e;
}
Owner.close(up);
if (closeTimeout != null) {
delegate.setCloseTimeout(closeTimeout);
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
delegate.close();
closed.set(true);
throw new AssertionError(e);
}
}

Expand Down

0 comments on commit cc4aa4b

Please sign in to comment.