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

Provide opportunity to create a client WebSocket with a given vertx context to use #5368

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
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
12 changes: 10 additions & 2 deletions src/main/java/io/vertx/core/http/impl/ClientWebSocketImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/**
* Client WebSocket implementation
*/
public class ClientWebSocketImpl implements ClientWebSocket {
public class ClientWebSocketImpl implements ClientWebSocketInternal {

private HttpClientBase client;
private final AtomicReference<Promise<WebSocket>> connect = new AtomicReference<>();
Expand All @@ -48,7 +48,15 @@ public class ClientWebSocketImpl implements ClientWebSocket {

@Override
public Future<WebSocket> connect(WebSocketConnectOptions options) {
ContextInternal ctx = client.vertx().getOrCreateContext();
return connect(client.vertx().getOrCreateContext(), options);
}

@Override
public Future<WebSocket> connect(Context context, WebSocketConnectOptions options) {
return connect((ContextInternal) context, options);
}

private Future<WebSocket> connect(ContextInternal ctx, WebSocketConnectOptions options) {
Promise<WebSocket> promise = ctx.promise();
if (!connect.compareAndSet(null, promise)) {
return ctx.failedFuture("Already connecting");
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/io/vertx/core/http/impl/ClientWebSocketInternal.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2011-2024 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*/
package io.vertx.core.http.impl;

import io.vertx.core.Context;
import io.vertx.core.Future;
import io.vertx.core.http.ClientWebSocket;
import io.vertx.core.http.WebSocket;
import io.vertx.core.http.WebSocketConnectOptions;

/**
* @author <a href="mailto:[email protected]">Julien Viet</a>
*/
public interface ClientWebSocketInternal extends ClientWebSocket {

Future<WebSocket> connect(Context context, WebSocketConnectOptions options);

}
10 changes: 0 additions & 10 deletions src/main/java/io/vertx/core/http/impl/HttpClientBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,6 @@ public void webSocket(WebSocketConnectOptions connectOptions, Handler<AsyncResul
webSocket(connectOptions, promise);
}

Future<WebSocket> webSocket(ContextInternal ctx, WebSocketConnectOptions connectOptions) {
PromiseInternal<WebSocket> promise = ctx.promise();
webSocket(connectOptions, promise);
return promise.andThen(ar -> {
if (ar.succeeded()) {
ar.result().resume();
}
});
}

private void webSocket(WebSocketConnectOptions connectOptions, PromiseInternal<WebSocket> promise) {
ContextInternal ctx = promise.context();
int port = getPort(connectOptions);
Expand Down
Loading