tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1367218 - in /tomcat/trunk/java/org/apache/catalina/tribes/membership: McastServiceImpl.java Membership.java
Date Mon, 30 Jul 2012 18:40:35 GMT
Author: markt
Date: Mon Jul 30 18:40:34 2012
New Revision: 1367218

URL: http://svn.apache.org/viewvc?rev=1367218&view=rev
Log:
Partial code clean-up for o.a.catalina.tribes
 - Add final prompted by UCDetector
 - Java 7 use of <>

Modified:
    tomcat/trunk/java/org/apache/catalina/tribes/membership/McastServiceImpl.java
    tomcat/trunk/java/org/apache/catalina/tribes/membership/Membership.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=1367218&r1=1367217&r2=1367218&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/tribes/membership/McastServiceImpl.java (original)
+++ tomcat/trunk/java/org/apache/catalina/tribes/membership/McastServiceImpl.java Mon Jul
30 18:40:34 2012
@@ -53,7 +53,7 @@ public class McastServiceImpl
     private static final org.apache.juli.logging.Log log =
         org.apache.juli.logging.LogFactory.getLog( McastService.class );
 
-    protected static int MAX_PACKET_SIZE = 65535;
+    protected static final int MAX_PACKET_SIZE = 65535;
     /**
      * Internal flag used for the listen thread that listens to the multicasting socket.
      */
@@ -67,23 +67,23 @@ public class McastServiceImpl
     /**
      * The local member that we intend to broad cast over and over again
      */
-    protected MemberImpl member;
+    protected final MemberImpl member;
     /**
      * The multicast address
      */
-    protected InetAddress address;
+    protected final InetAddress address;
     /**
      * The multicast port
      */
-    protected int port;
+    protected final int port;
     /**
      * The time it takes for a member to expire.
      */
-    protected long timeToExpiration;
+    protected final long timeToExpiration;
     /**
      * How often to we send out a broadcast saying we are alive, must be smaller than timeToExpiration
      */
-    protected long sendFrequency;
+    protected final long sendFrequency;
     /**
      * Reuse the sendPacket, no need to create a new one everytime
      */
@@ -99,11 +99,11 @@ public class McastServiceImpl
     /**
      * The actual listener, for callback when stuff goes down
      */
-    protected MembershipListener service;
+    protected final MembershipListener service;
     /**
      * The actual listener for broadcast callbacks
      */
-    protected MessageListener msgservice;
+    protected final MessageListener msgservice;
     /**
      * Thread to listen for pings
      */
@@ -116,7 +116,7 @@ public class McastServiceImpl
     /**
      * Time to live for the multicast packets that are being sent out
      */
-    protected int mcastTTL = -1;
+    protected final int mcastTTL;
     /**
      * Read timeout on the mcast socket
      */
@@ -124,7 +124,7 @@ public class McastServiceImpl
     /**
      * bind address
      */
-    protected InetAddress mcastBindAddress = null;
+    protected final InetAddress mcastBindAddress;
 
     /**
      * nr of times the system has to fail before a recovery is initiated
@@ -144,12 +144,13 @@ public class McastServiceImpl
     /**
      * Dont interrupt the sender/receiver thread, but pass off to an executor
      */
-    protected ExecutorService executor = ExecutorFactory.newThreadPool(0, 2, 2, TimeUnit.SECONDS);
+    protected final ExecutorService executor =
+            ExecutorFactory.newThreadPool(0, 2, 2, TimeUnit.SECONDS);
 
     /**
      * disable/enable local loopback message
      */
-    protected boolean localLoopbackDisabled = false;
+    protected final boolean localLoopbackDisabled;
 
     /**
      * Create a new mcast service impl
@@ -552,7 +553,7 @@ public class McastServiceImpl
     }//class ReceiverThread
 
     public class SenderThread extends Thread {
-        long time;
+        final long time;
         int errorCounter=0;
         public SenderThread(long time) {
             this.time = time;
@@ -596,7 +597,7 @@ public class McastServiceImpl
         }
 
 
-        McastServiceImpl parent = null;
+        final McastServiceImpl parent;
         public RecoveryThread(McastServiceImpl parent) {
             this.parent = parent;
         }

Modified: tomcat/trunk/java/org/apache/catalina/tribes/membership/Membership.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/tribes/membership/Membership.java?rev=1367218&r1=1367217&r2=1367218&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/tribes/membership/Membership.java (original)
+++ tomcat/trunk/java/org/apache/catalina/tribes/membership/Membership.java Mon Jul 30 18:40:34
2012
@@ -48,12 +48,12 @@ public class Membership implements Clone
      * The name of this membership, has to be the same as the name for the local
      * member
      */
-    protected MemberImpl local;
+    protected final MemberImpl local;
 
     /**
      * A map of all the members in the cluster.
      */
-    protected HashMap<MemberImpl, MbrEntry> map = new HashMap<MemberImpl, MbrEntry>();
+    protected HashMap<MemberImpl, MbrEntry> map = new HashMap<>();
 
     /**
      * A list of all the members in the cluster.
@@ -63,13 +63,12 @@ public class Membership implements Clone
     /**
       * sort members by alive time
       */
-    protected Comparator<Member> memberComparator = new MemberComparator();
+    protected final Comparator<Member> memberComparator;
 
     @Override
     public Object clone() {
         synchronized (membersLock) {
             Membership clone = new Membership(local, memberComparator);
-            @SuppressWarnings("unchecked") // map is correct type already
             final HashMap<MemberImpl, MbrEntry> tmpclone = (HashMap<MemberImpl,
MbrEntry>) map.clone();
             clone.map = tmpclone;
             clone.members = new MemberImpl[members.length];
@@ -84,20 +83,20 @@ public class Membership implements Clone
      * @param includeLocal - TBA
      */
     public Membership(MemberImpl local, boolean includeLocal) {
-        this.local = local;
-        if ( includeLocal ) addMember(local);
+        this(local, new MemberComparator(), includeLocal);
     }
 
     public Membership(MemberImpl local) {
-        this(local,false);
+        this(local, false);
     }
 
     public Membership(MemberImpl local, Comparator<Member> comp) {
-        this(local,comp,false);
+        this(local, comp, false);
     }
 
     public Membership(MemberImpl local, Comparator<Member> comp, boolean includeLocal)
{
-        this(local,includeLocal);
+        this.local = local;
+        if ( includeLocal ) addMember(local);
         this.memberComparator = comp;
     }
     /**
@@ -203,7 +202,7 @@ public class Membership implements Clone
             MbrEntry entry = i.next();
             if( entry.hasExpired(maxtime) ) {
                 if(list == null) // only need a list when members are expired (smaller gc)
-                    list = new java.util.ArrayList<MemberImpl>();
+                    list = new java.util.ArrayList<>();
                 list.add(entry.getMember());
             }
         }
@@ -292,10 +291,9 @@ public class Membership implements Clone
     /**
      * Inner class that represents a member entry
      */
-    protected static class MbrEntry
-    {
+    protected static class MbrEntry {
 
-        protected MemberImpl mbr;
+        protected final MemberImpl mbr;
         protected long lastHeardFrom;
 
         public MbrEntry(MemberImpl mbr) {



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


Mime
View raw message