davsclaus commented on code in PR #27210:
URL: https://github.com/apache/camel/pull/27210#discussion_r4155886066
##########
dsl/camel-cli-connector/src/main/java/org/apache/camel/cli/connector/WebSocketCliConnectorTransport.java:
##########
@@ -661,75 +694,52 @@ private static boolean isLoopback(String host) {
}
/**
- * One WebSocket connection, and what has been sent on it.
+ * One WebSocket connection, and what has been sent on it. The callbacks
come from the client, on any thread.
*/
- private final class Connection implements WebSocket.Listener {
+ private final class Connection implements CliWebSocketClient.Listener {
- private WebSocket ws;
- private final StringBuilder partial = new StringBuilder();
- private final long openedAt = System.currentTimeMillis();
+ // set on the scheduler thread, before the connection is used
+ private CliWebSocketClient.Channel channel;
+ private boolean lost;
+ private long openedAt = System.currentTimeMillis();
private volatile long lastSeen = openedAt;
private boolean helloSent;
private long lastTraceUid;
private long lastReceiveUid;
private final Map<String, String> lastSent = new HashMap<>();
@Override
- public void onOpen(WebSocket webSocket) {
- this.ws = webSocket;
- webSocket.request(1);
- execute(() -> opened(this));
- }
-
- @Override
- public CompletionStage<?> onText(WebSocket webSocket, CharSequence
data, boolean last) {
+ public void onText(String text) {
Review Comment:
A frame can reach `onFrame` before `opened(c, channel)` has run. The JDK
adapter calls `request(1)` in `onOpen`, and `opened` is only queued when the
`connect()` future completes, so a frame from a tool that writes right after
the handshake can be queued first.
`onFrame` then still runs the action, but `send()` drops the reply because
`c != connection`. For a `stop` action, the application stops without telling
the tool. Before this PR `opened` was queued inside `onOpen`, so the gap was
smaller.
If the tool can send before it gets `hello`, maybe drop frames for a
connection that isn't open yet, as `send()` already does:
```java
private void onFrame(Connection c, String text) {
if (c != connection) {
// not open yet, or already gone
return;
}
```
Or keep them until `opened` runs. If the tool always waits for `hello`, then
this is fine as is.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]