Add support to carry a UDP port in the broadcast, also add in versioning support...
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 18 Feb 2008 18:13:39 +0000 (18:13 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 18 Feb 2008 18:13:39 +0000 (18:13 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@628837 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/tribes/membership/MemberImpl.java
test/org/apache/catalina/tribes/test/membership/MemberSerialization.java

index 7598ccb..4856a73 100644 (file)
@@ -48,8 +48,8 @@ public class MemberImpl implements Member, java.io.Externalizable {
     public static final transient String TCP_LISTEN_HOST = "tcpListenHost";
     public static final transient String MEMBER_NAME = "memberName";
     
-    public static final transient byte[] TRIBES_MBR_BEGIN = new byte[] {84, 82, 73, 66, 69, 83, 45, 66};
-    public static final transient byte[] TRIBES_MBR_END   = new byte[] {84, 82, 73, 66, 69, 83, 45, 69};
+    public static final transient byte[] TRIBES_MBR_BEGIN = new byte[] {84, 82, 73, 66, 69, 83, 45, 66, 1, 0};
+    public static final transient byte[] TRIBES_MBR_END   = new byte[] {84, 82, 73, 66, 69, 83, 45, 69, 1, 0};
     
     /**
      * The listen host for this member
@@ -60,6 +60,10 @@ public class MemberImpl implements Member, java.io.Externalizable {
      * The tcp listen port for this member
      */
     protected int port;
+    /**
+     * The udp listen port for this member
+     */
+    protected int udpPort = -1;
     
     /**
      * The tcp/SSL listen port for this member
@@ -182,6 +186,7 @@ public class MemberImpl implements Member, java.io.Externalizable {
                8+ //alive time
                4+ //port
                4+ //secure port
+               4+ //udp port
                1+ //host length
                host.length+ //host
                4+ //command length
@@ -219,6 +224,7 @@ public class MemberImpl implements Member, java.io.Externalizable {
         //alive - 8 bytes
         //port - 4 bytes
         //secure port - 4 bytes
+        //udp port - 4 bytes
         //host length - 1 byte
         //host - hl bytes
         //clen - 4 bytes
@@ -255,6 +261,9 @@ public class MemberImpl implements Member, java.io.Externalizable {
         //secure port
         XByteBuffer.toBytes(securePort,data,pos);
         pos += 4;
+        //udp port
+        XByteBuffer.toBytes(udpPort,data,pos);
+        pos += 4;
         //host length
         data[pos++] = hl;
         //host
@@ -305,6 +314,7 @@ public class MemberImpl implements Member, java.io.Externalizable {
         //alive - 8 bytes
         //port - 4 bytes
         //secure port - 4 bytes
+       //udp port - 4 bytes
         //host length - 1 byte
         //host - hl bytes
         //clen - 4 bytes
@@ -319,7 +329,7 @@ public class MemberImpl implements Member, java.io.Externalizable {
         int pos = offset;
         
         if (XByteBuffer.firstIndexOf(data,offset,TRIBES_MBR_BEGIN)!=pos) {
-            throw new IllegalArgumentException("Invalid package, should start with:"+org.apache.catalina.tribes.util.Arrays.toString(TRIBES_MBR_BEGIN)+" Possibly an incompatible client broadcasting on the same multicast address.");
+            throw new IllegalArgumentException("Invalid package, should start with:"+org.apache.catalina.tribes.util.Arrays.toString(TRIBES_MBR_BEGIN));
         }
 
         if ( length < (TRIBES_MBR_BEGIN.length+4) ) {
@@ -352,6 +362,9 @@ public class MemberImpl implements Member, java.io.Externalizable {
         System.arraycopy(data, pos, sportd, 0, 4);
         pos += 4;
 
+        byte[] uportd = new byte[4];
+        System.arraycopy(data, pos, uportd, 0, 4);
+        pos += 4;
 
     
         byte hl = data[pos++];
@@ -387,6 +400,7 @@ public class MemberImpl implements Member, java.io.Externalizable {
         member.setHost(addr);
         member.setPort(XByteBuffer.toInt(portd, 0));
         member.setSecurePort(XByteBuffer.toInt(sportd, 0));
+        member.setUdpPort(XByteBuffer.toInt(uportd, 0));
         member.setMemberAliveTime(XByteBuffer.toLong(alived, 0));
         member.setUniqueId(uniqueId);
         member.payload = payload;
@@ -479,6 +493,10 @@ public class MemberImpl implements Member, java.io.Externalizable {
     public int getSecurePort() {
         return securePort;
     }
+    
+    public int getUdpPort() {
+       return udpPort;
+    }
 
     public void setMemberAliveTime(long time) {
        memberAliveTime=time;
@@ -590,6 +608,12 @@ public class MemberImpl implements Member, java.io.Externalizable {
 
     public void setSecurePort(int securePort) {
         this.securePort = securePort;
+        this.dataPkg = null;
+    }
+    
+    public void setUdpPort(int port) {
+       this.udpPort = port;
+       this.dataPkg = null;
     }
 
     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
index 97a5cb3..9fc7106 100644 (file)
@@ -32,6 +32,7 @@ import java.util.Arrays;
 public class MemberSerialization extends TestCase {
     MemberImpl m1, m2, p1,p2;
     byte[] payload = null;
+    int udpPort = 3445;
     protected void setUp() throws Exception {
         super.setUp();
         payload = new byte[333];
@@ -46,6 +47,8 @@ public class MemberSerialization extends TestCase {
         m2.setDomain(new byte[] {1,2,3,4,5,6,7,8,9});
         m1.setCommand(new byte[] {1,2,4,5,6,7,8,9});
         m2.setCommand(new byte[] {1,2,4,5,6,7,8,9});
+        m1.setUdpPort(udpPort);
+        m2.setUdpPort(m1.getUdpPort());
     }
     
     public void testCompare() throws Exception {
@@ -58,6 +61,19 @@ public class MemberSerialization extends TestCase {
         assertFalse(p1.equals(p2));
     }
     
+    public void testUdpPort() throws Exception {
+       byte[] md1 = m1.getData();
+       byte[] md2 = m2.getData();
+
+        MemberImpl a1 = MemberImpl.getMember(md1);
+        MemberImpl a2 = MemberImpl.getMember(md2);
+        
+        assertEquals(true, a1.getUdpPort()==a2.getUdpPort());
+        assertEquals(true,a1.getUdpPort()==udpPort);
+
+       
+    }
+    
     public void testSerializationOne() throws Exception {
         MemberImpl m = m1;
         byte[] md1 = m.getData(false,true);