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

tv pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jcs.git

commit 82607fe5ae451ad038628af60f9dc937f727e81d
Author: Thomas Vandahl <t...@apache.org>
AuthorDate: Mon Mar 29 16:12:07 2021 +0200

    Allow udpTTL to propagate from configuration to target call
---
 .../socket/tcp/TCPLateralCacheAttributes.java      | 25 ++++++++++++++++++++++
 .../tcp/behavior/ITCPLateralCacheAttributes.java   | 14 ++++++++++++
 .../jcs3/utils/discovery/UDPDiscoveryManager.java  | 24 ++++++++++++---------
 3 files changed, 53 insertions(+), 10 deletions(-)

diff --git 
a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/TCPLateralCacheAttributes.java
 
b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/TCPLateralCacheAttributes.java
index be1122c..b8fcacf 100644
--- 
a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/TCPLateralCacheAttributes.java
+++ 
b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/TCPLateralCacheAttributes.java
@@ -81,6 +81,9 @@ public class TCPLateralCacheAttributes
     /** discovery switch */
     private boolean udpDiscoveryEnabled = DEFAULT_UDP_DISCOVERY_ENABLED;
 
+    /** udp datagram TTL */
+    private int udpTTL = 0;
+
     /** can we put */
     private boolean allowPut = DEFAULT_ALLOW_GET;
 
@@ -256,6 +259,28 @@ public class TCPLateralCacheAttributes
     }
 
     /**
+     * The time-to-live for the UDP multicast packets
+     * <p>
+     * @return Returns the udpTTL.
+     */
+    @Override
+    public int getUdpTTL()
+    {
+        return udpTTL;
+    }
+
+    /**
+     * Sets the time-to-live for the UDP multicast packet
+     * <p>
+     * @param udpTTL The udpTTL to set.
+     */
+    @Override
+    public void setUdpTTL( final int udpTTL )
+    {
+        this.udpTTL = udpTTL;
+    }
+
+    /**
      * Is the lateral allowed to try and get from other laterals.
      * <p>
      * This replaces the old putOnlyMode
diff --git 
a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/behavior/ITCPLateralCacheAttributes.java
 
b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/behavior/ITCPLateralCacheAttributes.java
index ce4569f..871e93c 100644
--- 
a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/behavior/ITCPLateralCacheAttributes.java
+++ 
b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/behavior/ITCPLateralCacheAttributes.java
@@ -140,6 +140,20 @@ public interface ITCPLateralCacheAttributes
     void setUdpDiscoveryAddr( String udpDiscoveryAddr );
 
     /**
+     * The time-to-live for the UDP multicast packets
+     * <p>
+     * @return Returns the udpTTL.
+     */
+    int getUdpTTL();
+
+    /**
+     * Sets the time-to-live for the UDP multicast packet
+     * <p>
+     * @param udpTTL The udpTTL to set.
+     */
+    void setUdpTTL( final int udpTTL );
+
+    /**
      * Is the lateral allowed to try and get from other laterals.
      * <p>
      * This replaces the old putOnlyMode
diff --git 
a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/discovery/UDPDiscoveryManager.java
 
b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/discovery/UDPDiscoveryManager.java
index f07f4de..21fa5b8 100644
--- 
a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/discovery/UDPDiscoveryManager.java
+++ 
b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/discovery/UDPDiscoveryManager.java
@@ -66,39 +66,42 @@ public class UDPDiscoveryManager
     /**
      * Creates a service for the address and port if one doesn't exist already.
      * <p>
-     * We need to key this using the listener port too. TODO think of making 
one discovery service
-     * work for multiple types of clients.
+     * We need to key this using the listener port too.
+     * TODO think of making one discovery service work for multiple types of 
clients.
      * <p>
      * @param discoveryAddress
      * @param discoveryPort
      * @param servicePort
      * @param cacheMgr
      * @return UDPDiscoveryService
-     * @deprecated Specify serializer implementation explicitly
+     * @deprecated Specify serializer implementation explicitly, allow to 
specify udpTTL
      */
     @Deprecated
     public UDPDiscoveryService getService( final String discoveryAddress, 
final int discoveryPort, final int servicePort,
                                                         final 
ICompositeCacheManager cacheMgr )
     {
-        return getService(discoveryAddress, discoveryPort, servicePort, 
cacheMgr, new StandardSerializer());
+        return getService(discoveryAddress, discoveryPort, servicePort, 0,
+                cacheMgr, new StandardSerializer());
     }
 
     /**
      * Creates a service for the address and port if one doesn't exist already.
      * <p>
-     * We need to key this using the listener port too. TODO think of making 
one discovery service
-     * work for multiple types of clients.
+     * We need to key this using the listener port too.
+     * TODO think of making one discovery service work for multiple types of 
clients.
      * <p>
      * @param discoveryAddress
      * @param discoveryPort
      * @param servicePort
+     * @param udpTTL
      * @param cacheMgr
      * @param serializer
      *
      * @return UDPDiscoveryService
      */
     public UDPDiscoveryService getService( final String discoveryAddress, 
final int discoveryPort,
-            final int servicePort, final ICompositeCacheManager cacheMgr, 
final IElementSerializer serializer )
+            final int servicePort, final int updTTL, final 
ICompositeCacheManager cacheMgr,
+            final IElementSerializer serializer )
     {
         final String key = String.join(":", discoveryAddress, 
String.valueOf(discoveryPort), String.valueOf(servicePort));
 
@@ -106,9 +109,10 @@ public class UDPDiscoveryManager
             log.info( "Creating service for address:port:servicePort [{0}]", 
key );
 
             final UDPDiscoveryAttributes attributes = new 
UDPDiscoveryAttributes();
-            attributes.setUdpDiscoveryAddr( discoveryAddress );
-            attributes.setUdpDiscoveryPort( discoveryPort );
-            attributes.setServicePort( servicePort );
+            attributes.setUdpDiscoveryAddr(discoveryAddress);
+            attributes.setUdpDiscoveryPort(discoveryPort);
+            attributes.setServicePort(servicePort);
+            attributes.setUdpTTL(updTTL);
 
             final UDPDiscoveryService newService = new 
UDPDiscoveryService(attributes, serializer);
 

Reply via email to