You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tv...@apache.org on 2020/04/13 14:51:02 UTC
[commons-jcs] branch master updated: JCS-46 implement multicast
time-to-live configuration
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
The following commit(s) were added to refs/heads/master by this push:
new a036543 JCS-46 implement multicast time-to-live configuration
a036543 is described below
commit a036543ec8f710950d0f3ce559779c746b8aba44
Author: Thomas Vandahl <tv...@apache.org>
AuthorDate: Mon Apr 13 16:50:50 2020 +0200
JCS-46 implement multicast time-to-live configuration
---
.../jcs/utils/discovery/UDPDiscoveryAttributes.java | 19 +++++++++++++++++++
.../jcs/utils/discovery/UDPDiscoverySender.java | 14 ++++++++++----
.../jcs/utils/discovery/UDPDiscoverySenderThread.java | 18 ++++++++++++------
.../jcs/utils/discovery/UDPDiscoveryService.java | 3 ++-
.../utils/discovery/UDPDiscoverySenderUnitTest.java | 2 +-
.../jcs/utils/discovery/UDPDiscoveryUnitTest.java | 6 ++++--
xdocs/LateralUDPDiscovery.xml | 5 ++++-
7 files changed, 52 insertions(+), 15 deletions(-)
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryAttributes.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryAttributes.java
index 8a8e58a..1cf3962 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryAttributes.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryAttributes.java
@@ -58,6 +58,9 @@ public final class UDPDiscoveryAttributes
/** udp discovery port */
private int udpDiscoveryPort = DEFAULT_UDP_DISCOVERY_PORT;
+ /** udp datagram TTL */
+ private int udpTTL = 0;
+
/** default delay between sending passive broadcasts */
private static final int DEFAULT_SEND_DELAY_SEC = 60;
@@ -159,6 +162,22 @@ public final class UDPDiscoveryAttributes
}
/**
+ * @return Returns the udpTTL.
+ */
+ public int getUdpTTL()
+ {
+ return udpTTL;
+ }
+
+ /**
+ * @param udpTTL The udpTTL to set.
+ */
+ public void setUdpTTL( int udpTTL )
+ {
+ this.udpTTL = udpTTL;
+ }
+
+ /**
* @return Returns the udpDiscoveryPort.
*/
public int getUdpDiscoveryPort()
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/discovery/UDPDiscoverySender.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/discovery/UDPDiscoverySender.java
index 64ca500..6f4f9fe 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/discovery/UDPDiscoverySender.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/discovery/UDPDiscoverySender.java
@@ -43,10 +43,10 @@ public class UDPDiscoverySender implements AutoCloseable
private static final Log log = LogManager.getLog( UDPDiscoverySender.class );
/** The socket */
- private MulticastSocket localSocket;
+ private final MulticastSocket localSocket;
/** The address */
- private InetAddress multicastAddress;
+ private final InetAddress multicastAddress;
/** The port */
private final int multicastPort;
@@ -63,15 +63,21 @@ public class UDPDiscoverySender implements AutoCloseable
* <p>
* @param host
* @param port
+ * @param udpTTL the Datagram packet time-to-live
* @throws IOException
*/
- public UDPDiscoverySender( String host, int port )
+ public UDPDiscoverySender( String host, int port, int udpTTL )
throws IOException
{
try
{
log.debug( "Constructing socket for sender on port [{0}]", port );
localSocket = new MulticastSocket( port );
+ if (udpTTL > 0)
+ {
+ log.debug( "Setting datagram TTL to [{0}]", udpTTL );
+ localSocket.setTimeToLive(udpTTL);
+ }
// Remote address.
multicastAddress = InetAddress.getByName( host );
@@ -82,7 +88,7 @@ public class UDPDiscoverySender implements AutoCloseable
throw e;
}
- multicastPort = port;
+ this.multicastPort = port;
}
/**
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/discovery/UDPDiscoverySenderThread.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/discovery/UDPDiscoverySenderThread.java
index 3a8824f..6c7c2a5 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/discovery/UDPDiscoverySenderThread.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/discovery/UDPDiscoverySenderThread.java
@@ -79,8 +79,10 @@ public class UDPDiscoverySenderThread
() -> attributes.getServiceAddress(),
() -> attributes.getServicePort() );
- try (UDPDiscoverySender sender = new UDPDiscoverySender( attributes.getUdpDiscoveryAddr(),
- attributes.getUdpDiscoveryPort() ))
+ try (UDPDiscoverySender sender = new UDPDiscoverySender(
+ attributes.getUdpDiscoveryAddr(),
+ attributes.getUdpDiscoveryPort(),
+ attributes.getUdpTTL()))
{
// move this to the run method and determine how often to call it.
sender.requestBroadcast();
@@ -101,8 +103,10 @@ public class UDPDiscoverySenderThread
{
// create this connection each time.
// more robust
- try (UDPDiscoverySender sender = new UDPDiscoverySender( attributes.getUdpDiscoveryAddr(),
- attributes.getUdpDiscoveryPort() ))
+ try (UDPDiscoverySender sender = new UDPDiscoverySender(
+ attributes.getUdpDiscoveryAddr(),
+ attributes.getUdpDiscoveryPort(),
+ attributes.getUdpTTL()))
{
sender.passiveBroadcast( attributes.getServiceAddress(), attributes.getServicePort(), cacheNames );
@@ -126,8 +130,10 @@ public class UDPDiscoverySenderThread
{
// create this connection each time.
// more robust
- try (UDPDiscoverySender sender = new UDPDiscoverySender( attributes.getUdpDiscoveryAddr(),
- attributes.getUdpDiscoveryPort() ))
+ try (UDPDiscoverySender sender = new UDPDiscoverySender(
+ attributes.getUdpDiscoveryAddr(),
+ attributes.getUdpDiscoveryPort(),
+ attributes.getUdpTTL()))
{
sender.removeBroadcast( attributes.getServiceAddress(), attributes.getServicePort(), cacheNames );
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryService.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryService.java
index 107851a..1f8fc68 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryService.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryService.java
@@ -142,7 +142,8 @@ public class UDPDiscoveryService
// more robust
try (UDPDiscoverySender sender = new UDPDiscoverySender(
getUdpDiscoveryAttributes().getUdpDiscoveryAddr(),
- getUdpDiscoveryAttributes().getUdpDiscoveryPort() ))
+ getUdpDiscoveryAttributes().getUdpDiscoveryPort(),
+ getUdpDiscoveryAttributes().getUdpTTL()))
{
sender.passiveBroadcast( getUdpDiscoveryAttributes().getServiceAddress(), getUdpDiscoveryAttributes()
.getServicePort(), this.getCacheNames() );
diff --git a/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/discovery/UDPDiscoverySenderUnitTest.java b/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/discovery/UDPDiscoverySenderUnitTest.java
index e88930b..c28f805 100644
--- a/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/discovery/UDPDiscoverySenderUnitTest.java
+++ b/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/discovery/UDPDiscoverySenderUnitTest.java
@@ -61,7 +61,7 @@ public class UDPDiscoverySenderUnitTest
{
super.setUp();
receiver = new UDPDiscoveryReceiver( null, null, ADDRESS, PORT );
- sender = new UDPDiscoverySender( ADDRESS, PORT );
+ sender = new UDPDiscoverySender( ADDRESS, PORT, 0 );
}
/**
diff --git a/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryUnitTest.java b/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryUnitTest.java
index c070a53..0f85cb1 100644
--- a/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryUnitTest.java
+++ b/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryUnitTest.java
@@ -60,8 +60,10 @@ public class UDPDiscoveryUnitTest
t.start();
// create a sender
- UDPDiscoverySender sender = new UDPDiscoverySender( attributes.getUdpDiscoveryAddr(), attributes
- .getUdpDiscoveryPort() );
+ UDPDiscoverySender sender = new UDPDiscoverySender(
+ attributes.getUdpDiscoveryAddr(),
+ attributes.getUdpDiscoveryPort(),
+ 4 /* datagram TTL */);
// create more names than we have no wait facades for
// the only one that gets added should be testCache1
diff --git a/xdocs/LateralUDPDiscovery.xml b/xdocs/LateralUDPDiscovery.xml
index b19dbc6..4001f3e 100644
--- a/xdocs/LateralUDPDiscovery.xml
+++ b/xdocs/LateralUDPDiscovery.xml
@@ -55,7 +55,8 @@
Lateral Auxiliary Cache referenced by <code>LTCP</code>. It uses
UDP Discovery to locate other servers. It broadcasts to
multicast address <code>228.5.6.8</code> and port <code>6780</code>.
- It listens to port <code>1110</code>.
+ It listens to port <code>1110</code>. The UDP datagram time-to-live
+ is 4.
</p>
<source><![CDATA[
jcs.auxiliary.LTCP=org.apache.commons.jcs.auxiliary.lateral.socket.tcp.LateralTCPCacheFactory
@@ -65,6 +66,7 @@ jcs.auxiliary.LTCP.attributes.PutOnlyMode=true
jcs.auxiliary.LTCP.attributes.UdpDiscoveryAddr=228.5.6.8
jcs.auxiliary.LTCP.attributes.UdpDiscoveryPort=6780
jcs.auxiliary.LTCP.attributes.UdpDiscoveryEnabled=true
+jcs.auxiliary.LTCP.attributes.UdpTTL=4
]]></source>
</subsection>
<subsection name="Multi-homed hosts">
@@ -88,6 +90,7 @@ jcs.auxiliary.LTCP.attributes.UdpDiscoveryInterface=en0
jcs.auxiliary.LTCP.attributes.UdpDiscoveryAddr=228.5.6.8
jcs.auxiliary.LTCP.attributes.UdpDiscoveryPort=6780
jcs.auxiliary.LTCP.attributes.UdpDiscoveryEnabled=true
+jcs.auxiliary.LTCP.attributes.UdpTTL=4
]]></source>
</subsection>
</section>