|
23 | 23 |
|
24 | 24 | import javax.annotation.Nullable;
|
25 | 25 |
|
| 26 | +import io.netty.bootstrap.Bootstrap; |
26 | 27 | import io.netty.channel.Channel;
|
27 | 28 | import io.netty.channel.ChannelDuplexHandler;
|
28 | 29 | import io.netty.channel.ChannelInboundHandlerAdapter;
|
|
35 | 36 | import org.slf4j.LoggerFactory;
|
36 | 37 |
|
37 | 38 | import org.apache.celeborn.common.metrics.source.AbstractSource;
|
| 39 | +import org.apache.celeborn.common.network.client.ReconnectHandler; |
38 | 40 | import org.apache.celeborn.common.network.client.TransportClient;
|
39 | 41 | import org.apache.celeborn.common.network.client.TransportClientBootstrap;
|
40 | 42 | import org.apache.celeborn.common.network.client.TransportClientFactory;
|
@@ -73,6 +75,7 @@ public class TransportContext implements Closeable {
|
73 | 75 | @Nullable private final SSLFactory sslFactory;
|
74 | 76 | private final boolean enableHeartbeat;
|
75 | 77 | private final AbstractSource source;
|
| 78 | + private ReconnectHandler reconnectHandler; |
76 | 79 |
|
77 | 80 | private static final MessageEncoder ENCODER = MessageEncoder.INSTANCE;
|
78 | 81 | private static final SslMessageEncoder SSL_ENCODER = SslMessageEncoder.INSTANCE;
|
@@ -173,20 +176,22 @@ public boolean sslEncryptionEnabled() {
|
173 | 176 | }
|
174 | 177 |
|
175 | 178 | public TransportChannelHandler initializePipeline(
|
176 |
| - SocketChannel channel, ChannelInboundHandlerAdapter decoder, boolean isClient) { |
177 |
| - return initializePipeline(channel, decoder, msgHandler, isClient); |
| 179 | + SocketChannel channel, ChannelInboundHandlerAdapter decoder, Bootstrap bootstrap) { |
| 180 | + return initializePipeline(channel, decoder, msgHandler, true, bootstrap); |
178 | 181 | }
|
179 | 182 |
|
180 | 183 | public TransportChannelHandler initializePipeline(
|
181 |
| - SocketChannel channel, BaseMessageHandler resolvedMsgHandler, boolean isClient) { |
182 |
| - return initializePipeline(channel, new TransportFrameDecoder(), resolvedMsgHandler, isClient); |
| 184 | + SocketChannel channel, BaseMessageHandler resolvedMsgHandler) { |
| 185 | + return initializePipeline( |
| 186 | + channel, new TransportFrameDecoder(), resolvedMsgHandler, false, null); |
183 | 187 | }
|
184 | 188 |
|
185 | 189 | public TransportChannelHandler initializePipeline(
|
186 | 190 | SocketChannel channel,
|
187 | 191 | ChannelInboundHandlerAdapter decoder,
|
188 | 192 | BaseMessageHandler resolvedMsgHandler,
|
189 |
| - boolean isClient) { |
| 193 | + boolean isClient, |
| 194 | + Bootstrap bootstrap) { |
190 | 195 | try {
|
191 | 196 | ChannelPipeline pipeline = channel.pipeline();
|
192 | 197 | if (nettyLogger.getLoggingHandler() != null) {
|
@@ -221,8 +226,12 @@ public TransportChannelHandler initializePipeline(
|
221 | 226 | "idleStateHandler",
|
222 | 227 | enableHeartbeat
|
223 | 228 | ? new IdleStateHandler(conf.connectionTimeoutMs() / 1000, 0, 0)
|
224 |
| - : new IdleStateHandler(0, 0, conf.connectionTimeoutMs() / 1000)) |
225 |
| - .addLast("handler", channelHandler); |
| 229 | + : new IdleStateHandler(0, 0, conf.connectionTimeoutMs() / 1000)); |
| 230 | + if (isClient) { |
| 231 | + reconnectHandler = new ReconnectHandler(conf, bootstrap); |
| 232 | + pipeline.addLast(reconnectHandler); |
| 233 | + } |
| 234 | + pipeline.addLast("handler", channelHandler); |
226 | 235 | return channelHandler;
|
227 | 236 | } catch (RuntimeException e) {
|
228 | 237 | logger.error("Error while initializing Netty pipeline", e);
|
@@ -264,5 +273,8 @@ public void close() {
|
264 | 273 | if (sslFactory != null) {
|
265 | 274 | sslFactory.destroy();
|
266 | 275 | }
|
| 276 | + if (reconnectHandler != null) { |
| 277 | + reconnectHandler.stopReconnect(); |
| 278 | + } |
267 | 279 | }
|
268 | 280 | }
|
0 commit comments