Skip to content

Commit 6ee24ca

Browse files
committed
Have TcpClientImpl implement TcpClient
1 parent 9a90c99 commit 6ee24ca

File tree

4 files changed

+137
-14
lines changed

4 files changed

+137
-14
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) 2011-20123Contributors 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.internal.net;
12+
13+
import io.vertx.core.Closeable;
14+
import io.vertx.core.Future;
15+
import io.vertx.core.Promise;
16+
import io.vertx.core.internal.ContextInternal;
17+
import io.vertx.core.net.*;
18+
import io.vertx.core.spi.metrics.MetricsProvider;
19+
20+
/**
21+
* Net client internal API.
22+
*/
23+
public interface TcpClientInternal extends TcpClient, MetricsProvider, Closeable {
24+
25+
/**
26+
* Open a socket to the {@code remoteAddress} server.
27+
*
28+
* @param connectOptions the connect options
29+
* @param connectHandler the promise to resolve with the connect result
30+
* @param context the socket context
31+
*/
32+
void connectInternal(ConnectOptions connectOptions,
33+
Promise<TcpSocket> connectHandler,
34+
ContextInternal context);
35+
36+
Future<Void> closeFuture();
37+
38+
}

vertx-core/src/main/java/io/vertx/core/net/impl/tcp/NetClientBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ public NetClientBuilder protocol(String protocol) {
4949
}
5050

5151
public NetClientInternal build() {
52-
return new TcpClientImpl(vertx, config, protocol, sslOptions, registerWriteHandler);
52+
return new NetClientImpl(new TcpClientImpl(vertx, config, protocol, sslOptions, registerWriteHandler));
5353
}
5454
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Copyright (c) 2011-2026 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.net.impl.tcp;
12+
13+
import io.vertx.core.Completable;
14+
import io.vertx.core.Future;
15+
import io.vertx.core.Promise;
16+
import io.vertx.core.internal.ContextInternal;
17+
import io.vertx.core.internal.net.NetClientInternal;
18+
import io.vertx.core.net.*;
19+
import io.vertx.core.spi.metrics.Metrics;
20+
21+
import java.time.Duration;
22+
23+
public class NetClientImpl implements NetClientInternal {
24+
25+
private TcpClientImpl delegate;
26+
27+
public NetClientImpl(TcpClientImpl delegate) {
28+
this.delegate = delegate;
29+
}
30+
31+
@Override
32+
public void connectInternal(ConnectOptions connectOptions, Promise<NetSocket> connectHandler, ContextInternal context) {
33+
delegate.connectInternal(connectOptions, (Promise)connectHandler, context);
34+
}
35+
36+
@Override
37+
public Future<Void> closeFuture() {
38+
return delegate.closeFuture();
39+
}
40+
41+
@Override
42+
public Future<NetSocket> connect(int port, String host) {
43+
return (Future)delegate.connect(port, host);
44+
}
45+
46+
@Override
47+
public Future<NetSocket> connect(int port, String host, String serverName) {
48+
return (Future)delegate.connect(port, host, serverName);
49+
}
50+
51+
@Override
52+
public Future<NetSocket> connect(SocketAddress remoteAddress) {
53+
return (Future)delegate.connect(remoteAddress);
54+
}
55+
56+
@Override
57+
public Future<NetSocket> connect(SocketAddress remoteAddress, String serverName) {
58+
return (Future)delegate.connect(remoteAddress, serverName);
59+
}
60+
61+
@Override
62+
public Future<NetSocket> connect(ConnectOptions connectOptions) {
63+
return (Future)delegate.connect(connectOptions);
64+
}
65+
66+
@Override
67+
public void close(Completable<Void> completion) {
68+
delegate.close(completion);
69+
}
70+
71+
@Override
72+
public Future<Void> shutdown(Duration timeout) {
73+
return delegate.shutdown(timeout);
74+
}
75+
76+
@Override
77+
public Future<Boolean> updateSSLOptions(ClientSSLOptions options, boolean force) {
78+
return delegate.updateSSLOptions(options, force);
79+
}
80+
81+
@Override
82+
public Metrics getMetrics() {
83+
return delegate.getMetrics();
84+
}
85+
}

vertx-core/src/main/java/io/vertx/core/net/impl/tcp/TcpClientImpl.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import io.vertx.core.internal.logging.Logger;
2828
import io.vertx.core.internal.logging.LoggerFactory;
2929
import io.vertx.core.internal.net.NetClientInternal;
30+
import io.vertx.core.internal.net.TcpClientInternal;
3031
import io.vertx.core.internal.tls.SslContextManager;
3132
import io.vertx.core.internal.tls.SslContextProvider;
3233
import io.vertx.core.net.*;
@@ -48,7 +49,7 @@
4849
* @author <a href="http://tfox.org">Tim Fox</a>
4950
* @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
5051
*/
51-
class TcpClientImpl implements NetClientInternal {
52+
class TcpClientImpl implements TcpClientInternal {
5253

5354
private static final Logger log = LoggerFactory.getLogger(TcpClientImpl.class);
5455
protected final Duration idleTimeout;
@@ -108,22 +109,22 @@ protected void initChannel(ChannelPipeline pipeline, boolean ssl) {
108109
}
109110

110111
@Override
111-
public Future<NetSocket> connect(int port, String host) {
112+
public Future<TcpSocket> connect(int port, String host) {
112113
return connect(port, host, (String) null);
113114
}
114115

115116
@Override
116-
public Future<NetSocket> connect(int port, String host, String serverName) {
117+
public Future<TcpSocket> connect(int port, String host, String serverName) {
117118
return connect(SocketAddress.inetSocketAddress(port, host), serverName);
118119
}
119120

120121
@Override
121-
public Future<NetSocket> connect(SocketAddress remoteAddress) {
122+
public Future<TcpSocket> connect(SocketAddress remoteAddress) {
122123
return connect(remoteAddress, null);
123124
}
124125

125126
@Override
126-
public Future<NetSocket> connect(SocketAddress remoteAddress, String serverName) {
127+
public Future<TcpSocket> connect(SocketAddress remoteAddress, String serverName) {
127128
ConnectOptions connectOptions = new ConnectOptions();
128129
connectOptions.setRemoteAddress(remoteAddress);
129130
String peerHost = remoteAddress.host();
@@ -141,15 +142,15 @@ public Future<NetSocket> connect(SocketAddress remoteAddress, String serverName)
141142
}
142143

143144
@Override
144-
public Future<NetSocket> connect(ConnectOptions connectOptions) {
145+
public Future<TcpSocket> connect(ConnectOptions connectOptions) {
145146
ContextInternal context = vertx.getOrCreateContext();
146-
Promise<NetSocket> promise = context.promise();
147+
Promise<TcpSocket> promise = context.promise();
147148
connectInternal(connectOptions, registerWriteHandler, promise, context, config.getReconnectAttempts());
148149
return promise.future();
149150
}
150151

151152
@Override
152-
public void connectInternal(ConnectOptions connectOptions, Promise<NetSocket> connectHandler, ContextInternal context) {
153+
public void connectInternal(ConnectOptions connectOptions, Promise<TcpSocket> connectHandler, ContextInternal context) {
153154
ClientSSLOptions sslOptions = connectOptions.getSslOptions();
154155
if (sslOptions == null) {
155156
connectOptions.setSslOptions(this.sslOptions);
@@ -172,7 +173,6 @@ private void handleClose(Completable<Void> completion) {
172173
}
173174
}
174175

175-
@Override
176176
public void close(Completable<Void> completion) {
177177
channelGroup.shutdown(0, TimeUnit.SECONDS).onComplete(completion);
178178
}
@@ -208,7 +208,7 @@ public Future<Boolean> updateSSLOptions(ClientSSLOptions options, boolean force)
208208

209209
private void connectInternal(ConnectOptions connectOptions,
210210
boolean registerWriteHandlers,
211-
Promise<NetSocket> connectHandler,
211+
Promise<TcpSocket> connectHandler,
212212
ContextInternal context,
213213
int remainingAttempts) {
214214
if (channelGroup.isStarted()) {
@@ -242,7 +242,7 @@ private void connectInternal2(ConnectOptions connectOptions,
242242
ClientSSLOptions sslOptions,
243243
SslContextProvider sslContextProvider,
244244
boolean registerWriteHandlers,
245-
Promise<NetSocket> connectHandler,
245+
Promise<TcpSocket> connectHandler,
246246
ContextInternal context,
247247
int remainingAttempts) {
248248
EventLoop eventLoop = context.nettyEventLoop();
@@ -375,7 +375,7 @@ private static SocketAddress peerAddress(SocketAddress remoteAddress, ConnectOpt
375375
private void connected(ContextInternal context,
376376
ClientSSLOptions sslOptions,
377377
Channel ch,
378-
Promise<NetSocket> connectHandler,
378+
Promise<TcpSocket> connectHandler,
379379
SocketAddress remoteAddress,
380380
boolean ssl,
381381
boolean registerWriteHandlers) {
@@ -400,7 +400,7 @@ private void connected(ContextInternal context,
400400
ch.pipeline().addLast("handler", handler);
401401
}
402402

403-
private void failed(ContextInternal context, Channel ch, Throwable th, Promise<NetSocket> connectHandler) {
403+
private void failed(ContextInternal context, Channel ch, Throwable th, Promise<TcpSocket> connectHandler) {
404404
if (ch != null) {
405405
ch.close();
406406
}

0 commit comments

Comments
 (0)