tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fha...@apache.org
Subject svn commit: r628837 - in /tomcat/trunk: java/org/apache/catalina/tribes/membership/MemberImpl.java test/org/apache/catalina/tribes/test/membership/MemberSerialization.java
Date Mon, 18 Feb 2008 18:13:42 GMT
Author: fhanik
Date: Mon Feb 18 10:13:39 2008
New Revision: 628837

URL: http://svn.apache.org/viewvc?rev=628837&view=rev
Log:
Add support to carry a UDP port in the broadcast, also add in versioning support (last two
bytes) so that we can move the protocol forward

Modified:
    tomcat/trunk/java/org/apache/catalina/tribes/membership/MemberImpl.java
    tomcat/trunk/test/org/apache/catalina/tribes/test/membership/MemberSerialization.java

Modified: tomcat/trunk/java/org/apache/catalina/tribes/membership/MemberImpl.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/tribes/membership/MemberImpl.java?rev=628837&r1=628836&r2=628837&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/tribes/membership/MemberImpl.java (original)
+++ tomcat/trunk/java/org/apache/catalina/tribes/membership/MemberImpl.java Mon Feb 18 10:13:39
2008
@@ -48,8 +48,8 @@
     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 @@
      * 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 @@
                8+ //alive time
                4+ //port
                4+ //secure port
+               4+ //udp port
                1+ //host length
                host.length+ //host
                4+ //command length
@@ -219,6 +224,7 @@
         //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 @@
         //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 @@
         //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 @@
         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 @@
         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 @@
         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 int getSecurePort() {
         return securePort;
     }
+    
+    public int getUdpPort() {
+    	return udpPort;
+    }
 
     public void setMemberAliveTime(long time) {
        memberAliveTime=time;
@@ -590,6 +608,12 @@
 
     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 {

Modified: tomcat/trunk/test/org/apache/catalina/tribes/test/membership/MemberSerialization.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/tribes/test/membership/MemberSerialization.java?rev=628837&r1=628836&r2=628837&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/tribes/test/membership/MemberSerialization.java
(original)
+++ tomcat/trunk/test/org/apache/catalina/tribes/test/membership/MemberSerialization.java
Mon Feb 18 10:13:39 2008
@@ -32,6 +32,7 @@
 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 @@
         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 {
@@ -56,6 +59,19 @@
         assertFalse(m1.equals(p2));
         assertFalse(m2.equals(p2));
         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 {



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


Mime
View raw message