You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by re...@apache.org on 2022/12/21 17:23:53 UTC

[jackrabbit-oak] branch 1.22 updated: OAK-9022: use SystemPropertySupplier in ClusterNodeInfo

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

reschke pushed a commit to branch 1.22
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git


The following commit(s) were added to refs/heads/1.22 by this push:
     new 2ef6325eb5 OAK-9022: use SystemPropertySupplier in ClusterNodeInfo
2ef6325eb5 is described below

commit 2ef6325eb5a0d37a9a2d5ab203c81bab6ecd173c
Author: Julian Reschke <re...@apache.org>
AuthorDate: Mon Apr 20 11:13:02 2020 +0000

    OAK-9022: use SystemPropertySupplier in ClusterNodeInfo
    
    git-svn-id: https://svn.apache.org/repos/asf/jackrabbit/oak/trunk@1876753 13f79535-47bb-0310-9956-ffa450edef68
---
 .../oak/plugins/document/ClusterNodeInfo.java      | 33 +++++++++-------------
 1 file changed, 14 insertions(+), 19 deletions(-)

diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java
index 7011db5d63..9289cce6a3 100644
--- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java
+++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java
@@ -43,10 +43,12 @@ import java.util.concurrent.TimeUnit;
 import com.google.common.base.Stopwatch;
 
 import org.apache.jackrabbit.oak.commons.StringUtils;
+import org.apache.jackrabbit.oak.plugins.document.util.SystemPropertySupplier;
 import org.apache.jackrabbit.oak.stats.Clock;
 import org.jetbrains.annotations.NotNull;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.slf4j.event.Level;
 
 /**
  * Information about a cluster node.
@@ -193,17 +195,11 @@ public class ClusterNodeInfo {
      */
     private static Clock clock = Clock.SIMPLE;
 
-    public static final int DEFAULT_LEASE_DURATION_MILLIS;
-
-    static {
-        String leaseDurationProp = "oak.documentMK.leaseDurationSeconds";
-        Integer leaseProp = Integer.getInteger(leaseDurationProp);
-        if (leaseProp != null) {
-            LOG.info("Lease duration set to: " + leaseProp + "s (using system property " + leaseDurationProp + ")");
-        }
-        /** OAK-3398 : default lease duration 120sec **/
-        DEFAULT_LEASE_DURATION_MILLIS = 1000 * (leaseProp != null ? leaseProp : 120);
-    }
+    /** OAK-3398 : default lease duration 120sec **/
+    private static final int DEFAULT_LEASE_DURATION_SEC = SystemPropertySupplier.create("oak.documentMK.leaseDurationSeconds", 120)
+            .loggingTo(LOG).validateWith(value -> value >= 0)
+            .formatSetMessage((name, value) -> String.format("Lease duration set to: %ss (using system property %s)", name, value)).get();
+    public static final int DEFAULT_LEASE_DURATION_MILLIS = 1000 * DEFAULT_LEASE_DURATION_SEC;
 
     /** OAK-3398 : default update interval 10sec **/
     public static final int DEFAULT_LEASE_UPDATE_INTERVAL_MILLIS = 1000 * 10;
@@ -215,8 +211,8 @@ public class ClusterNodeInfo {
      */
     public static final int DEFAULT_LEASE_FAILURE_MARGIN_MILLIS = 1000 * 20;
 
-    public static final boolean DEFAULT_LEASE_CHECK_DISABLED =
-            Boolean.valueOf(System.getProperty("oak.documentMK.disableLeaseCheck", "false"));
+    public static final boolean DEFAULT_LEASE_CHECK_DISABLED = SystemPropertySupplier
+            .create("oak.documentMK.disableLeaseCheck", Boolean.FALSE).loggingTo(LOG).get();
 
     /**
      * Default lease check mode is strict, unless disabled via system property.
@@ -1192,12 +1188,11 @@ public class ClusterNodeInfo {
      * be simulated.
      */
     private static String getHWAFromSystemProperty() {
-        String pname = ClusterNodeInfo.class.getName() + ".HWADDRESS";
-        String hwa = System.getProperty(pname, "");
-        if (!"".equals(hwa)) {
-            LOG.debug("obtaining hardware address from system variable " + pname + ": " + hwa);
-        }
-        return hwa;
+        return SystemPropertySupplier.create(ClusterNodeInfo.class.getName() + ".HWADDRESS", "").loggingTo(LOG)
+                .logSuccessAs(Level.DEBUG)
+                .formatSetMessage(
+                        (name, value) -> String.format("obtaining hardware address from system variable %s: %s", name, value))
+                .get();
     }
 
     /**