You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2011/01/15 17:33:05 UTC

svn commit: r1059366 - /tomcat/trunk/java/org/apache/catalina/tribes/membership/McastServiceImpl.java

Author: markt
Date: Sat Jan 15 16:33:05 2011
New Revision: 1059366

URL: http://svn.apache.org/viewvc?rev=1059366&view=rev
Log:
Refactor to make clearer what is going on

Modified:
    tomcat/trunk/java/org/apache/catalina/tribes/membership/McastServiceImpl.java

Modified: tomcat/trunk/java/org/apache/catalina/tribes/membership/McastServiceImpl.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/tribes/membership/McastServiceImpl.java?rev=1059366&r1=1059365&r2=1059366&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/tribes/membership/McastServiceImpl.java (original)
+++ tomcat/trunk/java/org/apache/catalina/tribes/membership/McastServiceImpl.java Sat Jan 15 16:33:05 2011
@@ -547,7 +547,7 @@ public class McastServiceImpl
                             try { Thread.sleep(500); } catch ( Exception ignore ){}
                             if ( (++errorCounter)>=recoveryCounter ) {
                                 errorCounter=0;
-                                new RecoveryThread(McastServiceImpl.this).start();
+                                RecoveryThread.recover(McastServiceImpl.this);
                             }
                         }
                     }
@@ -575,7 +575,7 @@ public class McastServiceImpl
                     else log.debug("Unable to send mcast message.",x);
                     if ( (++errorCounter)>=recoveryCounter ) {
                         errorCounter=0;
-                        new RecoveryThread(McastServiceImpl.this).start();
+                        RecoveryThread.recover(McastServiceImpl.this);
                     }
                 }
                 try { Thread.sleep(time); } catch ( Exception ignore ) {}
@@ -585,22 +585,27 @@ public class McastServiceImpl
 
     protected static class RecoveryThread extends Thread {
         static volatile boolean running = false;
-        McastServiceImpl parent = null;
-        public RecoveryThread(McastServiceImpl parent) {
-            this.parent = parent;
-            if (!init(this)) parent = null;
-        }
-        
-        public static synchronized boolean init(RecoveryThread t) {
-            if ( running ) return false;
-            if ( !t.parent.isRecoveryEnabled()) return false;
+
+        public static synchronized void recover(McastServiceImpl parent) {
+            if (running) return;
+            if (!parent.isRecoveryEnabled())
+                return;
+            
             running = true;
+            
+            Thread t = new RecoveryThread(parent);
+            
             t.setName("Tribes-MembershipRecovery");
             t.setDaemon(true);
             t.start();
-            return true;
         }
 
+
+        McastServiceImpl parent = null;
+        public RecoveryThread(McastServiceImpl parent) {
+            this.parent = parent;
+        }
+        
         public boolean stopService() {
             try {
                 parent.stop(Channel.MBR_RX_SEQ | Channel.MBR_TX_SEQ);



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r1059366 - /tomcat/trunk/java/org/apache/catalina/tribes/membership/McastServiceImpl.java

Posted by Konstantin Kolinko <kn...@gmail.com>.
2011/1/15 Mark Thomas <ma...@apache.org>:
> On 15/01/2011 16:33, markt@apache.org wrote:
>> Author: markt
>> Date: Sat Jan 15 16:33:05 2011
>> New Revision: 1059366
>>
>> URL: http://svn.apache.org/viewvc?rev=1059366&view=rev
>> Log:
>> Refactor to make clearer what is going on
>
> Hopefully this is clearer.
>
>> @@ -585,22 +585,27 @@ public class McastServiceImpl
>>
>>      protected static class RecoveryThread extends Thread {
>>          static volatile boolean running = false;
>> -        McastServiceImpl parent = null;
>> -        public RecoveryThread(McastServiceImpl parent) {
>> -            this.parent = parent;
>> -            if (!init(this)) parent = null;
>> -        }
>
> I couldn't see what the "if (!init(this)) parent = null;" line was
> doing. Even if it were "... this.parent = null;" I still don;t see the
> need. Am I missing something?

My guess is that is to prevent this RecoveryThread from being used if
recovery is disabled.

Actually, as you noticed, in TC 6 that assignment modifies the method
argument and thus does nothing. In 5.5 it is  this.parent=null; thanks
to this rev:

http://svn.apache.org/viewvc?view=revision&revision=571739

With this kind of code I would expect "if (parent != null)" checks
elsewhere, but there are no such checks.


Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r1059366 - /tomcat/trunk/java/org/apache/catalina/tribes/membership/McastServiceImpl.java

Posted by Mark Thomas <ma...@apache.org>.
On 15/01/2011 16:33, markt@apache.org wrote:
> Author: markt
> Date: Sat Jan 15 16:33:05 2011
> New Revision: 1059366
> 
> URL: http://svn.apache.org/viewvc?rev=1059366&view=rev
> Log:
> Refactor to make clearer what is going on

Hopefully this is clearer.

> @@ -585,22 +585,27 @@ public class McastServiceImpl
>  
>      protected static class RecoveryThread extends Thread {
>          static volatile boolean running = false;
> -        McastServiceImpl parent = null;
> -        public RecoveryThread(McastServiceImpl parent) {
> -            this.parent = parent;
> -            if (!init(this)) parent = null;
> -        }

I couldn't see what the "if (!init(this)) parent = null;" line was
doing. Even if it were "... this.parent = null;" I still don;t see the
need. Am I missing something?

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org