You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2015/08/25 10:57:34 UTC

[27/50] ignite git commit: Added TTL to multicast IP finder

Added TTL to multicast IP finder


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/82ce0a08
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/82ce0a08
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/82ce0a08

Branch: refs/heads/ignite-1093
Commit: 82ce0a088494a2d9adbfdf23255636dcf047f046
Parents: 452af6a
Author: Valentin Kulichenko <va...@gmail.com>
Authored: Thu Aug 20 17:36:02 2015 -0700
Committer: Valentin Kulichenko <va...@gmail.com>
Committed: Thu Aug 20 23:57:14 2015 -0700

----------------------------------------------------------------------
 .../TcpDiscoveryMulticastIpFinder.java          | 38 ++++++++++++++++++++
 1 file changed, 38 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/82ce0a08/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/multicast/TcpDiscoveryMulticastIpFinder.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/multicast/TcpDiscoveryMulticastIpFinder.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/multicast/TcpDiscoveryMulticastIpFinder.java
index b93c547..2a07879 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/multicast/TcpDiscoveryMulticastIpFinder.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/multicast/TcpDiscoveryMulticastIpFinder.java
@@ -99,6 +99,9 @@ public class TcpDiscoveryMulticastIpFinder extends TcpDiscoveryVmIpFinder {
     /** Local address */
     private String locAddr;
 
+    /** Time to live. */
+    private Integer ttl;
+
     /** */
     @GridToStringExclude
     private Collection<AddressSender> addrSnds;
@@ -223,6 +226,32 @@ public class TcpDiscoveryMulticastIpFinder extends TcpDiscoveryVmIpFinder {
         return locAddr;
     }
 
+    /**
+     * Set the default time-to-live for multicast packets sent out on this
+     * IP finder in order to control the scope of the multicast.
+     * <p>
+     * The TTL has to be in the range {@code  0 <= TTL <= 255}.
+     * <p>
+     * If TTL is {@code 0}, packets are not transmitted on the network,
+     * but may be delivered locally.
+     *
+     * @param ttl Time to live.
+     */
+    @IgniteSpiConfiguration(optional = true)
+    public void setTimeToLive(int ttl) {
+        this.ttl = ttl;
+    }
+
+    /**
+     * Set the default time-to-live for multicast packets sent out on this
+     * IP finder.
+     *
+     * @return Time to live.
+     */
+    public int getTimeToLive() {
+        return ttl;
+    }
+
     /** {@inheritDoc} */
     @Override public void initializeLocalAddresses(Collection<InetSocketAddress> addrs) throws IgniteSpiException {
         // If IGNITE_OVERRIDE_MCAST_GRP system property is set, use its value to override multicast group from
@@ -245,6 +274,9 @@ public class TcpDiscoveryMulticastIpFinder extends TcpDiscoveryVmIpFinder {
             throw new IgniteSpiException("Invalid number of address request attempts, " +
                 "value greater than zero is expected: " + addrReqAttempts);
 
+        if (ttl != null && (ttl < 0 || ttl > 255))
+            throw new IgniteSpiException("Time-to-live value is out of 0 <= TTL <= 255 range: " + ttl);
+
         if (F.isEmpty(getRegisteredAddresses()))
             U.warn(log, "TcpDiscoveryMulticastIpFinder has no pre-configured addresses " +
                 "(it is recommended in production to specify at least one address in " +
@@ -453,6 +485,9 @@ public class TcpDiscoveryMulticastIpFinder extends TcpDiscoveryVmIpFinder {
 
                     sock.setSoTimeout(resWaitTime);
 
+                    if (ttl != null)
+                        sock.setTimeToLive(ttl);
+
                     reqPckt.setData(MSG_ADDR_REQ_DATA);
 
                     try {
@@ -722,6 +757,9 @@ public class TcpDiscoveryMulticastIpFinder extends TcpDiscoveryVmIpFinder {
 
             sock.joinGroup(mcastGrp);
 
+            if (ttl != null)
+                sock.setTimeToLive(ttl);
+
             return sock;
         }