Skip to content

refactor: replace the WebSocketClient builder with setters - #1566

Merged
jlouvel merged 2 commits into
3.0from
refactor/websocket-client-setters
Nov 1, 2026
Merged

jlouvel merged 2 commits into
3.0from
refactor/websocket-client-setters

Conversation

@jlouvel

@jlouvel jlouvel commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

WebSocketClient in the experimental org.restlet.ext.websocket extension was configured through a fluent Builder. This PR switches it to the Restlet API conventions used by the RPC extensions (MCP, gRPC, Smithy): a constructor, getter and void setter pairs, and a start() / stop() lifecycle.

WebSocketClient client = new WebSocketClient();
client.setConnectTimeout(Duration.ofSeconds(5));
client.setMaxMessageSize(1 << 20);
try (client; WebSocketSession session = client.connect("ws://host/")) {
    ...
}

Changes

  • Removed WebSocketClient.Builder, builder() and create(). Each setting is now a getter/setter pair: SslContext, ConnectTimeout, IdleTimeout, MaxMessageSize, MaxFrameSize, Compression and HostnameVerification.
  • Added start(), stop() and isStarted(). start() creates the I/O threads and stop() releases them. close() calls stop(), and a stopped client can be started again.
  • connect() starts a stopped client, like Restlet.handle().
  • Changing a setting while the client is started throws IllegalStateException.
  • getMaxFrameSize() returns the maximum message size until a frame size is set, the same default as before.

The extension has not been released yet, so the builder is removed rather than deprecated.

Testing

  • Updated the existing tests to the new API. Renamed builderValidatesSettings to clientValidatesSettings and added settingsAreFixedWhileStarted.
  • mvn -pl org.restlet.ext.websocket verify passes locally: 28 tests, no failures.

Not in this PR

The client still creates its own Netty event loop instead of borrowing one from the application's connector. That is a separate, larger change.

🤖 Generated with Claude Code

Follow the Restlet API conventions used by the RPC extensions:
constructors, getter and void setter pairs, and a start/stop lifecycle
instead of a fluent builder.

- Remove WebSocketClient.Builder, builder() and create(). Settings are
  now configured with setters on a new WebSocketClient().
- Add start(), stop() and isStarted(). close() stops the client, which
  can be started again. connect() starts a stopped client, like
  Restlet.handle().
- Reject setting changes while the client is started.

The extension is unreleased, so the builder is removed rather than
deprecated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Jerome Louvel <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The public API migration lacks a breaking-change entry, and the same-instance stop/reconfigure/reconnect lifecycle lacks integration-test coverage.

2 open issues
What changed in this PR

This PR replaces the experimental WebSocket client’s builder API with constructor-based configuration and setters, aligning it with the Restlet RPC extensions.

Changes:

  • Adds getters and setters, with configuration changes blocked while the client is started.
  • Introduces a restartable lifecycle and automatic startup on connection.
  • Migrates existing tests and adds configuration validation and lifecycle-state checks.
File Description
org.restlet.ext.websocket/​src/​test/​java/​org/​restlet/​ext/​websocket/​WebSocketTestCase.java Updates shared client setup to use setters.
org.restlet.ext.websocket/​src/​test/​java/​org/​restlet/​ext/​websocket/​WebSocketSessionTestCase.java Migrates client usage and adds settings and lifecycle assertions.
org.restlet.ext.websocket/​src/​test/​java/​org/​restlet/​ext/​websocket/​WebSocketCompressionTestCase.java Migrates compression and frame-limit tests to setters.
org.restlet.ext.websocket/​src/​main/​java/​org/​restlet/​ext/​websocket/​WebSocketClient.java Replaces the builder with configurable, restartable client lifecycle methods.

Review effort: Balanced

Also describe the setter-based configuration and restartable lifecycle
of WebSocketClient in the changes log.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Jerome Louvel <[email protected]>
@sonarqubecloud

Copy link
Copy Markdown

@jlouvel
jlouvel merged commit dc2a011 into 3.0 Nov 1, 2026
3 checks passed
@jlouvel
jlouvel deleted the refactor/websocket-client-setters branch November 1, 2026 02:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants