Skip to content

Commit a7c2ba5

Browse files
committed
Provide opportunity to create a client WebSocket with a given vertx context to use.
1 parent 032de2b commit a7c2ba5

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed

src/main/java/io/vertx/core/http/impl/ClientWebSocketImpl.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
/**
2828
* Client WebSocket implementation
2929
*/
30-
public class ClientWebSocketImpl implements ClientWebSocket {
30+
public class ClientWebSocketImpl implements ClientWebSocketInternal {
3131

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

4949
@Override
5050
public Future<WebSocket> connect(WebSocketConnectOptions options) {
51-
ContextInternal ctx = client.vertx().getOrCreateContext();
51+
return connect(client.vertx().getOrCreateContext(), options);
52+
}
53+
54+
@Override
55+
public Future<WebSocket> connect(Context context, WebSocketConnectOptions options) {
56+
return connect((ContextInternal) context, options);
57+
}
58+
59+
private Future<WebSocket> connect(ContextInternal ctx, WebSocketConnectOptions options) {
5260
Promise<WebSocket> promise = ctx.promise();
5361
if (!connect.compareAndSet(null, promise)) {
5462
return ctx.failedFuture("Already connecting");
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) 2011-2024 Contributors to the Eclipse Foundation
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7+
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
8+
*
9+
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10+
*/
11+
package io.vertx.core.http.impl;
12+
13+
import io.vertx.core.Context;
14+
import io.vertx.core.Future;
15+
import io.vertx.core.http.ClientWebSocket;
16+
import io.vertx.core.http.WebSocket;
17+
import io.vertx.core.http.WebSocketConnectOptions;
18+
19+
/**
20+
* @author <a href="mailto:[email protected]">Julien Viet</a>
21+
*/
22+
public interface ClientWebSocketInternal extends ClientWebSocket {
23+
24+
Future<WebSocket> connect(Context context, WebSocketConnectOptions options);
25+
26+
}

src/main/java/io/vertx/core/http/impl/HttpClientBase.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,6 @@ public void webSocket(WebSocketConnectOptions connectOptions, Handler<AsyncResul
172172
webSocket(connectOptions, promise);
173173
}
174174

175-
Future<WebSocket> webSocket(ContextInternal ctx, WebSocketConnectOptions connectOptions) {
176-
PromiseInternal<WebSocket> promise = ctx.promise();
177-
webSocket(connectOptions, promise);
178-
return promise.andThen(ar -> {
179-
if (ar.succeeded()) {
180-
ar.result().resume();
181-
}
182-
});
183-
}
184-
185175
private void webSocket(WebSocketConnectOptions connectOptions, PromiseInternal<WebSocket> promise) {
186176
ContextInternal ctx = promise.context();
187177
int port = getPort(connectOptions);

0 commit comments

Comments
 (0)