activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rajdav...@apache.org
Subject svn commit: r937265 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/transport/tcp/ test/java/org/apache/activemq/transport/tcp/
Date Fri, 23 Apr 2010 12:32:40 GMT
Author: rajdavies
Date: Fri Apr 23 12:32:40 2010
New Revision: 937265

URL: http://svn.apache.org/viewvc?rev=937265&view=rev
Log:
Apply fixECNBits patch for https://issues.apache.org/activemq/browse/AMQ-2636

Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/QualityOfServiceUtils.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/tcp/QualityOfServiceUtilsTest.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/QualityOfServiceUtils.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/QualityOfServiceUtils.java?rev=937265&r1=937264&r2=937265&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/QualityOfServiceUtils.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/QualityOfServiceUtils.java
Fri Apr 23 12:32:40 2010
@@ -32,7 +32,7 @@ public class QualityOfServiceUtils {
     private static final int MIN_DIFF_SERV = 0;
     private static final Map<String, Integer> DIFF_SERV_NAMES
         = new HashMap<String, Integer>();
-    // TODO: Find other names used for Differentiated Services values.
+    /** Common names used for Differentiated Services values. */
     static {
         DIFF_SERV_NAMES.put("EF", 46);
         DIFF_SERV_NAMES.put("AF11", 10);
@@ -119,8 +119,9 @@ public class QualityOfServiceUtils {
         Socket socket = new Socket();
         try {
             int systemTrafficClass = socket.getTrafficClass();
-            // The 7th and 8th bits of the system traffic class are the ECN bits.
-            return dscp | (systemTrafficClass & 192);
+            // The 1st and 2nd bits of the system traffic class are the ECN
+            // bits.
+            return (dscp << 2) | (systemTrafficClass & 3);
         } catch (SocketException e) {
             throw new IllegalArgumentException("Setting Differentiated Services"
                 + " not supported: " + e);

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java?rev=937265&r1=937264&r2=937265&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java
Fri Apr 23 12:32:40 2010
@@ -648,7 +648,29 @@ public class TcpTransport extends Transp
                 + " Differentiated Services and Type of Services transport "
                 + " options on the same connection.");
         }
+
         sock.setTrafficClass(this.trafficClass);
+
+        int resultTrafficClass = sock.getTrafficClass();
+        if (this.trafficClass != resultTrafficClass) {
+            // In the case where the user has specified the ECN bits (e.g. in
+            // Type of Service) but the system won't allow the ECN bits to be
+            // set or in the case where setting the traffic class failed for
+            // other reasons, emit a warning.
+            if ((this.trafficClass >> 2) == (resultTrafficClass >> 2)
+                    && (this.trafficClass & 3) != (resultTrafficClass & 3))
{
+                LOG.warn("Attempted to set the Traffic Class to "
+                    + this.trafficClass + " but the result Traffic Class was "
+                    + resultTrafficClass + ". Please check that your system "
+                    + "allows you to set the ECN bits (the first two bits).");
+            } else {
+                LOG.warn("Attempted to set the Traffic Class to "
+                    + this.trafficClass + " but the result Traffic Class was "
+                    + resultTrafficClass + ". Please check that your system "
+                         + "supports java.net.setTrafficClass.");
+            }
+            return false;
+        }
         // Reset the guards that prevent both the Differentiated Services
         // option and the Type of Service option from being set on the same
         // connection.

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/tcp/QualityOfServiceUtilsTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/tcp/QualityOfServiceUtilsTest.java?rev=937265&r1=937264&r2=937265&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/tcp/QualityOfServiceUtilsTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/tcp/QualityOfServiceUtilsTest.java
Fri Apr 23 12:32:40 2010
@@ -31,8 +31,7 @@ public class QualityOfServiceUtilsTest e
 
     protected void setUp() throws Exception {
         Socket socket = new Socket();
-        ECN = socket.getTrafficClass();
-        ECN = ECN & Integer.parseInt("11000000", 2);
+        ECN = socket.getTrafficClass() & Integer.parseInt("00000011", 2);
     }
 
     protected void tearDown() throws Exception {
@@ -90,7 +89,7 @@ public class QualityOfServiceUtilsTest e
         }
         // Make sure it adjusted for any system ECN values.
         assertEquals("Incorrect Differentiated Services Code Point "  + dscp
-            + " returned for name " + name + ".", ECN | expected, dscp);
+            + " returned for name " + name + ".", ECN | (expected << 2), dscp);
     }
 
     private void testInvalidDiffServName(String name) {
@@ -107,7 +106,7 @@ public class QualityOfServiceUtilsTest e
             int dscp = QualityOfServiceUtils.getDSCP(Integer.toString(val));
             // Make sure it adjusted for any system ECN values.
             assertEquals("Incorrect Differentiated Services Code Point "
-                + "returned for value " + val + ".", ECN | val, dscp);
+                + "returned for value " + val + ".", ECN | (val << 2), dscp);
         } catch (IllegalArgumentException e) {
             fail("IllegalArgumentException thrown for valid Differentiated "
                  + "Services value " + val);



Mime
View raw message