Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor channel closure handling #118

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,8 @@ public void distributeClosingException(String message) {
}

public void shutdownGracefully() {
responses
.values()
.forEach(
future ->
future.completeExceptionally(
new ClosingException(
"Operation terminated: The closing process has been initiated for the"
+ " resource.")));
String msg = "Operation terminated: The closing process has been initiated for the resource.";
responses.values().forEach(future -> future.completeExceptionally(new ClosingException(msg)));
responses.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ public class ChannelHandler {

protected final Channel channel;
protected final CallbackDispatcher callbackDispatcher;
private boolean isClosed = false;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use AtomicBoolean which is thread safe

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: except that the variable is bi-directional. It doesn't matter if multiple threads set isClosed to true, it will be true.


public boolean isClosed() {
return !channel.isOpen();
return this.isClosed;
}

/**
Expand Down Expand Up @@ -88,6 +89,7 @@ public CompletableFuture<Response> connect(ConnectionRequest request) {

/** Closes the UDS connection and frees corresponding resources. */
public ChannelFuture close() {
this.isClosed = true;
callbackDispatcher.shutdownGracefully();
return channel.close();
}
Expand Down
Loading