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

rmaucher pushed a commit to branch 11.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit f3d134171ffd729fd40a1e97bc2aeff3b2915f71
Author: opencode <[email protected]>
AuthorDate: Sun Oct 11 10:52:07 2026 +0200

    Report the configured mcast so timeout and TTL through JMX
    
    The getSoTimeout() and getTtl() attributes of the membership service
    MBean returned private fields that only the matching setters wrote,
    while start() configures the multicast service from the mcastSoTimeout
    and mcastTTL properties directly. A deployment that configures the
    multicast membership through its properties, rather than through the
    setters, therefore ran with a socket timeout and TTL that JMX reported
    as the field default of zero.
    
    The two attributes now read the properties, as every other
    property-backed attribute of the service does, with the previous zero
    default kept for an unset property, which also makes them report what
    a subsequent start would apply rather than a setter value that a
    replaced set of properties dropped on the floor. The fields behind the
    getters are no longer used and were removed.
    
    Add tests for the property based configuration, the setters, the
    default of an unset property, and the precedence of a replaced set of
    properties over an earlier setter value.
---
 .../catalina/tribes/membership/McastService.java   | 16 ++++---
 .../tribes/membership/TestMcastService.java        | 50 ++++++++++++++++++++++
 2 files changed, 60 insertions(+), 6 deletions(-)

diff --git a/java/org/apache/catalina/tribes/membership/McastService.java 
b/java/org/apache/catalina/tribes/membership/McastService.java
index cda9f12608..0672086983 100644
--- a/java/org/apache/catalina/tribes/membership/McastService.java
+++ b/java/org/apache/catalina/tribes/membership/McastService.java
@@ -64,8 +64,6 @@ public class McastService extends MembershipServiceBase 
implements MessageListen
      * The local member
      */
     protected MemberImpl localMember;
-    private int mcastSoTimeout;
-    private int mcastTTL;
 
     /**
      * The payload for multicast messages.
@@ -482,7 +480,11 @@ public class McastService extends MembershipServiceBase 
implements MessageListen
 
     @Override
     public int getSoTimeout() {
-        return mcastSoTimeout;
+        String p = properties.getProperty("mcastSoTimeout");
+        if (p != null) {
+            return Integer.parseInt(p);
+        }
+        return 0;
     }
 
     /**
@@ -490,13 +492,16 @@ public class McastService extends MembershipServiceBase 
implements MessageListen
      * @param mcastSoTimeout the timeout in milliseconds
      */
     public void setSoTimeout(int mcastSoTimeout) {
-        this.mcastSoTimeout = mcastSoTimeout;
         properties.setProperty("mcastSoTimeout", 
String.valueOf(mcastSoTimeout));
     }
 
     @Override
     public int getTtl() {
-        return mcastTTL;
+        String p = properties.getProperty("mcastTTL");
+        if (p != null) {
+            return Integer.parseInt(p);
+        }
+        return 0;
     }
 
     /**
@@ -517,7 +522,6 @@ public class McastService extends MembershipServiceBase 
implements MessageListen
      * @param mcastTTL the TTL value
      */
     public void setTtl(int mcastTTL) {
-        this.mcastTTL = mcastTTL;
         properties.setProperty("mcastTTL", String.valueOf(mcastTTL));
     }
 
diff --git a/test/org/apache/catalina/tribes/membership/TestMcastService.java 
b/test/org/apache/catalina/tribes/membership/TestMcastService.java
index ad5b981db5..431e6fae9a 100644
--- a/test/org/apache/catalina/tribes/membership/TestMcastService.java
+++ b/test/org/apache/catalina/tribes/membership/TestMcastService.java
@@ -69,4 +69,54 @@ public class TestMcastService {
 
         Assert.assertNull("the membership implementation must be released on 
stop", service.impl);
     }
+
+    /*
+     * The soTimeout and ttl reported through MBean must reflect the 
configuration, whether it is
+     * supplied through the properties file or through the setters. Previously 
the getters read
+     * private fields that only the setters wrote, so a property-based 
configuration that the socket
+     * did apply was reported as the default 0.
+     */
+    @Test
+    public void testSoTimeoutAndTtlReflectProperties() throws Exception {
+        Properties properties = new Properties();
+        properties.setProperty("mcastAddress", "228.0.0.4");
+        properties.setProperty("mcastPort", "45564");
+        properties.setProperty("memberDropTime", "3000");
+        properties.setProperty("mcastFrequency", "500");
+        properties.setProperty("tcpListenHost", "127.0.0.1");
+        properties.setProperty("tcpListenPort", "4000");
+        properties.setProperty("mcastSoTimeout", "1234");
+        properties.setProperty("mcastTTL", "5");
+
+        McastService service = new McastService();
+        service.setProperties(properties);
+
+        Assert.assertEquals(1234, service.getSoTimeout());
+        Assert.assertEquals(5, service.getTtl());
+
+        // The setters keep overriding, with the setter value taking precedence
+        service.setSoTimeout(7);
+        service.setTtl(9);
+        Assert.assertEquals(7, service.getSoTimeout());
+        Assert.assertEquals(9, service.getTtl());
+
+        // A later setProperties replaces the whole configuration, and with it 
the setter values,
+        // as that is what a subsequent start() would apply
+        properties.remove("mcastSoTimeout");
+        properties.remove("mcastTTL");
+        service.setProperties(properties);
+        Assert.assertEquals(0, service.getSoTimeout());
+        Assert.assertEquals(0, service.getTtl());
+    }
+
+    /*
+     * When neither the properties nor a setter provides a value, the reported 
soTimeout and ttl
+     * default to 0, as they did before.
+     */
+    @Test
+    public void testSoTimeoutAndTtlDefaultToZero() throws Exception {
+        McastService service = new McastService();
+        Assert.assertEquals(0, service.getSoTimeout());
+        Assert.assertEquals(0, service.getTtl());
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to