mirror of https://github.com/apache/activemq.git
Apply fixECNBits patch for https://issues.apache.org/activemq/browse/AMQ-2636
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@937265 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f8b0c22d0f
commit
9740fb21a6
|
@ -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);
|
||||
|
|
|
@ -648,7 +648,29 @@ public class TcpTransport extends TransportThreadSupport implements Transport, S
|
|||
+ " 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.
|
||||
|
|
|
@ -31,8 +31,7 @@ public class QualityOfServiceUtilsTest extends TestCase {
|
|||
|
||||
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 extends TestCase {
|
|||
}
|
||||
// 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 extends TestCase {
|
|||
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);
|
||||
|
|
Loading…
Reference in New Issue