slfan1989 commented on code in PR #1349:
URL: https://github.com/apache/ratis/pull/1349#discussion_r2820930457


##########
ratis-netty/src/main/java/org/apache/ratis/netty/client/NettyClientStreamRpc.java:
##########
@@ -136,20 +141,38 @@ void shutdownGracefully() {
   }
 
   static class Connection {
-    static final TimeDuration RECONNECT = TimeDuration.valueOf(100, 
TimeUnit.MILLISECONDS);
-
     private final InetSocketAddress address;
     private final WorkerGroupGetter workerGroup;
     private final Supplier<ChannelInitializer<SocketChannel>> 
channelInitializerSupplier;
+    private final long minReconnectMillis;
+    private final long maxReconnectMillis;
+    private final int maxReconnectAttempts;
+    private final RetryPolicy reconnectPolicy;
 
     /** The {@link ChannelFuture} is null when this connection is closed. */
     private final AtomicReference<MemoizedSupplier<ChannelFuture>> ref;
+    private final AtomicBoolean reconnectScheduled = new AtomicBoolean(false);
+    private final AtomicInteger reconnectAttempts = new AtomicInteger();
 
     Connection(InetSocketAddress address, WorkerGroupGetter workerGroup,
-        Supplier<ChannelInitializer<SocketChannel>> 
channelInitializerSupplier) {
+        Supplier<ChannelInitializer<SocketChannel>> channelInitializerSupplier,
+        TimeDuration reconnectDelay, TimeDuration reconnectMaxDelay, int 
reconnectMaxAttempts) {
       this.address = address;
       this.workerGroup = workerGroup;
       this.channelInitializerSupplier = channelInitializerSupplier;
+      this.minReconnectMillis = 
reconnectDelay.getUnit().toMillis(reconnectDelay.getDuration());
+      this.maxReconnectMillis = 
reconnectMaxDelay.getUnit().toMillis(reconnectMaxDelay.getDuration());
+      this.maxReconnectAttempts = reconnectMaxAttempts;
+      Preconditions.assertTrue(minReconnectMillis > 0, () -> 
"minReconnectMillis = " + minReconnectMillis + " <= 0");
+      Preconditions.assertTrue(maxReconnectMillis >= minReconnectMillis,
+          () -> "maxReconnectMillis = " + maxReconnectMillis + " < 
minReconnectMillis = " + minReconnectMillis);
+      Preconditions.assertTrue(maxReconnectAttempts >= 0,
+          () -> "maxReconnectAttempts = " + maxReconnectAttempts + " < 0");
+      this.reconnectPolicy = ExponentialBackoffRetry.newBuilder()
+          .setBaseSleepTime(reconnectDelay)
+          .setMaxSleepTime(reconnectMaxDelay)
+          .setMaxAttempts(maxReconnectAttempts)
+          .build();

Review Comment:
   Thanks for the suggestion—agreed. We’ll pass reconnectPolicy to keep the 
design extensible for future RetryPolicy support.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to