This is an automated email from the ASF dual-hosted git repository.

szetszwo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ratis.git


The following commit(s) were added to refs/heads/master by this push:
     new bc37ab50 RATIS-1633. Improve the grpc config output log information. 
(#691)
bc37ab50 is described below

commit bc37ab504c2c429f3a858a4e847dee969455f1d5
Author: leo65535 <[email protected]>
AuthorDate: Sun Jul 24 03:29:18 2022 +0800

    RATIS-1633. Improve the grpc config output log information. (#691)
---
 .../main/java/org/apache/ratis/conf/ConfUtils.java    | 18 ++++++++++++++++++
 .../java/org/apache/ratis/grpc/GrpcConfigKeys.java    | 19 ++++++++++++-------
 2 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/ratis-common/src/main/java/org/apache/ratis/conf/ConfUtils.java 
b/ratis-common/src/main/java/org/apache/ratis/conf/ConfUtils.java
index e5b04c67..b21cc642 100644
--- a/ratis-common/src/main/java/org/apache/ratis/conf/ConfUtils.java
+++ b/ratis-common/src/main/java/org/apache/ratis/conf/ConfUtils.java
@@ -153,6 +153,14 @@ public interface ConfUtils {
     return get(integerGetter, key, defaultValue, logger, assertions);
   }
 
+  @SafeVarargs
+  static int getInt(
+      BiFunction<String, Integer, Integer> integerGetter,
+      String key, int defaultValue, int fallbackValue,
+      Consumer<String> logger, BiConsumer<String, Integer>... assertions) {
+    return get(integerGetter, key, defaultValue, fallbackValue, logger, 
assertions);
+  }
+
   @SafeVarargs
   static long getLong(
       BiFunction<String, Long, Long> longGetter,
@@ -215,6 +223,16 @@ public interface ConfUtils {
     return value;
   }
 
+  @SafeVarargs
+  static <T> T get(BiFunction<String, T, T> getter,
+      String key, T defaultValue, T fallbackValue,
+      Consumer<String> logger, BiConsumer<String, T>... assertions) {
+    T value = get(getter, key, defaultValue, null, assertions);
+    value = value != defaultValue ? value : fallbackValue;
+    logGet(key, value, defaultValue, logger);
+    return value;
+  }
+
   static InetSocketAddress getInetSocketAddress(
       BiFunction<String, String, String> stringGetter,
       String key, String defaultValue, Consumer<String> logger) {
diff --git a/ratis-grpc/src/main/java/org/apache/ratis/grpc/GrpcConfigKeys.java 
b/ratis-grpc/src/main/java/org/apache/ratis/grpc/GrpcConfigKeys.java
index c265ab2d..0ba995de 100644
--- a/ratis-grpc/src/main/java/org/apache/ratis/grpc/GrpcConfigKeys.java
+++ b/ratis-grpc/src/main/java/org/apache/ratis/grpc/GrpcConfigKeys.java
@@ -100,9 +100,9 @@ public interface GrpcConfigKeys {
     String PORT_KEY = PREFIX + ".port";
     int PORT_DEFAULT = -1;
     static int port(RaftProperties properties) {
-      final int port = getInt(properties::getInt,
-          PORT_KEY, PORT_DEFAULT, getDefaultLog(), requireMin(-1), 
requireMax(65536));
-      return port != PORT_DEFAULT ? port : Server.port(properties);
+      final int fallbackServerPort = Server.port(properties, null);
+      return getInt(properties::getInt,
+          PORT_KEY, PORT_DEFAULT, fallbackServerPort, getDefaultLog(), 
requireMin(-1), requireMax(65536));
     }
     static void setPort(RaftProperties properties, int port) {
       setInt(properties::setInt, PORT_KEY, port);
@@ -124,9 +124,9 @@ public interface GrpcConfigKeys {
     String PORT_KEY = PREFIX + ".port";
     int PORT_DEFAULT = -1;
     static int port(RaftProperties properties) {
-      final int port = getInt(properties::getInt,
-          PORT_KEY, PORT_DEFAULT, getDefaultLog(), requireMin(-1), 
requireMax(65536));
-      return port != PORT_DEFAULT ? port : Server.port(properties);
+      final int fallbackServerPort = Server.port(properties, null);
+      return getInt(properties::getInt,
+          PORT_KEY, PORT_DEFAULT, fallbackServerPort, getDefaultLog(), 
requireMin(-1), requireMax(65536));
     }
     static void setPort(RaftProperties properties, int port) {
       setInt(properties::setInt, PORT_KEY, port);
@@ -148,9 +148,14 @@ public interface GrpcConfigKeys {
     String PORT_KEY = PREFIX + ".port";
     int PORT_DEFAULT = 0;
     static int port(RaftProperties properties) {
+      return port(properties, getDefaultLog());
+    }
+
+    static int port(RaftProperties properties, Consumer<String> logger) {
       return getInt(properties::getInt,
-          PORT_KEY, PORT_DEFAULT, getDefaultLog(), requireMin(0), 
requireMax(65536));
+          PORT_KEY, PORT_DEFAULT, logger, requireMin(0), requireMax(65536));
     }
+
     static void setPort(RaftProperties properties, int port) {
       setInt(properties::setInt, PORT_KEY, port);
     }

Reply via email to