diff --git a/src/main/java/io/vertx/core/http/impl/ClientWebSocketImpl.java b/src/main/java/io/vertx/core/http/impl/ClientWebSocketImpl.java index fa1354f50e7..ee3aec248bf 100644 --- a/src/main/java/io/vertx/core/http/impl/ClientWebSocketImpl.java +++ b/src/main/java/io/vertx/core/http/impl/ClientWebSocketImpl.java @@ -27,7 +27,7 @@ /** * Client WebSocket implementation */ -public class ClientWebSocketImpl implements ClientWebSocket { +public class ClientWebSocketImpl implements ClientWebSocketInternal { private HttpClientBase client; private final AtomicReference> connect = new AtomicReference<>(); @@ -48,7 +48,15 @@ public class ClientWebSocketImpl implements ClientWebSocket { @Override public Future connect(WebSocketConnectOptions options) { - ContextInternal ctx = client.vertx().getOrCreateContext(); + return connect(client.vertx().getOrCreateContext(), options); + } + + @Override + public Future connect(Context context, WebSocketConnectOptions options) { + return connect((ContextInternal) context, options); + } + + private Future connect(ContextInternal ctx, WebSocketConnectOptions options) { Promise promise = ctx.promise(); if (!connect.compareAndSet(null, promise)) { return ctx.failedFuture("Already connecting"); diff --git a/src/main/java/io/vertx/core/http/impl/ClientWebSocketInternal.java b/src/main/java/io/vertx/core/http/impl/ClientWebSocketInternal.java new file mode 100644 index 00000000000..9c5f8964326 --- /dev/null +++ b/src/main/java/io/vertx/core/http/impl/ClientWebSocketInternal.java @@ -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 Julien Viet + */ +public interface ClientWebSocketInternal extends ClientWebSocket { + + Future connect(Context context, WebSocketConnectOptions options); + +} diff --git a/src/main/java/io/vertx/core/http/impl/HttpClientBase.java b/src/main/java/io/vertx/core/http/impl/HttpClientBase.java index 552f783e0be..66add748d9a 100644 --- a/src/main/java/io/vertx/core/http/impl/HttpClientBase.java +++ b/src/main/java/io/vertx/core/http/impl/HttpClientBase.java @@ -172,16 +172,6 @@ public void webSocket(WebSocketConnectOptions connectOptions, Handler webSocket(ContextInternal ctx, WebSocketConnectOptions connectOptions) { - PromiseInternal promise = ctx.promise(); - webSocket(connectOptions, promise); - return promise.andThen(ar -> { - if (ar.succeeded()) { - ar.result().resume(); - } - }); - } - private void webSocket(WebSocketConnectOptions connectOptions, PromiseInternal promise) { ContextInternal ctx = promise.context(); int port = getPort(connectOptions);