Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=47308
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 18 Jun 2009 17:08:38 +0000 (17:08 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 18 Jun 2009 17:08:38 +0000 (17:08 +0000)
Patch provided by Keiichi Fujino with one change, default is false

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@786165 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/tribes/membership/McastService.java
java/org/apache/catalina/tribes/membership/McastServiceImpl.java
webapps/docs/config/cluster-membership.xml

index bb774ca..5417b3e 100644 (file)
@@ -245,6 +245,9 @@ public class McastService implements MembershipService,MembershipListener,Messag
         properties.setProperty("recoverySleepTime", String.valueOf(recoverySleepTime));
     }
 
+    public void setLocalLoopbackDisabled(boolean localLoopbackDisabled) {
+        properties.setProperty("localLoopbackDisabled",String.valueOf(localLoopbackDisabled));
+    }
 
     /**
      * @deprecated use getPort()
@@ -383,7 +386,8 @@ public class McastService implements MembershipService,MembershipListener,Messag
                                     ttl,
                                     soTimeout,
                                     this,
-                                    this);
+                                    this,
+                                    Boolean.valueOf(properties.getProperty("localLoopbackDisabled","false")).booleanValue());
         String value = properties.getProperty("recoveryEnabled","true");
         boolean recEnabled = Boolean.valueOf(value).booleanValue() ;
         impl.setRecoveryEnabled(recEnabled);
index 11da4d4..f31d28e 100644 (file)
@@ -148,6 +148,11 @@ public class McastServiceImpl
     protected ExecutorService executor = new ThreadPoolExecutor(0, 2, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
     
     /**
+     * disable/enable local loopback message
+     */
+    protected boolean localLoopbackDisabled = false;
+    
+    /**
      * Create a new mcast service impl
      * @param member - the local member
      * @param sendFrequency - the time (ms) in between pings sent out
@@ -156,6 +161,7 @@ public class McastServiceImpl
      * @param bind - the bind address (not sure this is used yet)
      * @param mcastAddress - the mcast address
      * @param service - the callback service
+     * @param disableLoopbackMode - disable loopbackMode
      * @throws IOException
      */
     public McastServiceImpl(
@@ -168,7 +174,8 @@ public class McastServiceImpl
         int ttl,
         int soTimeout,
         MembershipListener service,
-        MessageListener msgservice)
+        MessageListener msgservice,
+        boolean localLoopbackDisabled)
     throws IOException {
         this.member = member;
         this.address = mcastAddress;
@@ -180,6 +187,7 @@ public class McastServiceImpl
         this.service = service;
         this.msgservice = msgservice;
         this.sendFrequency = sendFrequency;
+        this.localLoopbackDisabled = localLoopbackDisabled;
         init();
     }
 
@@ -213,7 +221,7 @@ public class McastServiceImpl
         } else {
             socket = new MulticastSocket(port);
         }
-        socket.setLoopbackMode(true); //hint that we don't need loop back messages
+        socket.setLoopbackMode(localLoopbackDisabled); //hint if we want disable loop back(local machine) messages
         if (mcastBindAddress != null) {
                        if(log.isInfoEnabled())
                 log.info("Setting multihome multicast interface to:" +mcastBindAddress);
index 52fb1d0..61c5886 100644 (file)
       The default is <code>5000</code> (5 seconds). <br/>
       </p>
     </attribute>
+    
+    <attribute name="localLoopbackDisabled" required="false">
+      <p>
+      Membership uses multicast, it will call <code>java.net.MulticastSocket.setLoopbackMode(localLoopbackDisabled)</code>.
+      When <code>localLoopbackDisabled==true</code> multicast messages will not reach other nodes on the same local machine.
+      The default is <code>false</code>. <br/>
+      </p>
+    </attribute>
 
 
   </attributes>