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

Decouple the WebSocketBase frame aggregator from the frame handler #4799

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Changes from all commits
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
40 changes: 34 additions & 6 deletions src/main/java/io/vertx/core/http/impl/WebSocketImplBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public abstract class WebSocketImplBase<S extends WebSocketBase> implements WebS
private Object metric;
private Handler<Buffer> handler;
private Handler<WebSocketFrameInternal> frameHandler;
private FrameAggregator frameAggregator;
private Handler<Buffer> pongHandler;
private Handler<Void> drainHandler;
private Handler<Throwable> exceptionHandler;
Expand Down Expand Up @@ -525,9 +526,14 @@ protected void handleClose(boolean graceful) {
}

private void receiveFrame(WebSocketFrameInternal frame) {
Handler<WebSocketFrameInternal> frameAggregator;
Handler<WebSocketFrameInternal> frameHandler;
synchronized (conn) {
frameHandler = this.frameHandler;
frameAggregator = this.frameAggregator;
}
if (frameAggregator != null) {
context.dispatch(frame, frameAggregator);
}
if (frameHandler != null) {
context.dispatch(frame, frameHandler);
Expand Down Expand Up @@ -670,10 +676,21 @@ public S frameHandler(Handler<WebSocketFrame> handler) {
public WebSocketBase textMessageHandler(Handler<String> handler) {
synchronized (conn) {
checkClosed();
if (frameHandler == null || frameHandler.getClass() != FrameAggregator.class) {
frameHandler = new FrameAggregator();
if (handler != null) {
if (frameAggregator == null) {
frameAggregator = new FrameAggregator();
}
frameAggregator.textMessageHandler = handler;
} else {
if (frameAggregator != null) {
if (frameAggregator.binaryMessageHandler == null) {
frameAggregator = null;
} else {
frameAggregator.textMessageHandler = null;
frameAggregator.textMessageBuffer = null;
}
}
}
((FrameAggregator) frameHandler).textMessageHandler = handler;
return this;
}
}
Expand All @@ -682,10 +699,21 @@ public WebSocketBase textMessageHandler(Handler<String> handler) {
public S binaryMessageHandler(Handler<Buffer> handler) {
synchronized (conn) {
checkClosed();
if (frameHandler == null || frameHandler.getClass() != FrameAggregator.class) {
frameHandler = new FrameAggregator();
if (handler != null) {
if (frameAggregator == null) {
frameAggregator = new FrameAggregator();
}
frameAggregator.binaryMessageHandler = handler;
} else {
if (frameAggregator != null) {
if (frameAggregator.textMessageHandler == null) {
frameAggregator = null;
} else {
frameAggregator.binaryMessageHandler = null;
frameAggregator.binaryMessageBuffer = null;
}
}
}
((FrameAggregator) frameHandler).binaryMessageHandler = handler;
return (S) this;
}
}
Expand Down
Loading